HOWTO: Terminate Windows From a 16-Bit VB ApplicationID: Q142820
|
The Microsoft Visual Basic for Windows SendKeys function cannot be used to
close the Microsoft Windows Program Manager in order to terminate Microsoft
Windows. To correctly close Program Manager, you must invoke the
ExitWindows API function, as shown below.
Many software setup or installation programs are designed to exit Windows,
and then restart Windows when the setup or installation is complete. You
can make a Visual Basic program automatically exit Windows and then restart
Windows by passing the EW_RESTARTWINDOWS value to the ExitWindows API
function. The value for the EW_RESTARTWINDOWS constant is &H42.
You may want to terminate the current Windows session by closing the
Program Manager from within a Visual Basic application. You may think that
you can activate the Program Manager control menu and send the appropriate
key sequences using the Visual Basic SendKeys function. However, this
method does not work because after the Close menu item is chosen, a system
modal dialog box is opened that prompts you to save changes to Program
Manager. A system modal dialog box locks out ALL other programs until it is
satisfied. Therefore, the keystroke you send by using the SendKeys function
never arrives in the dialog box.
To correctly close Program Manager, you must use the ExitWindows API
function. You can declare this API function in a code module name Module1.
' Use for Windows 3.11 or Windows for Workgroups 3.11 applications:
Declare Function ExitWindows Lib "user" (ByVal wReturnCode as Long, _
ByVal dwReserved as Integer) as Integer
' Use for Windows 95/98 or Windows NT applications:
Declare Function ExitWindows Lib "user32" alias "ExitWindowsEx" _
(ByVal wReturnCode as Long, ByVal dwReserved as Long) as Long
' Use for Windows 3.11 or Windows for Workgroups 3.11 applications:
RetVal% = ExitWindows(0,0)
' Use for Windows 95/98 or Windows NT Applications:
RetVal& = ExitWindows(0&, 0&)
AppActivate("Program Manager")
SendKeys "%{ }{DOWN 5}{ENTER 2}", 0 'ALT, SPACE, DOWN 5, ENTER 2
Additional query words: kbVBp400 kb16bitonly kbVBp kbCtrl
Keywords : kb16bitonly kbCtrl kbVBp kbVBp400
Version : WINDOWS:4.0
Platform : WINDOWS
Issue type : kbhowto
Last Reviewed: May 28, 1999