how to link the windows shutting and program
hi,
i want my program to sthut down when the windows shuts down. It is dialog based applicatoin.
How to do it?
regards
Anima
[149 byte] By [
anima_sg] at [2007-11-18 1:38:20]

# 4 Re: how to link the windows shutting and program
Hello Guys!
Check this out its form MSDN :
WM_QUERYENDSESSION:
The WM_QUERYENDSESSION message is sent when the user chooses to end the session or when an application calls the ExitWindows function. If any application returns zero, the session is not ended. The system stops sending WM_QUERYENDSESSION messages as soon as one application returns zero.
After processing this message, the system sends the WM_ENDSESSION message with the wParam parameter set to the results of the WM_QUERYENDSESSION message.
A window receives this message through its WindowProc function.
LRESULT CALLBACK WindowProc(
HWND hwnd, // handle to window
UINT uMsg, // WM_QUERYENDSESSION
WPARAM wParam, // not used
LPARAM lParam // logoff option
);
Parameters:
wParam :
This parameter is reserved for future use.
lParam :
Specifies whether the user is logging off or shutting down the system. If this parameter includes the ENDSESSION_LOGOFF value, the user if logging off. (Note that this parameter is a bit mask. To test for this value, use a bitwise operation; do not test for equality.)
Windows 2000:
If this parameter is zero, the system is shutting down.
Return Values:
If an application can terminate conveniently, it should return TRUE; otherwise, it should return FALSE.
Remarks:
By default, the DefWindowProc function returns TRUE for this message.
Windows NT/2000:
When an application returns TRUE for this message, it receives the WM_ENDSESSION message and it is terminated, regardless of how the other applications respond to the WM_QUERYENDSESSION message.
Windows 95/98:
After all applications return TRUE for this message, they receive the WM_ENDSESSION and they are terminated.
Hope this can help :)
Aamir!
# 6 Re: how to link the windows shutting and program
anima_sg!
U need no GUI to receive this message, what u need is a "WndProc" in ur exe (or a message handler in MFC) so that it can wrestle with this message. This message is broadcasted when windows is shutting down or user tries to logoff. If u have difficulty using it, i'll try to send a sample to u.
Aamir!
# 9 Re: how to link the windows shutting and program
Hello anima_sg!
Here is a sample application but it is is Win32, i hope u can convert it into MFC else i'll try to do it for u :)
I was having some difficulty with MessageBox so i created my own dialog for this purpose, this program will not allow to shutdown or logoff and neither it will close by itself, u'll have to kill it through Task Manager.
Any difficulty, ur free to ask.
Aamir!