Announcement

Collapse
No announcement yet.

CD tray door open or closed?

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

  • CD tray door open or closed?

    The following code can open or close the CD tray.
    How do you check if the door is already closed?
    Would like to modify code to toggle state of CD door.

    Code:
    #COMPILE EXE  "cdtoggle.bas"
    DECLARE FUNCTION GetDriveType LIB "KERNEL32.DLL" ALIAS "GetDriveTypeA" (nDrive AS ASCIIZ) AS DWORD
    DECLARE FUNCTION mciSendString LIB "WINMM.DLL" ALIAS "mciSendStringA"   (lpstrCommand AS ASCIIZ, lpstrReturnString AS ASCIIZ, BYVAL uReturnLength AS DWORD, BYVAL hwndCallback AS DWORD) AS LONG
    DECLARE SUB opentray(letter AS ASCIIZ)
    DECLARE SUB closetray(letter AS ASCIIZ)
    FUNCTION PBMAIN()
      LOCAL drive AS LONG
      LOCAL drivetype AS LONG
      LOCAL letter AS ASCIIZ * 4
      LOCAL result AS LONG
      FOR drive = 65 TO 90
        letter = CHR$(drive) + ":\"
        drivetype = getdrivetype(letter)
        '? "drive " + letter + " type" + str$(drivetype)
        IF drivetype = 5 THEN closetray letter
      NEXT
    END FUNCTION
    SUB opentray(letter AS ASCIIZ)
      LOCAL result AS LONG
      mcisendstring "open " + letter + " type cdaudio alias cdname", "", 0,0
      mcisendstring "set cdname door " + "open ", "",0,0
      mcisendstring "close cdname", "",0,0
      END SUB
    SUB closetray(letter AS ASCIIZ)
      LOCAL result AS LONG
      mcisendstring "open " + letter + " type cdaudio alias cdname", "", 0,0
      mcisendstring "set cdname door " + "closed " , "",0,0
      mcisendstring "close cdname", "",0,0
    END SUB
    Last edited by Mike Doty; 15 Jul 2008, 12:07 AM. Reason: Questions end with a question mark not a period.
    How long is an idea?

  • #2
    I don't think any of the mcisendstring() commands can be used to determine if a CD drive is open or closed, but depending on what you're trying to do something like this may get the job done:

    Code:
    IF GetFileAttributes("H:\") = -1 THEN
        STDOUT "CD drive is either open, or closed but has no CD"
    ELSE
        STDOUT "CD drive is closed and has a CD"
    END IF
    -

    Comment

    Working...
    X