Here is my code to do that. Notice that you can do some quick stuff after reciving the #WM_QUERYENDSESSION
Run this code and restar or shutdown windos and you will see:
Code: Select all
Procedure WinCallback(hWnd, uMsg, wParam, lParam)
If uMsg = #WM_QUERYENDSESSION
;Do your stuff here
MessageRequester("","Oops! Windows are shuting down!!")
EndIf
ProcedureReturn #PB_ProcessPureBasicEvents
EndProcedure
If OpenWindow(0,100,150,450,200,"Windows shutdown detect",#PB_Window_SystemMenu)
SetWindowCallback(@WinCallback())
CreateGadgetList(WindowID(0))
StringGadget(1,50,50,350,20,"")
ButtonGadget(2,200,100,150,25,"Do nothing yet")
Repeat
eventID=WaitWindowEvent()
Select eventID
Case #PB_Event_Gadget
Select EventGadget()
Case 2
EndSelect
EndSelect
Until eventID=#PB_Event_CloseWindow
EndIf