The deal is, i want to stop an AudioCd from starting the default AudioPlayer when the Cd is inserted:
I can stop any AutoRun Cd like your Windows cd or even Rings' Winblows 89, it's pretty simple.
But how cant i prevent an audiocd when inserted from launching the default player.
According MS there is 3 wayes to do that.
http://msdn.microsoft.com/library/defau ... ay_reg.asp
1. The user holds the ShiftKey down when the Cd is inserted ( I don't wanna do that.)
2. Messing with the user's Registry to disable autorun ( I don't wanna do that either.)
3. Use RegisterWindowMessage_("QueryCancelAutoPlay") and catch it from callback and deny it from there. (preffered)
This require your app. to be on top to receive the message.
That is just what i want.
The following code should prevent any autorun cd's from starting when inserted, but not an audiocd
well not on my system atleast.
(That is, it prevents it from playing of course, as im using it, but not from starting the default player )
But but. How in >>***-!!!-##<< are you suppose to stop an audiocd from running when inserted?
without the shiftkey og the regstry that is. ?
Btw. the #WM_DEVICECHANGE is not needed to prevent autorun it's just there because i have tried goddamed every thing but the right thing, i guess.
in this cleand up Ex. it's there mostly because somebody might find it interesting
Code: Select all
; This code will stop autorun cd from starting
; but not an audio cd (well not on my systen atleast)
; **. Remember this app. need to be on top most otherwise it won't catch the message!
Global MsgID.l,DoneTic.l,gettic.l
#Eject=$8004
#Insert=$8000
#MSGID = "QueryCancelAutoPlay"
#WM_DEVICECHANGE = 537
Procedure WindowCallback(WindowID, Message, wParam, lParam)
Result = #PB_ProcessPureBasicEvents
If message = MsgID
SetGadgetText(4, ">> ** QueryCancelAutoPlay ** : "+Str(MsgID)+" <<")
;Returning 0 = False AutoPlay is on
Result = 1 ; Returning 1 = True AutoPlay is disable
EndIf
If message = #WM_DEVICECHANGE
If wParam=#Eject
SetGadgetText(2, ">> DeviceChange ** Ejected ** :"+Hex(wParam)+" <<")
ElseIf wParam=#Insert
SetGadgetText(3, ">> DeviceChange ** Inserted ** :"+Hex(wParam)+" <<")
DoneTic=gettickcount_() +5000
gettic=1
EndIf
;Result = 1
EndIf
ProcedureReturn Result
EndProcedure
Procedure Open_Window_0()
If OpenWindow(0, 216, 0, 369, 150, #PB_Window_SystemMenu | #PB_Window_MinimizeGadget | #PB_Window_MaximizeGadget | #PB_Window_SizeGadget | #PB_Window_TitleBar , "Test AutoPlay")
If CreateGadgetList(WindowID())
ButtonGadget(0, 15, 25,150, 20,"Test Eject CD")
ButtonGadget(1, 175, 25,150, 20,"Test Insert Cd")
StringGadget(2, 13, 60,270, 20, "DeviceChange Eject : idel")
StringGadget(3, 13, 90, 270, 20, "DeviceChange Insert: idel")
StringGadget(4, 13, 120, 270, 20,"QueryCancelAutoPlay: idel")
EndIf
EndIf
EndProcedure
Open_Window_0()
SetWindowCallback(@WindowCallback())
MsgID = RegisterWindowMessage_(#MSGID)
Repeat
If DoneTic <=gettickcount_() And gettic
SetGadgetText(2, "DeviceChange Eject : idel")
SetGadgetText(3, "DeviceChange insert: idel")
SetGadgetText(4, "QueryCancelAutoPlay: idel")
gettic=0
EndIf
EventID = WaitWindowEvent()
Select EventID
Case #PB_EventGadget
Select EventGadgetID()
Case 0
mciSendString_("open cdaudio alias cd", "", 0,0);
mciSendString_( "set cd door open wait", "", 0,0)
Case 1
mciSendString_("set cd door closed wait", "", 0,0)
EndSelect
; Case MsgID
; SetGadgetText(#Gadget_1, "bla..")
Case #PB_Event_CloseWindow
Quit = 1
EndSelect
Until Quit
End
Henrik
