Click here to Skip to main content
15,888,454 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi All

Is there any way to identify that the restart/Shut Down button was pressed in my program.

Thanks in advance!
Posted

1 solution

You can handle the WM_QUERYENDSESSION message.

MFC wraps this as CWnd::OnQueryEndSession.
 
Share this answer
 
v2
Comments
Ivan Ivanov 83 3-Nov-10 10:39am    
Well I did a bit silly :). I wanted to keep the question short but I instead made it too short! :D What I'll write now had to be in the question itself.

In my program I need to show for how long the PC is running since it was turned on. But not like what you see in the LAN status window. If I restart the time interval keeping variable shown by the program should be saved and shown after reentry in Win (Because the PC wasn't physically turned of). And if I press the Shut Down button that shouldn't happen. You see I need two different behaviours on pressing restart and shut down so my question was really missleading, sorry.

I actually started writing this but I've deleted it 'cause I thought it was clear enough. (obviously I was wrong)
Nish Nishant 3-Nov-10 10:43am    
Unfortunately, WM_QUERYENDSESSION won't let you differentiate between a shutdown and a reboot. A reboot is still a shutdown, if you think of it. Except that the machine is instantly turned on after shutting down. So you could still handle it that way I guess.
Ivan Ivanov 83 3-Nov-10 11:17am    
"A reboot is still a shutdown, if you think of it. Except that the machine is instantly turned on after shutting down" That is absolutely true for laptops but desktops are different sotry ;) none of the PC components is powered off by the issues reset signal. but that's an interesting point :)if I have to make difference between laptops and desktops I better leave it like it is now (the functionality is implemented only ti resets after restart) maybe I really sholdn't make it so complicated. :) Otherwise I had that idea to capture a handle of the very window that holds the <stand by=""><shut down=""><restart> buttons and get the return code... Do you think that could work out? :)
Nish Nishant 3-Nov-10 11:38am    
You could write a hook that will monitor for clicks on the start menu shutdown menu items, that would work. It'll be different for different versions of Windows because of the positioning of the menu items. And in older versions like XP, you actually have a non-hookable dialog where the selection between reboot, logoff, and shutdown are made.
Ivan Ivanov 83 3-Nov-10 16:56pm    
Thanks I'll cosider this :)

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900