react on rundown?
react on rundown?
hallo,
is it possible to dedect a "end task" signal in pb?So I can do some imprtend stuff? Like, for example, the notepad ask to save unsaved text when I do an "End Task" in the Taskmanager.
is it possible to dedect a "end task" signal in pb?So I can do some imprtend stuff? Like, for example, the notepad ask to save unsaved text when I do an "End Task" in the Taskmanager.
Re: react on rundown?
> is it possible to dedect a "end task" signal in pb?
I don't think so. By design, ending a task with the Task Manager means
the task doesn't know it's going to happen. Fred's reply about the two
EndSession flags are only for when Windows itself is exiting.
I don't think so. By design, ending a task with the Task Manager means
the task doesn't know it's going to happen. Fred's reply about the two
EndSession flags are only for when Windows itself is exiting.
>I don't think so. By design, ending a task with the Task Manager means
>the task doesn't know it's going to happen. Fred's reply about the two
>EndSession flags are only for when Windows itself is exiting.
I think you are talkng about "end process" thats different from "end task", you can try it with notepad, "end process" kills notepad, and any unsaved data are lost, but with a "end task" notepad will ask you if you want to save the data before stopping.
Spock!
>the task doesn't know it's going to happen. Fred's reply about the two
>EndSession flags are only for when Windows itself is exiting.
I think you are talkng about "end process" thats different from "end task", you can try it with notepad, "end process" kills notepad, and any unsaved data are lost, but with a "end task" notepad will ask you if you want to save the data before stopping.
Spock!
> I think you are talkng about "end process" thats different from "end task"
Actually, it all depends on which version of Windows you're using.
Windows 9x uses an "End Task" button (in CTRL+ALT+DEL) to kill a process,
but Windows 2K/XP uses "End Process" as the button name. Both buttons
will kill the app without the app knowing it's going to happen.
Actually, it all depends on which version of Windows you're using.
Windows 9x uses an "End Task" button (in CTRL+ALT+DEL) to kill a process,
but Windows 2K/XP uses "End Process" as the button name. Both buttons
will kill the app without the app knowing it's going to happen.
-
- Enthusiast
- Posts: 628
- Joined: Fri Feb 20, 2009 9:24 am
- Location: Almaty (Kazakhstan. not Borat, but Triple G)
- Contact:
Re: react on rundown?
after 7 years i am still know how to made it 
i have 2 part of code:
and
the second example is stop the windows shutdown. how i can make like this, but not to stop - only pause. when my programm is made some before quit code, only after this shutdown (or restart, or logoff) is remain.

i have 2 part of code:
Code: Select all
Declare.l MyWindowCallback(WindowID, Message, wParam, lParam)
OpenWindow(0,0,0,320,200, "Test Window",#PB_Window_SystemMenu)
SetWindowCallback(@MyWindowCallback())
Procedure.l MyWindowCallback(WindowID, Message, wParam, lParam)
Result = #PB_ProcessPureBasicEvents
If Message = $16 ; End Session Message
If wParam
; the section is ending
If lParam
;user is logging off
MessageRequester("X", "User is is logging off.")
Else
;user is shutting down the system.
MessageRequester("X", "User is shutting down the system.")
EndIf
EndIf
EndIf
ProcedureReturn Result
EndProcedure
Repeat
If WaitWindowEvent() = #PB_Event_CloseWindow: Break: EndIf
ForEver
Code: Select all
Procedure WindowsCallback(WindowID,Message,wParam,lParam)
If Message=#WM_QUERYENDSESSION
ProcedureReturn 0 ; Aborts shutdown.
Else
ProcedureReturn #PB_ProcessPureBasicEvents
EndIf
EndProcedure
OpenWindow(0,200,200,300,100,"Try to shutdown!",#PB_Window_SystemMenu)
SetWindowCallback(@WindowsCallback())
Repeat :
Until WaitWindowEvent()=#PB_Event_CloseWindow
- netmaestro
- PureBasic Bullfrog
- Posts: 8451
- Joined: Wed Jul 06, 2005 5:42 am
- Location: Fort Nelson, BC, Canada
Re: react on rundown?
The OS is going to wait until it gets a response from all the running processes before shutting down. Any process that returns #Null from WM_QUERYENDSESSION will stop the shutdown, but you don't want to return #Null, you just want to take some action and then, when you're ready, return #True:
Code: Select all
Procedure WindowsCallback(WindowID,Message,wParam,lParam)
If Message=#WM_QUERYENDSESSION
result = MessageRequester("Note:", "Save <project name here> before windows shutdown?", #PB_MessageRequester_YesNoCancel)
If result = #PB_MessageRequester_Yes
; simulate a save
If CreateFile(0, GetTemporaryDirectory()+"test.txt")
WriteString(0, "Saved stuff!")
CloseFile(0)
EndIf
EndIf
ProcedureReturn #True
Else
ProcedureReturn #PB_ProcessPureBasicEvents
EndIf
EndProcedure
OpenWindow(0,200,200,300,100,"Try to shutdown!",#PB_Window_SystemMenu)
SetWindowCallback(@WindowsCallback())
Repeat : Until WaitWindowEvent()=#PB_Event_CloseWindow
BERESHEIT
Re: react on rundown?
> The OS is going to wait until it gets a response from all the running processes before shutting down
Not quite. It does shut down after a specific time (default is 20 seconds).
There are many web sites that explain how to change that timeout in the
Registry to force a fast shutdown without letting apps save their data.
Not quite. It does shut down after a specific time (default is 20 seconds).
There are many web sites that explain how to change that timeout in the
Registry to force a fast shutdown without letting apps save their data.
I compile using 5.31 (x86) on Win 7 Ultimate (64-bit).
"PureBasic won't be object oriented, period" - Fred.
"PureBasic won't be object oriented, period" - Fred.
-
- Enthusiast
- Posts: 628
- Joined: Fri Feb 20, 2009 9:24 am
- Location: Almaty (Kazakhstan. not Borat, but Triple G)
- Contact:
Re: react on rundown?
didnt work
this dialog Y/N is shows, but windows shutdown is continued, and after a few seconds program still terminated uncorrectly.
for test - try to restart or shutdown windows xp when in microsoft office word document present not saved data - he will waite as long, as you need to press button.
i think must be some pause win api command... the truth is out there.
maybe like this will work:
1. detecting what exactly happening restart, shutdown or logoff
2. full stop shutdown process
3. run some "prepeare for end" code
4. start windows restart, shutdown or logoff - that we detect in "1" - by my programm herself

for test - try to restart or shutdown windows xp when in microsoft office word document present not saved data - he will waite as long, as you need to press button.
i think must be some pause win api command... the truth is out there.
maybe like this will work:
1. detecting what exactly happening restart, shutdown or logoff
2. full stop shutdown process
3. run some "prepeare for end" code
4. start windows restart, shutdown or logoff - that we detect in "1" - by my programm herself
- doctorized
- Addict
- Posts: 882
- Joined: Fri Mar 27, 2009 9:41 am
- Location: Athens, Greece
Re: react on rundown?
PB is right, there is no 'End Proccess' event.
If we need to be a little more accurate, but not 100%:
If we need to be a little more accurate, but not 100%:
Code: Select all
Declare.l MyWindowCallback(WindowID, Message, wParam, lParam)
OpenWindow(0,0,0,320,200, "Test Window",#PB_Window_SystemMenu)
SetWindowCallback(@MyWindowCallback())
Procedure.l MyWindowCallback(WindowID, Message, wParam, lParam)
Result = #PB_ProcessPureBasicEvents
If Message = $10; we closed the program from the 'Programs' tab.
MessageRequester("X","we closed the program from the 'Programs' tab.")
ElseIf Message = $112; we closed the program from the windows bar
MessageRequester("ok","we closed the program from the windows bar")
ElseIf Message = $16 ; End Session Message
MessageRequester("ok","$16")
If wParam
; the section is ending
If lParam
;user is logging off
MessageRequester("X", "User is is logging off.")
Else
;user is shutting down the system.
MessageRequester("X", "User is shutting down the system.")
EndIf
EndIf
EndIf
ProcedureReturn Result
EndProcedure
Repeat
If WaitWindowEvent() = #PB_Event_CloseWindow: Break: EndIf
ForEver
; after message $112 these messages are following: $90, 2, $82.