| After the application is compiled, we need to design the packaging and distribution functions of the application. When compiling the installation program, you often encounter the following problem: after the program is installed, You need to restart the computer. In Code How to Control WINDOWS shutdown or restart? To implement this function, you need to use an exitwindowsex function provided by Windows API. You can view the Help file provided by C ++ builder to obtain the usage format of this function: Bool exitwindowsex ( Uint uflags, // Set shutdown Parameters DWORD dwreserved // System reserved words ); The main values and meanings of uflags are shown in table 1. Dwreserved is a reserved word of the system. Enter 0 at will. After learning how to use the exitwindowsex function, the following example describes how to control WINDOWS shutdown or restart in C ++ builder. The design steps are as follows: 1. After running the C ++ builder system, activate the "file/New Application" menu to create a new project. 2. Activate the "file/Save as" menu to save the form unit as the file name exitu. cpp, and then activate the "file/save project as" menu to save the project file as the file name expri. BPR. (Note: The project file name and form unit file name must not have the same name .) 3. add four tbutton components button1, button2, button3, and button4 to the form, set their caption attributes to "other identity Logon", "shutdown", "restart", and "Force shutdown ". 4. Set the onclick event response code of the button1, button2, button3, and button4 components respectively as follows: Void _ fastcall tform1: button1click (tobject sender) { // Log on with another identity DWORD temp; Exitwindowsex (ewx_logoff, temp ); } //------------------------------ Void _ fastcall tform1: button2click (tobject sender) { // Shutdown DWORD temp; Exitwindowsex (ewx_shutdown, temp ); } //------------------------------ Void _ fastcall tform1: button3click (tobject sender) { // Restart DWORD temp; Exitwindowsex (ewx_reboot, temp ); } //------------------------------ Void _ fastcall tform1: button4click (tobject sender) { // Force Shutdown DWORD temp; Exitwindowsex (ewx_force, temp ); } Table 1 set values Brief meaning Ewx_force Force terminate the program running and exit the system Ewx_logoff Log out and Log On As another user Ewx_reboot Restart Ewx_shutdown Shutdown 5. After running the program, click the four buttons to test their functions. If you can complete various settings, it means you have succeeded, then we can apply the methods described in this article to the self-developed C ++ Builder application to control WINDOWS shutdown. the program runs in Windows 98 and C ++ Builder 5.0. |