/************************************************************
 *** BootEd1 - Sample Cmm code to demonstrate uses of the ***
 ***           WinExec() function.                        ***
 ************************************************************/

#include <WinExec.lib>
#include <MsgBox.lib>
#include <WinUtil.lib>

MessageBox("This example CEnvi program will start\n"
           "NotePad to edit both C:\\Config.sys and\n"
           "C:\\Autoexec.bat, and then display them\n"
           "both on the screen together.  This example\n"
           "is like BootEd2 but this uses WinExec().",
           "BootEd1 - Description");

// start up two versions of notepad with the two files we care about
MustWinExec("NotePad.exe c:\\Config.sys");
MustWinExec("NotePad.exe c:\\AutoExec.bat");

// Give the two processes 3/4 second to start up
Suspend(750);

// Get the WindowHandles for both programs by searching for their name
Config = MustGetWindowHandle("NOTEPAD - CONFIG.SYS");
AutoExec = MustGetWindowHandle("NOTEPAD - AUTOEXEC.BAT");

// position these two windows to fill the top-half and the bottom-half of
// the screen
ScreenWidth = GetSystemMetrics(SM_CXSCREEN);
ScreenHeight = GetSystemMetrics(SM_CYSCREEN);

MoveWindow(Config,0,0,ScreenWidth,ScreenHeight/2,True);
MoveWindow(AutoExec,0,ScreenHeight/2,ScreenWidth,ScreenHeight/2,True);


MustWinExec(command)
{
   result = WinExec(command);
   if ( result < 32 ) {
      sprintf(ErrorMessage,"That call to WinExec returned error: %d",ErrorNumber);
      MessageBox(ErrorMessage);
      exit(1);
   }
}

MustGetWindowHandle(title)
{
   handle = GetWindowHandle(title);
   if ( 0 == handle ) {
      sprintf(ErrorMessage,"%s did not load.",title);
      MessageBox(ErrorMessage);
      exit(1);
   }
   return(handle);
}
