Back to Amir Israeli Homepage

[CBoot : boot your P.C. programmaticly ]

This article was contributed by Amir Israeli Amir Israeli.
Amir Israeli Web Site

Environment: Win 95/98 VC6 SP1

CBoot is a very simple class : if provides 4 basic function to perform various types of computer boot , OS boot etc.
You understand what each one is doing from the name :

	static BOOL Logoff(BOOL bEmergency=FALSE,BOOL bShowWarning=FALSE);
	static BOOL Poweroff(BOOL bEmergency=FALSE,BOOL bShowWarning=FALSE);
	static BOOL Reboot(BOOL bEmergency=FALSE,BOOL bShowWarning=FALSE);
	static BOOL Shutdown(BOOL bEmergency=FALSE,BOOL bShowWarning=FALSE);
since the functions are static you don't have to instantiate the class: you simply call CBoot::LogOff(); to log-off with default behaveiour. The function where all job happens is a static one : CBoot::Boot .This function calls the API : ExitWindowEx.

The boot process works as follows : if an application wishes to boot : it (you - the programmer) calls ExitWindowsEx(UINT nFlags ,0); with desired flags. this function sends WM_QUERYENDSESSION message to all aplications (top level windows) with 0 in WPARAM (reserved) and flags of boot in LPARAM. Every application may (should) override this function and do his own set of end-session activities (such as destroying heap , relase all memory, save state). If an application allows its own termination it return TRUE. (This is also the default behaviour in DefWindowProc) but if it doesn't : it return FALSE . If doing that termination is canceled (an Exit windows dialog is being shown by window). All this is true whenever ExitWindowsEx is conditional : it wont continue if one application disapprove . Adding EWX_FORCE to flags forces boot and application responces aren't checked.


All these functions include 2 additional parameters that get default values : BOOL bEmergency causes the function to add EWX_FORCE to ExitWindowsEx flags to force boot : even if the top level window doen't respond : TRUE; but you may loose unsaved information. BOOL bShowWarning=TRUE adds a dialog (of type MessageBox) of warning , the dialog is located in Warning function. You may change this function to modify the MB_YESNO|MB_ICONWARNING type of MessageBox.

Downloads

Download demo project - 35 Kb
Download source - 2 Kb

History

Date Posted: December 20, 2000

Home  |  Links  |  About