The system cannot shut down after the program has shrunk to the pallet (solution)
Sinom
when the program is minimized to the tray, there is a problem that the system cannot shut down, which is common in the WinXP system., here is a solution!
First, the solution
Responding to system shutdown messages
Procedure Wmqueryendsession (var msg:tmessage); message wm_queryendsession;
Procedure Tformtray.wmqueryendsession (var msg:tmessage);
Begin
Msg. Result: = 1;
End;
Second, the principle
Msdn:
the wm_queryendsession message is sent if the user chooses to end the session or if an application calls one of the system shutdown func tions. If any application returns zero, the session was not ended. The system stops sending wm_queryendsession messages as soon as one application returns zero.
The wm_queryendsession message is sent to all windows that have not been terminated when the dialog is closed or when a program invokes the system shutdown function. When the program is handling this message, if False (0) is returned, the system will not end the conversation or shutdown (logoff).
Windows broadcasts a message wm_queryendsession to all the top-level windows when it shuts down, and its lparam parameter can distinguish between shutting down or logging off the user (lparam is endsession_logoff when logging off the user). Then Windows will wait until all the applications return true for this message to shut down, so as long as our application returns false,windows this message will not shut down. And through this example, you should also be able to distinguish between the system shutdown and logoff users.
LRESULT CALLBACK WndProc (HWND hwnd, UINT imsg, WPARAM WPARAM, LPARAM LPARAM) {Switch(imsg) { CaseWm_destroy:postquitmessage (0) ; return 0 ; Case wm_queryendsession: // before shutting down, do something to protect the data return 1 ; // return 1 to end the program } return DefWindowProc (hwnd, imsg, WParam, LParam); }}
About the value of the lparam parameter:
Endsession_closeapp
0x00000001
The application is using a file, which must be replaced, and the system is being serviced, or system resources is exhausted. For more information, see Guidelines for applications.
Endsession_critical
0x40000000
The application is forced-shut down.
Endsession_logoff
0x80000000
The user is logging off.
More information: http://msdn.microsoft.com/en-us/library/windows/desktop/aa376890 (v=vs.85). aspx
The system cannot shut down after the program has shrunk to the pallet (solution)