Control WINDOWS shutdown in the C ++ builder program

Source: Internet
Author: User
In C ++ BuilderProgramWindows Shutdown

2000-08-16 14:20:07

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.

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.