VB 6.0 When developing an application, the user requests to add direct shutdown functions inside the program, so that the operation is all internally performed in the application. To this end, the author programming the program, the Windows API function call, successfully implemented the Windows 9x "shutdown system" simulation function, meeting the user requirements, and now the design process is listed as follows:
First, design shutdown system interface
New Engineering Files and Forms Form1, Form1 Add Options Option1, Option2, Option3, and set their CAPTION attribute to "Turn off the computer (S)", "Restart your computer (R)", "Close all programs and other User login "; add the command button Command1 and Command2, Command3 and the CAPTION attribute is set to" Yes "," No "," Help ". That is, a simulation interface for Windows 98 "Close System" is designed.
Second, the general event code is declared for the API function exitwindowsex ()
When VB 6.0 application is designed, call the rich Windows API function to complete the VB itself does not provide or cannot be implemented. These functions belong to the "operating system" level, which enables the application to add a lot of colors. The exitwindowsex () function has the function of turning off the Windows system, and must declare before calling:
Declare function exitwindowsex lib "user32" (byval uflags as long) AS Long
Parameter Description: This function has two parameters vflags, dwreserved, where the VFlags parameter determines the shutdown operation that the user needs to do, the dwreserved parameter is not used as a reservation.
The VFlags parameter can take the following constants (or the corresponding value):
EWX_SHUTDOWN 1 Turn off the computer
EWX_REBOOT 2 restart your computer
EWX_LOGOFF 0 Close all programs and log in as other users
Third, the shutdown function All program code list is as follows:
'Universal code to the exitwinwodsex () function declaration
Private Declare Function EXITWINDOWSEX LIB "User32" (Byval dwreserved as long) AS Long
Const shutdown = 1
Const reboot = 2
Const logoff = 0
Private submmand1_click ()
DIM SH As Long
If Option1.Value = true kil
'Turn off computer options
Sh = exitwindowsex (shutdown, dwreserved)
END IF
If Option2.Value = TRUE THEN
'Restarting the computer option
Sh = exitwindowsex (reboot, dwreserved)
END IF
If Option3.Value = True Then
'Close all programs and other users
As a login option
SH = EXITWINDOWSEX (Logoff, DwReServed)
END IF
End Sub
Private sub fascist2_click ()
Unload me
End Sub
The F5 runs the program, which is turned off! This feature joins the application developed by the user, quite practical.