home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
DP Tool Club 19
/
CD_ASCQ_19_010295.iso
/
win
/
prg
/
cenviw
/
exitwin.cmm
< prev
next >
Wrap
Text File
|
1994-09-03
|
5KB
|
159 lines
// ExitWin.cmm - Exit Windows with options to reboot system, go
// ver.1 to DOS, or run command and return, with options
// for what to do before exiting.
Instructions()
{
puts("\aExitWin - Exit Windows; optionally restart windows or system")
puts(``)
puts(`USAGE: CEnvi ExitWin <DOS | REBOOT | RESTART [Command]> [Options]`)
puts(``)
puts(`WHERE: DOS - Exit Windows and return to DOS`)
puts(` REBOOT - Exit Windows and reboot computer`)
puts(` RESTART - Exit Windows, run optional DOS Command, and restart Windows`)
puts(` Command - Optional DOS command for RESTART options`)
puts(` Options - Any of the following options may be added`)
puts(` /FILESAVE - Select the File/Save menu option for Windows`)
puts(` /FORCE - Force applications to close; may lose data`)
puts(``)
puts(`NOTE: Without the /FORCE and/or /FILESAVE option, some applications may`)
puts(` refuse to close and so Windows won't exit. With the /FORCE option`)
puts(` applications will be forced to end even if data is not saved.`)
puts(``)
puts(`EXAMPLES: CEnvi ExitWin DOS /FILESAVE /FORCE`)
puts(` CEnvi ExitWin RESTART copy C:\WIN\WIN.INI C:\WIN\WIN.BAK`)
puts(` CEnvi ExitWin REBOOT /FORCE`)
puts(``)
printf("Press any key to exit...");
getch();
exit(EXIT_FAILURE);
}
#include <OptParms.lib>
#include <Message.lib>
#include <WinTools.lib>
#include <MenuCtrl.lib>
main(argc,argv)
{
// parse input to get actions wanted
FileSave = OptionalParameter(argc,argv,"FILESAVE");
Force = OptionalParameter(argc,argv,"FORCE");
if ( 1 < argc ) {
if ( !stricmp(argv[1],"RESTART") ) {
if ( 2 == argc )
ExitFunction = "RestartWindows";
else {
ExitFunction = "RunCommandAndRestartWindows";
ExitCommands = argv + 2;
ExitCommandCount = argc - 2;
}
} else if ( argc == 2 ) {
if ( !stricmp(argv[1],"DOS") )
ExitFunction = "ExitToDOS";
else if ( !stricmp(argv[1],"REBOOT") )
ExitFunction = "ExitAndRebootComputer";
}
}
if ( !defined(ExitFunction) )
Instructions();
if ( FileSave ) {
AutoSelectFileSave();
}
if ( Force ) {
QuitAllNamedWindows();
}
// call exit function, which should not return
function(ExitFunction,ExitCommandCount,ExitCommands);
// if exit function returned then there was a problem
printf("\n\a\n");
puts(`Exit did not succeed.`)
printf("Press any key to quit...");
getch();
return EXIT_FAILURE;
}
RunCommandAndRestartWindows(argc,argv)
{
// build command parameters
lExe = defined(COMSPEC) ? COMSPEC : "COMMAND.COM";
lParms = "/C";
for ( lArg = 0; lArg < argc; lArg++ ) {
strcat(lParms," ");
strcat(lParms,argv[lArg]);
}
DynamicLink("USER","EXITWINDOWSEXEC",SWORD16,PASCAL,lExe,lParms);
}
RestartWindows()
{
#define EW_RESTARTWINDOWS 0x42
DynamicLink("USER","EXITWINDOWS",SWORD16,PASCAL,0,EW_RESTARTWINDOWS,0);
}
ExitAndRebootComputer()
{
#define EW_REBOOTSYSTEM 0x43
DynamicLink("USER","EXITWINDOWS",SWORD16,PASCAL,0,EW_REBOOTSYSTEM,0);
}
ExitToDOS()
{
DynamicLink("USER","EXITWINDOWS",SWORD16,PASCAL,0,0,0);
}
QuitAllNamedWindows() // Post WM_QUIT to all windows
{
printf("Send WM_QUIT to all windows...");
if ( lWinList = WindowList() ) {
for ( lIdx = 0; lIdx <= GetArraySpan(lWinlist); lIdx++ ) {
lWin = lWinList[lIdx];
Title = GetWindowTitle(lWin);
if ( Title && lWin != ScreenHandle() ) {
printf("\b\b\b\nQuit \"%s\"...",Title);
PostMessage(lWin,WM_QUIT,0,0);
}
}
}
printf("\b\b\b\n");
}
AutoSelectFileSave() // select File/Save wherever it is available
{
printf("Select File/Save where applicable...");
if ( lWinList = WindowList() ) {
for ( lIdx = 0; lIdx <= GetArraySpan(lWinlist); lIdx++ ) {
lWin = lWinList[lIdx];
Title = GetWindowTitle(lWin);
if ( Title && lWin != ScreenHandle() )
SelectSaveFromMenu(lWin,Title);
}
}
printf("\b\b\b\n");
}
SelectSaveFromMenu(pHwnd,pTitle) // if menu has Save, then select it
{
// get handle for the menu
if ( MenuHandle = GetMenu(pHwnd) ) {
// Get ID for the "Save" menu item
if ( SaveID = FindMenuString( MenuHandle, "File##Save", False ) ) {
// Don't select if disabled or grayed
SaveState = GetMenuState(MenuHandle,SaveID,MF_BYCOMMAND);
if ( !(SaveState & (MF_DISABLED|MF_GRAYED)) ) {
// Finally! This window has "Save", so select it
printf("\b\b\b\nFile/Save \"%s\"...",pTitle);
MenuCommand(pHwnd,SaveID,True);
}
}
}
}