Results 1 to 17 of 17

Thread: Detect if CD door opens

  1. #1

    Thread Starter
    Frenzied Member blindlizard's Avatar
    Join Date
    Feb 2001
    Location
    Austin, TX - United States of America
    Posts
    1,141

    Detect if CD door opens

    How can I detect if the CD door opens while my app is running? I am makig something for my son, but I want the app to die if he opens the CD door. That way when he puts the next CD in, it will play the next app, and I don't have to worry about him getting confussed.
    I drink to make other people more interesting!
    [vbcode]On Error GoTo Bar[/vbcode]
    http://www.monsterlizard.com

  2. #2
    Fanatic Member laserman's Avatar
    Join Date
    Jan 2002
    Location
    Wales U.K
    Posts
    775
    This opens the cddoor via a button but you can implement the code wherever suits you.
    Hope this helps.

    VB Code:
    1. Private Sub Command1_Click()
    2. retvalue = mciSendString("set CDAudio door open", _
    3. returnstring, 127, 0)
    4. MsgBox ("The Cddoor has opened,Your application will terminate"), vbInformation

  3. #3

    Thread Starter
    Frenzied Member blindlizard's Avatar
    Join Date
    Feb 2001
    Location
    Austin, TX - United States of America
    Posts
    1,141
    No, I don't need to open the door, I need to know if the door has been opened. I need to know if he pushed the eject button on the CD drive, then kill the app.
    I drink to make other people more interesting!
    [vbcode]On Error GoTo Bar[/vbcode]
    http://www.monsterlizard.com

  4. #4
    Super Moderator manavo11's Avatar
    Join Date
    Nov 2002
    Location
    Around the corner from si_the_geek
    Posts
    7,171
    There was a post about this a short while ago. I'll search for it. I had an attachment there...


    Has someone helped you? Then you can Rate their helpful post.

  5. #5
    Super Moderator manavo11's Avatar
    Join Date
    Nov 2002
    Location
    Around the corner from si_the_geek
    Posts
    7,171
    Here it is (look attachment in one of my posts ) : http://www.vbforums.com/showthread.p...hreadid=253107


    Has someone helped you? Then you can Rate their helpful post.

  6. #6

    Thread Starter
    Frenzied Member blindlizard's Avatar
    Join Date
    Feb 2001
    Location
    Austin, TX - United States of America
    Posts
    1,141
    Ok, I downloaded the cdspy project, but am a little lost at what I am looking at. Do you think you can walk me through it. When I run it nothing happens, should it? I see the Function ProcessDeviceChange that looks like it will tell if a cd is inserted or removed, but I am not sure what to pass it. Thanks.
    I drink to make other people more interesting!
    [vbcode]On Error GoTo Bar[/vbcode]
    http://www.monsterlizard.com

  7. #7
    Frenzied Member Shawn N's Avatar
    Join Date
    Dec 2001
    Location
    Houston
    Posts
    1,631
    Strange how much my coding on that post looks like what you posted, manavo.
    Please rate my post.

  8. #8
    Super Moderator manavo11's Avatar
    Join Date
    Nov 2002
    Location
    Around the corner from si_the_geek
    Posts
    7,171
    Hey don't look at me! You might have noticed that the code is from www.allapi.net (http://www.mentalis.org/vbexamples/v...ategory=SOURCE)


    Has someone helped you? Then you can Rate their helpful post.

  9. #9
    Super Moderator manavo11's Avatar
    Join Date
    Nov 2002
    Location
    Around the corner from si_the_geek
    Posts
    7,171
    Well, what it does is subclass the form and process the messages sent.


    When media is inserted or removed then you process the messages that are sent to the form (ProcessDeviceChange) to detect which drive it was and if it was inserted or removed. When you first run the application you won't see anything. You will see stuff in the listbox when you open/close the cdrom drives...

    Is that any better?


    Has someone helped you? Then you can Rate their helpful post.

  10. #10

    Thread Starter
    Frenzied Member blindlizard's Avatar
    Join Date
    Feb 2001
    Location
    Austin, TX - United States of America
    Posts
    1,141
    ah, ok i see now. But, here is what I am doing. I have an application burnt to a CD. This application allows my son to choose from the movies (also bunt to the CD) and open them with the default player for the file type, ie .avi opens with Windows Media Player. He has enough movies to fit about 8 CDs. When he puts one it, it runs my application (burnt on the CD) and allows him to navigate and play the movies on the CD. What I want is after he puts a CD in and it runs my application, that if he decides that is not the CD he wants, and opens the CD tray, that the application will terminate. This way when he puts in another CD, the application on it will run and he wont accidentally use the old app from the CD that is no longer in the drive.
    I drink to make other people more interesting!
    [vbcode]On Error GoTo Bar[/vbcode]
    http://www.monsterlizard.com

  11. #11
    Super Moderator manavo11's Avatar
    Join Date
    Nov 2002
    Location
    Around the corner from si_the_geek
    Posts
    7,171
    Wouldn't the app end if the cd was ejected? Anyway, what you can do is this :

    Use all the subclassing stuff on your app, then when one of the drives on your computer is ejected all the code in ProcessDeviceChange will execute. Instead of the listbox stuff you can use the eject code to compare this Chr$(FirstDriveFromMask(DBVol.dbcv_unitmask)) with this Left$(App.Path, 1) (to get the drive letter that your app is in. You can probably skip this part if you have only one drive). If it is the same, unload your form. I think that'll work


    Has someone helped you? Then you can Rate their helpful post.

  12. #12
    Frenzied Member Shawn N's Avatar
    Join Date
    Dec 2001
    Location
    Houston
    Posts
    1,631
    If I was doing this project, I'd check at startup to see if my app was already running. You could use FindWindow to look for your application (I'm not sure about PrevInstance).


    If it was already running, you could just unload.
    Please rate my post.

  13. #13

    Thread Starter
    Frenzied Member blindlizard's Avatar
    Join Date
    Feb 2001
    Location
    Austin, TX - United States of America
    Posts
    1,141
    manavo11, I think that will work, thanks I'll try that.

    Shawn N, that would be easiest, but I don't think it will do what I need because, if he ejects the CD and dosent put a new one in, the app will stay running. Then if he tries to open one of the movies it will error out because the path won't exist anymore.
    I drink to make other people more interesting!
    [vbcode]On Error GoTo Bar[/vbcode]
    http://www.monsterlizard.com

  14. #14
    Frenzied Member Shawn N's Avatar
    Join Date
    Dec 2001
    Location
    Houston
    Posts
    1,631
    Nothing a little error handling couldn't handle.
    Please rate my post.

  15. #15

    Thread Starter
    Frenzied Member blindlizard's Avatar
    Join Date
    Feb 2001
    Location
    Austin, TX - United States of America
    Posts
    1,141
    Yeah, I hear you, but I can't very well popup a message to him because he can't read. I think it would be less confusing in the long run to lhave the app go away. He can understand that you put the CD in, play movies, and remove the CD. Oh, and my 2 year old is using these now too.
    I drink to make other people more interesting!
    [vbcode]On Error GoTo Bar[/vbcode]
    http://www.monsterlizard.com

  16. #16
    Frenzied Member Shawn N's Avatar
    Join Date
    Dec 2001
    Location
    Houston
    Posts
    1,631
    Yea, I was thinking about that right after my post.
    Please rate my post.

  17. #17
    Super Moderator manavo11's Avatar
    Join Date
    Nov 2002
    Location
    Around the corner from si_the_geek
    Posts
    7,171
    Let me know how it works out


    Has someone helped you? Then you can Rate their helpful post.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width