如何知道windows关闭:
It is possible for you to detect when windows is being shutdown and to prevent this shutdown from within a running Delphi application. The simple solution is to add an event handler to the main form's OnCloseQuery event. This event handler occurs as a result of a WM_QUERYENDSESSION message which is sent to all running application in Windows when Windows is about to be shut down. The boolean CanClose parameter to this event can be set to True to allow Windows to shut down or, CanClose can be set to False to prevent Windows from shutting down. The code below illustrates using this event. procedure TForm1.FormCloseQuery(Sender: TObject; var CanClose: Boolean);
begin
// Ask user if shutdown should occur.
if MessageDlg('Are you sure?', mtConfirmation, mbYesNoCancel, 0) = mrYes
then CanClose := true // Allow Windows to shut down.
else CanClose := false; // Prevent Windows from shutting down.
end; 如何将机器转为睡眠:
Uses
Windows;procedure SuspendComputer(Force:Boolean);
begin
SetSystemPowerState(FALSE,Force);
end;
It is possible for you to detect when windows is being shutdown and to prevent this shutdown from within a running Delphi application. The simple solution is to add an event handler to the main form's OnCloseQuery event. This event handler occurs as a result of a WM_QUERYENDSESSION message which is sent to all running application in Windows when Windows is about to be shut down. The boolean CanClose parameter to this event can be set to True to allow Windows to shut down or, CanClose can be set to False to prevent Windows from shutting down. The code below illustrates using this event. procedure TForm1.FormCloseQuery(Sender: TObject; var CanClose: Boolean);
begin
// Ask user if shutdown should occur.
if MessageDlg('Are you sure?', mtConfirmation, mbYesNoCancel, 0) = mrYes
then CanClose := true // Allow Windows to shut down.
else CanClose := false; // Prevent Windows from shutting down.
end; 如何将机器转为睡眠:
Uses
Windows;procedure SuspendComputer(Force:Boolean);
begin
SetSystemPowerState(FALSE,Force);
end;
解决方案 »
免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货