When actual application, some settings of the system must be restarted; and sometimes the time is demonstrated.
After a software, Windows must be turned off; and during the demo, the user will prohibit the user from turning off Windows. How to
Solving the above problems, the author has comprehensively solved the above problems.
Realization Principle: 1. Restart Windows, turn off Windows, ending the current user process is implemented by calling the ExitWindowSex function. This function has two parameters, the previous parameter uses EWX_force to represent the forcibly shut down Windows without reminding other applications Run the result, the latter parameter EWX_LOGOFF indicates that the current user process is logged out; EWX_SHUTDOWN indicates to turn off Windows; EWX_reboot indicates restarting Windows. 2. Prohibiting shutting down Windows is a message to each application WM_QUERYENDSESSION, notify each application The program is to shut down, such as the message value of feedback is 0, then Windows98 cannot be turned off. Figure 1 Application example:
Establish a form containing the following controls:
Control control name CAPTION
Form1 restart Windows system
Check box Checkbox1 forcibly ending the current user process
Check box Checkbox2 forced shutdown
Check box Checkbox3 forcibly restarting the machine
Check box Checkbox4 prohibited shutdown
Check box Checkbox5 exit
2. List of procedures:
Unit CLSW;
Interface
Uses
Windows, Messages, Sysutils, Classes, Graphics, Controls, Forms, Dialogs,
STDCTRLS;
Type
TFORM1 = Class (TFORM)
Checkbox1: Tcheckbox;
Checkbox2: tcheckbox;
Checkbox3: Tcheckbox;
Checkbox4: tcheckbox;
Checkbox5: Tcheckbox;
Procedure Checkbox1click (Sender: TOBJECT);
Procedure CheckBox2Click (Sender: TOBJECT);
Procedure CheckBox3Click (Sender: TOBJECT);
Procedure CheckBox5Click (Sender: TOBJECT);
Private
Procedure WmqueryEndSession (Var Msg: TMESSAGE);
Message WM_QUERYENDSESSION;
{Private Declarations}
public
{Public declarations}
END;
VAR
FORM1: TFORM1;
IMPLEMentation
{$ R * .dfm}
Procedure TFORM1.CHECKBOX1CLICK (Sender: TOBJECT);
Var EWX_LOGOFF, EWX_FORCE: Integer;
Begin
EWX_LOGOFF: = 0;
EWX_FORCE: = 4;
EXITWINDOWSEX (EWX_FORCE OR EWX_LOGOFF, 0);
END;
Procedure TFORM1.CHECKBOX2CLICK (Sender: TOBJECT);
Var EWX_SHUTDOWN, EWX_FORCE: INTEGER;
Begin
EWX_SHUTDOWN: = 1;
EWX_FORCE: = 4;
EXITWINDOWSEX (EWX_FORCE OR EWX_SHUTDOWN, 0);
END;
Procedure TFORM1.CHECKBOX3CLICK (Sender: TOBJECT);
Var EWX_REBOOT, EWX_FORCE: Integer;
Begin
EWX_REBOOT: = 2;
EWX_FORCE: = 4;
EXITWINDOWSEX (EWX_FORCE OR EWX_REBOOT, 0);
END;
Procedure TFORM1.WMQUERYENDSESSION (VAR MSG: TMESSAGE);
Begin
if Checkbox4.checked THEN
msg.result: = 1
Else
msg.result: = 0;
END;
Procedure TFORM1.CHECKBOX5CLICK (Sender: TOBJECT);
Begin
CLOSE;
END;
End.
The above procedures run through the Windows 98, the DEPHI 4.0 environment.