ShutdownBlockReasonCreate
Posted: Thu Mar 31, 2011 10:55 am
I've tried to create a ShutdownBlockReason for Vista/Win7 Users to show them a reason for the block (instead Windows shows just that it's blocking for unknown reason). It works as I need it so far if I use via Prototype. But if I use via "Import" I got Unresolved symbol error instead. I prefer to use as "Import" cause there is a *.lib available I guess... so I wonder how to do it via import?
Code: Select all
; Does not work via Import that way:
; Import("user32.lib")
; ShutdownBlockReasonCreate(hWnd.i, *pwszReason)
; ShutdownBlockReasonDestroy(hWnd.i)
; EndImport
Prototype ProtoShutdownBlockReasonCreate(hWnd.i, *pwszReason)
Prototype ProtoShutdownBlockReasonDestroy(hWnd.i)
If OpenLibrary(0, "user32.dll")
Global ShutdownBlockReasonCreate.ProtoShutdownBlockReasonCreate = GetFunction(0, "ShutdownBlockReasonCreate")
Global ShutdownBlockReasonDestroy.ProtoShutdownBlockReasonDestroy = GetFunction(0, "ShutdownBlockReasonDestroy")
CloseLibrary(0)
EndIf
Procedure unicodePtr(string.s)
If string.s
*ptr = AllocateMemory(StringByteLength(string.s,#PB_Unicode))
PokeS(*ptr,string.s,StringByteLength(string.s,#PB_Unicode),#PB_Unicode)
ProcedureReturn(*ptr)
EndIf
EndProcedure
Procedure WindowsCallback(WindowID,Message,wParam,lParam)
If Message=#WM_QUERYENDSESSION
block_reason.s = "Download is still in progress."
ShutdownBlockReasonCreate(WindowID(0), unicodePtr(block_reason.s))
result = MessageRequester("Warning", block_reason.s+" Abort shutdown?", #PB_MessageRequester_YesNoCancel)
If result = #PB_MessageRequester_Yes
AbortSystemShutdown_(#Null)
Else
ShutdownBlockReasonDestroy(WindowID(0))
ProcedureReturn #True
EndIf
ProcedureReturn #False
Else
ProcedureReturn #PB_ProcessPureBasicEvents
EndIf
EndProcedure
; Testing
If OpenWindow(0,0,0,200,100,"Shutdown and wait")
SetWindowCallback(@WindowsCallback())
Repeat
Until WaitWindowEvent() = #PB_Event_CloseWindow
EndIf