The system cannot shut down after the program has shrunk to the pallet (solution)

Source: Internet
Author: User

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)

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.