CD-Laufwerk wurde geöffnet?
Verfasst: 26.11.2006 23:07
Hmmm, gibt es irgendeine Möglichkeit, mit der man feststellen kann ob ein Laufwerk geöffnet/geschlossen wurde? Ich nehm mal an, über Winapi?
Code: Alles auswählen
Global OldProc.l
g_lOldProc.l = SetWindowLong_(MeinHWND, GWL_WNDPROC, @WndProc)
Code: Alles auswählen
Procedure.l WndProc(hWnd.l, Msg.l, wp.l, lp.l)
If Msg.l = WM_DEVICECHANGE
If wp.l = DBT_DEVICEARRIVAL
; CD geöffnet
EndIf
If wp.l = DBT_DEVICEREMOVECOMPLETE
; CD geschlossen
EndIf
EndIf
ProcedureReturn CallWindowProc_(OldProc.l, hWnd.l, Msg.l, wp.l, lp.l)
EndProcedure
Code: Alles auswählen
SetWindowLong_(MeinHWND, GWL_WNDPROC, OldProc.l)
Code: Alles auswählen
Global ret$
ret$ = Space(255)
;
If OpenWindow(0, 10, 10, 500, 320, "CD - ROM Test", #PB_Window_SystemMenu|#PB_Window_MinimizeGadget|#PB_Window_ScreenCentered)
If CreateGadgetList(WindowID(0))
ButtonGadget(1, 5, 10, 80, 20, "Ende")
ButtonGadget(2, 100, 10, 80, 20, "Open Door")
ButtonGadget(3, 200, 10, 80, 20, "Close Door")
ButtonGadget(4, 300, 10, 80, 20, "Status")
ButtonGadget(5, 400, 10, 80, 20, "Modus")
ListViewGadget(6, 10, 50, 380, 250)
EndIf
Repeat
EventID.l = WaitWindowEvent()
Select EventID
Case #PB_Event_CloseWindow
Quit = 1
Case #PB_Event_Gadget
Select EventGadget()
Case 1
Quit = 1
Case 2
; Open door
mciSendString_("set cdaudio door open", ret$, 0, 0)
Case 3
; Close door
mciSendString_("set cdaudio door closed", ret$, 0, 0)
Case 4
; Status
;mciSendString_("status cdaudio ready", ret$, 255, 0)
; liefert true, wenn das CD Laufwerk bereit ist.
mciSendString_("status cdaudio media present", ret$, 255, 0)
Select ret$
Case "true"
AddGadgetItem(6, -1, "Status : " + "CD - ROM im Laufwerk !")
Case "false"
AddGadgetItem(6, -1, "Status : " + "KEINE CD - ROM im Laufwerk !")
EndSelect
Case 5
; Modus (zeigt aktuellen Status an)
mciSendString_("status cdaudio mode", ret$, 255, 0)
AddGadgetItem(6, -1, ret$)
EndSelect
EndSelect
Until Quit = 1
EndIf
End
Code: Alles auswählen
; CD subclassing
; Volker Schmid
; PureBasic V4
#MainWin = 0
#Info = 1
#Text = 2
#WM_DEVICECHANGE = $0219
#DBT_DEVICEARRIVAL = $8000
#DBT_DEVICEREMOVECOMPLETE = $8004
#GWL_WNDPROC = -4
Global OldProc.l
Procedure.l WndProc(hwnd.l, msg.l, wp.l, lp.l)
; subclass routine
If msg.l = #WM_DEVICECHANGE
; devicemessage
If wp.l = #DBT_DEVICEARRIVAL
; CD closed
SetGadgetText(#Text, "drive-state: closed")
EndIf
If wp.l = #DBT_DEVICEREMOVECOMPLETE
; CD opened
SetGadgetText(#Text, "drive-state: open")
EndIf
EndIf
; continue with the original routine
ProcedureReturn CallWindowProc_(OldProc.l, hwnd.l, msg.l, wp.l, lp.l)
EndProcedure
If OpenWindow(#MainWin, 100, 100, 195, 140, "CD subclassing test", #PB_Window_SystemMenu)
CreateGadgetList(WindowID(#MainWin))
TextGadget(#Info, 10, 10, 160, 80, "Shows the state of the CD tray. Remind, that closing may take a while until windows recognizes the medium.")
TextGadget(#Text, 10, 100, 160, 20, "drive-state: actual undefined")
; start subclassing
OldProc.l = SetWindowLong_(WindowID(#MainWin), #GWL_WNDPROC, @WndProc())
Repeat
EventID.l = WaitWindowEvent()
If EventID.l = #PB_Event_CloseWindow ; If the user has pressed on the close button
Quit.l = 1
EndIf
Until Quit.l = 1
; stop subclassing
SetWindowLong_(WindowID(#MainWin), #GWL_WNDPROC, OldProc.l)
; close window
CloseWindow(#MainWin)
End
Else
; cant create window
EndIf
Code: Alles auswählen
AnzahlLW.l=InitAudioCD()
Debug AnzahlLW
If AnzahlLW>0
UseAudioCD(0)
EjectAudioCD(0)
Delay(3000)
RunProgram("C:\WINDOWS\explorer.exe", ProgramParameter(0),"")
Pfad.s=FormatDate("%yyyy%mm%dd-%hh%ii",Date())
R.l=0
While R<10
Delay(2000)
If CopyDirectory(ProgramParameter(0),ProgramParameter(1)+"\"+Pfad+"\", "", #PB_FileSystem_Recursive)=0
R+1
Else
R=10
EndIf
Wend
EndIf