I'm checking to see if I could move one or two programs to purebasic. One of them detects
a removable drive beeing inserted or removed from the system.
I tried with the code below, but can't get it to work. It detects a removable device message
but not the type (Insert, remove). I've tried Purebasic for a couple of days only, so I'm shure
there's some stupid mistake in there, but I can't see what it is!
Code: Select all
;GENERAL PROCEDURES
Global DeviceEvent
#WM_DEVICECHANGE=$219
#DBT_DEVICEARRIVAL=$8000 ;A device has been inserted
#DBT_DEVICEREMOVECOMPLETE=$8004 ;A device has been removed.
Procedure GetDeviceEvent(WindowID,Message,wParam,lParam)
;Callback procedure to catch a removable device event
Result = #PB_ProcessPureBasicEvents
If Message=#WM_DEVICECHANGE
DeviceEvent=wParam
EndIf
ProcedureReturn Result
EndProcedure
;MAIN WINDOW AND CONTROLS
;Main window flags
Flags=#PB_Window_SystemMenu|#PB_Window_ScreenCentered
Flags=Flags|#PB_Window_MinimizeGadget|#PB_Window_MaximizeGadget
;Open the main window
If OpenWindow(0,0,0,600,400,Flags,"Removable device test")=0
MessageRequester("","Error",#PB_MessageRequester_Ok)
End
EndIf
;Set the callback to catch a removable device event
SetWindowCallback(@GetDeviceEvent())
;MAIN WINDOW EVENT LOOP
Repeat
Event=WaitWindowEvent()
Select Event
Case #WM_DEVICECHANGE
Select DeviceEvent
Case #DBT_DEVICEARRIVAL
MessageRequester("","Inserted",#PB_MessageRequester_Ok)
Case #DBT_DEVICEREMOVECOMPLETE
MessageRequester("","Removed",#PB_MessageRequester_Ok)
EndSelect
Case #PB_Event_CloseWindow
;Program closed
Exit=1
EndSelect
Until Exit