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.
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
Comment