home *** CD-ROM | disk | FTP | other *** search
/ PC Administrator / spravce.iso / RunModule / src / RunModule1.cpp < prev    next >
Encoding:
C/C++ Source or Header  |  2002-06-18  |  20.9 KB  |  626 lines

  1. // RunModule1.cpp: implementation of the CRunModule class.
  2. //
  3. /*
  4. Copyright 2001 Anish Mistry. All rights reserved.
  5.  
  6. Redistribution and use in source and binary forms, with or without modification,
  7. are permitted provided that the following conditions are met:
  8.  
  9.    1. Redistributions of source code must retain the above copyright notice, 
  10.    this list of conditions and the following disclaimer.
  11.    2. Redistributions in binary form must reproduce the above copyright notice,
  12.    this list of conditions and the following disclaimer in the documentation 
  13.    and/or other materials provided with the distribution.
  14.  
  15. THIS SOFTWARE IS PROVIDED BY ANISH MISTRY ``AS IS'' AND ANY EXPRESS OR IMPLIED 
  16. WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY 
  17. AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS 
  18. OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY,
  19. OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE
  20. GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
  21. CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR
  22. TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
  23. SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  24.  
  25. The views and conclusions contained in the software and documentation are those
  26. of the authors and should not be interpreted as representing official policies,
  27. either expressed or implied, of Anish Mistry or AM Productions.
  28.  
  29. * Variation of the FreeBSD License. http://www.freebsd.org/copyright/freebsd-license.html
  30. */
  31. //////////////////////////////////////////////////////////////////////
  32.  
  33. #include "stdafx.h"
  34. #include "RunModule1.h"
  35.  
  36. //////////////////////////////////////////////////////////////////////
  37. // Construction/Destruction
  38. //////////////////////////////////////////////////////////////////////
  39.  
  40. DWORD WINAPI DoRunProgram( LPVOID pData );
  41.  
  42. DWORD WINAPI DoRunProgram( LPVOID pData )
  43. {// begin DoRunProgram
  44.     CRunModule *pThisClass = (CRunModule *)pData;
  45.     pThisClass->OnButtonOk();
  46.     return 0;
  47. }// end DoRunProgram
  48.  
  49. CRunModule::CRunModule()
  50. {
  51.  
  52. }
  53.  
  54. CRunModule::CRunModule(const char *pCommandLine)
  55. {// begin CRunModule(const char *pCommandLine)
  56.     // initilize class variables
  57.     m_bNoCaption = false;
  58.     m_bHideDescriptions = false;
  59.     m_bShellSafe = false;
  60.     m_nThreadID    = 1;
  61.     m_nErrorCode = 0;
  62.     m_pListFile[0] = NULL;
  63.     // parse command line
  64.     CCommandLine clCmdLine(pCommandLine);
  65.     bool bIgnoreErrors = false;
  66.     bool bBatchRun = false;
  67.     int nDelayExec = 0;
  68.     char pBuffer[MAX_PATH] = {NULL};
  69.     char pCommand[MAX_PATH] = {NULL};
  70.     char pObject[MAX_PATH] = {NULL};
  71.     char cSwitch = NULL;
  72.     while((cSwitch = clCmdLine.GetNextSwitch()))
  73.     {// begin parse command line
  74.             switch(cSwitch)
  75.             {// begin cSwitch switch
  76.                 case 'o':    // object/file/folder
  77.                     clCmdLine.GetNextString(pObject);
  78.                     //MessageBox(NULL,pObject,"/o switch data",MB_OK);
  79.                     break;
  80.                 case 'c':    // action to perform on object
  81.                     clCmdLine.GetNextString(pCommand);
  82.                     //MessageBox(NULL,pCommand,"/c switch data",MB_OK);
  83.                     break;
  84.                 case 'f':    // set the data file
  85.                     clCmdLine.GetNextString(m_pListFile);
  86.                     //MessageBox(NULL,m_pListFile,"/f switch data",MB_OK);
  87.                     break;
  88.                 case 'b':    // batch run data file
  89.                     bBatchRun = true;
  90.                     break;
  91.                 case 'i':    // ignore batch run errors 
  92.                     bIgnoreErrors = true;
  93.                     break;
  94.                 case 'd':    // delay executing objects (ms)
  95.                     clCmdLine.GetNextString(pBuffer);
  96.                     nDelayExec = Atoi(pBuffer);
  97.                     break;
  98.                 default:    // invalid switch
  99.                     break;
  100.             }// end cSwitch switch
  101.     }// end parse command line
  102.     if(pObject[0])
  103.     {// begin execute object
  104.         m_nErrorCode = RunProgram(pObject,pCommand);
  105.     }// end execute object
  106.     if(!m_pListFile[0])
  107.     {// begin use default file list
  108.         lstrcpy(m_pListFile,"list.ini");
  109.     }// end use default file list
  110.     if(bBatchRun)
  111.     {// begin BatchRun
  112.         m_nErrorCode = BatchRun(nDelayExec,bIgnoreErrors);
  113.     }// end BatchRun
  114. }// end CRunModule(const char *pCommandLine)
  115.  
  116.  
  117. CRunModule::~CRunModule()
  118. {
  119.  
  120. }
  121.  
  122. bool CRunModule::Init(HINSTANCE hInstance, HWND hParent, unsigned long nTemplateID, bool bDoModal)
  123. {// begin Init
  124.     if(m_nErrorCode)    // check for command line run
  125.         return false;
  126.     return CMyDialog::Init(hInstance,hParent,nTemplateID,bDoModal);
  127. }// end Init
  128.  
  129. bool CRunModule::OnInitDialog(HWND hDlg)
  130. {// begin OnInitDialog
  131.     CMyDialog::OnInitDialog(hDlg);
  132.  
  133.     // add "Task Manager" to the system menu
  134.     HMENU hSysMenu = GetSystemMenu(hDlg,false);
  135.     char pTask[] = "Task Manager";
  136.     AppendMenu(hSysMenu,MF_SEPARATOR,0,pTask);
  137.     AppendMenu(hSysMenu,MF_STRING,IDM_TASKMANAGER,pTask);
  138.     // add "Control Panel" to the system menu
  139.     char pControl[] = "Control Panel";
  140.     AppendMenu(hSysMenu,MF_STRING,IDM_CONTROLPANEL,pControl);
  141.     // add "About..." to the system menu
  142.     char pAbout[] = "About...";
  143.     AppendMenu(hSysMenu,MF_SEPARATOR,0,pTask);
  144.     AppendMenu(hSysMenu,MF_STRING,IDM_ABOUT,pAbout);
  145.  
  146.     // set the window Icon
  147.     SendMessage(m_hDlg,WM_SETICON,ICON_SMALL,(LPARAM)(HICON)LoadImage(m_hInstance,MAKEINTRESOURCE(IDI_RUNMODULE),IMAGE_ICON,16,16,LR_DEFAULTCOLOR));   
  148.     SendMessage(m_hDlg,WM_SETICON,ICON_BIG,(LPARAM)(HICON)LoadImage(m_hInstance,MAKEINTRESOURCE(IDI_RUNMODULE),IMAGE_ICON,32,32,LR_DEFAULTCOLOR));   
  149.     SIZE imageSize = {16,16};
  150.     // subclass the combobox
  151.     m_ccObject.Init(GetDlgItem(m_hDlg,IDC_COMBO_RUN));
  152.     m_cacCommand.Init(GetDlgItem(m_hDlg,IDC_COMBO_OPTION));
  153.     // initilize the buttons with the required variables
  154.     m_biOkButton.Create(IDOK,m_hDlg,m_hInstance,BI_SIZE|BI_CENTERIMAGE,imageSize);
  155.     m_biCancelButton.Create(IDCANCEL,m_hDlg,m_hInstance,BI_SIZE|BI_CENTERIMAGE,imageSize);
  156.     m_biBrowseButton.Create(IDC_BROWSE,m_hDlg,m_hInstance,BI_SIZE|BI_CENTERIMAGE,imageSize);
  157.     m_biAboutButton.Create(IDC_ABOUT,m_hDlg,m_hInstance,BI_SIZE|BI_CENTERIMAGE,imageSize);
  158.     m_cbiCloseCheck.Create(IDC_CHECK_CLOSE,m_hDlg,m_hInstance,BI_SIZE,imageSize);
  159.  
  160.     // manually set the styles of the text (do this automatically later)
  161.     m_biOkButton.SetTextStyles(DT_CENTER|DT_VCENTER|DT_NOCLIP|DT_SINGLELINE);
  162.     m_biCancelButton.SetTextStyles(DT_CENTER|DT_VCENTER|DT_NOCLIP|DT_SINGLELINE);
  163.     m_biBrowseButton.SetTextStyles(DT_CENTER|DT_VCENTER|DT_NOCLIP|DT_SINGLELINE);
  164.     m_biAboutButton.SetTextStyles(DT_CENTER|DT_VCENTER|DT_NOCLIP|DT_SINGLELINE);
  165.     m_cbiCloseCheck.SetTextStyles(DT_VCENTER|DT_NOCLIP|DT_SINGLELINE);
  166.  
  167.  
  168.     m_biOkButton.SetColor(RGB(0,200,0));
  169.     m_biCancelButton.SetColor(RGB(200,0,0));
  170.     m_biBrowseButton.SetColor(RGB(223,223,0));
  171.     m_biAboutButton.SetColor(RGB(0,174,174));
  172.  
  173.     // load the desired icon into the button
  174.     m_biOkButton.LoadCtrlImage(IDB_BITMAP_OK);
  175.     m_biCancelButton.LoadCtrlImage(IDB_BITMAP_CANCEL);
  176.     m_biBrowseButton.LoadCtrlImage(IDB_BITMAP_BROWSE);
  177.     m_biAboutButton.LoadCtrlImage(IDB_BITMAP_ABOUT);
  178.     m_cbiCloseCheck.LoadCtrlImage(IDI_RUNMODULE);
  179.  
  180.     // move all the windows to the desired positions
  181.     // NOTE: do this in the reverse tab order to preserve order
  182.     LoadWindowPlacement(m_hDlg,"wnd");
  183.     LoadWindowPlacement(GetDlgItem(m_hDlg,IDC_STATIC_MESSAGE),"status-edit");
  184.     LoadWindowPlacement(m_cbiCloseCheck.GetSafeHwnd(),"close-check");
  185.     LoadWindowPlacement(m_biAboutButton.GetSafeHwnd(),"about-button");
  186.     LoadWindowPlacement(m_biBrowseButton.GetSafeHwnd(),"browse-button");
  187.     LoadWindowPlacement(m_biCancelButton.GetSafeHwnd(),"exit-button");
  188.     LoadWindowPlacement(m_biOkButton.GetSafeHwnd(),"ok-button");
  189.     LoadWindowPlacement(GetDlgItem(m_hDlg,IDC_COMBO_OPTION),"command-combo");
  190.     LoadWindowPlacement(m_ccObject.GetSafeHwnd(),"object-combo");
  191.  
  192.     // load settings
  193.     CRunModuleData rmdSettings;
  194.     // check if it is being used as a shell
  195.     m_bShellSafe = rmdSettings.MakeShellSafe();
  196.     // check for descriptions
  197.     m_bHideDescriptions = rmdSettings.HideDescriptions();
  198.     if(m_bHideDescriptions)
  199.     {// begin hide
  200.         ShowWindow(GetDlgItem(m_hDlg,IDC_STATIC_OBJECT),SW_HIDE);
  201.         ShowWindow(GetDlgItem(m_hDlg,IDC_STATIC_COMMAND),SW_HIDE);
  202.         SetWindowText(m_biOkButton.GetSafeHwnd(),"");
  203.         SetWindowText(m_biCancelButton.GetSafeHwnd(),"");
  204.         SetWindowText(m_biBrowseButton.GetSafeHwnd(),"");
  205.         SetWindowText(m_biAboutButton.GetSafeHwnd(),"");
  206.         SetWindowText(m_cbiCloseCheck.GetSafeHwnd(),"");
  207.     }// end hide
  208.     WPARAM wState = 0;
  209.     if(rmdSettings.GetStayOpen())
  210.         wState = BST_CHECKED;
  211.     else
  212.         wState = BST_UNCHECKED;
  213.     m_cbiCloseCheck.SetCheckState(wState);
  214.     // change the dialog style
  215.     unsigned long int nStyles = GetWindowLong(m_hDlg,GWL_STYLE);
  216.     m_bNoCaption = rmdSettings.NoCaption();
  217.     if(m_bNoCaption)
  218.     {// begin remove the caption area
  219.         nStyles ^= WS_CAPTION;
  220.     }// end remove the caption area
  221.     unsigned long int nExStyles = GetWindowLong(m_hDlg,GWL_EXSTYLE);
  222.     HWND hZOrder = NULL;
  223.     if(rmdSettings.MakeToolWindow())
  224.         nExStyles |= WS_EX_TOOLWINDOW;
  225.     if(rmdSettings.MakeTopMost())
  226.         hZOrder = HWND_TOPMOST;
  227.     // apply the settings
  228.     SetWindowLong(m_hDlg,GWL_STYLE,nStyles);
  229.     SetWindowLong(m_hDlg,GWL_EXSTYLE,nExStyles);
  230.     // flush the window cache
  231.     SetWindowPos(m_hDlg,hZOrder,0,0,0,0,SWP_NOMOVE|SWP_NOSIZE|SWP_FRAMECHANGED);
  232.     // set the focus to the edit control of the combobox
  233.     SetFocus(GetDlgItem(m_ccObject.GetSafeHwnd(),1001));
  234.  
  235.     // load the previous runs in the combo box
  236.     LoadRunComboBox();
  237.  
  238.     // register the return focus hotkey with an ID of 1
  239.     RegisterHotKey(m_hDlg,1,MOD_WIN,LOBYTE(VkKeyScan('r')));
  240.     RegisterHotKey(m_hDlg,2,MOD_ALT|MOD_CONTROL,LOBYTE(VkKeyScan('r')));
  241.  
  242.     // return true so that the focus is left on the edit control
  243.     return false;
  244. }// end OnInitDialog
  245.  
  246. bool CRunModule::LoadRunComboBox()
  247. {// begin LoadRunComboBox
  248.     // load the files combo box
  249.     char pObject[1024] = {NULL};
  250.     char pCommand[1024] = {NULL};
  251.     CRunModuleListFile rmlfFile;
  252.     rmlfFile.SetFile(m_pListFile);
  253.     // empty the combo boxes
  254.     m_ccObject.ResetContent();
  255.     m_cacCommand.ResetContent();
  256.     for(int i = 1;rmlfFile.GetItem(i,pObject,pCommand);i++)
  257.     {// begin load string into combo box
  258.         if(m_ccObject.SelectString(0,pObject) == CB_ERR)
  259.             m_ccObject.AddString(pObject);
  260.         if(m_cacCommand.SelectString(0,pCommand) == CB_ERR)
  261.             m_cacCommand.AddString(pCommand);
  262.     }// end load string into combo box
  263.     return true;
  264. }// begin LoadRunComboBox
  265.  
  266. LRESULT CRunModule::DlgProc(HWND hDlg,UINT nMessage,WPARAM wParam,LPARAM lParam)
  267. {// begin DlgProc
  268.     switch (nMessage) 
  269.     {
  270.     case WM_SYSCOMMAND:
  271.         return OnSysCommand(wParam,lParam);
  272.     case WM_DESTROY:
  273.         return OnDestroy();
  274.     case WM_LBUTTONDOWN:
  275.         if(m_bNoCaption)
  276.             return OnLButtonDown(wParam,lParam);
  277.         break;
  278.     case WM_CONTEXTMENU:
  279.         if(m_bNoCaption)
  280.             return OnContextMenu(wParam,lParam);
  281.         break;
  282.     case WM_HOTKEY:
  283.         OnHotKey(wParam,lParam);
  284.         break;
  285.     }
  286.     return CSnapDlg::DlgProc(hDlg,nMessage,wParam,lParam);
  287. }// end DlgProc
  288.  
  289. bool CRunModule::OnDestroy()
  290. {// begin OnDestroy
  291.     // cleanup the icons
  292.     DestroyIcon((HICON)SendMessage(m_hDlg,WM_SETICON,ICON_SMALL,(LPARAM)NULL));
  293.     // save the main window's position
  294.     RECT rWndRect = {NULL};
  295.     GetWindowRect(m_hDlg,&rWndRect);
  296.     POINT pt = {rWndRect.left,rWndRect.top};
  297.     CRunModuleData rmdSettings;
  298.     rmdSettings.SetWndPos(pt);
  299.     if(m_cbiCloseCheck.GetCheckState() == BST_CHECKED)
  300.         rmdSettings.SetStayOpen(true);
  301.     else
  302.         rmdSettings.SetStayOpen(false);
  303.     // unregister the hotkeys
  304.     UnregisterHotKey(m_hDlg,1);
  305.     UnregisterHotKey(m_hDlg,2);
  306.     return false;
  307. }// end OnDestroy
  308.  
  309. bool CRunModule::OnCommand(WPARAM wParam, LPARAM lParam)
  310. {// begin OnCommand
  311.     int nID = LOWORD(wParam); 
  312.     int nEvent = HIWORD(wParam); 
  313.     // Parse the menu selections:
  314.     switch (nID)
  315.     {// begin parse controls
  316.         case IDOK:
  317.             unsigned long int nThreadID;
  318.             nThreadID = GetNextThreadID();
  319.             CreateThread(NULL,0,DoRunProgram,this,0,&nThreadID);
  320.            break;
  321.         case IDCANCEL:
  322.             if(m_bShellSafe)
  323.             {// begin confirm exit
  324.                 if(MessageBox(m_hDlg,"Exit RunModule?","Confirm",MB_YESNO) == IDYES)
  325.                     EndDialog(0);
  326.             }// end confirm exit
  327.             else
  328.                 EndDialog(0);
  329.            break;
  330.         case IDC_BROWSE:
  331.            OnButtonBrowse();
  332.            break;
  333.         case IDC_ABOUT:
  334.             OnAbout();
  335.             break;
  336.         case IDC_COMBO_RUN:
  337.             switch(nEvent)
  338.             {// begin wmEvent
  339.                 case CBN_SELENDOK:
  340.                     LoadItemCommand();
  341.                     break;
  342.             }// end wmEvent
  343.             break;
  344.         default:
  345.            return true;
  346.     }// end parse controls
  347.     return false;
  348. }// end OnCommand
  349.  
  350. unsigned long int CRunModule::GetNextThreadID()
  351. {// begin GetNextThreadID
  352.     return m_nThreadID++;
  353. }// end GetNextThreadID
  354.  
  355. void CRunModule::OnButtonBrowse()
  356. {// begin OnButtonBrowse
  357.     char pFilePath[1024] = {NULL};
  358.     char pOldCurrentDirectory[1024] = {NULL};
  359.     GetCurrentDirectory(1023,pOldCurrentDirectory);
  360.         OPENFILENAME ofnAttribs = {sizeof(OPENFILENAME),
  361.         NULL,
  362.         NULL,
  363.         NULL,
  364.         NULL,
  365.         NULL,
  366.         NULL,
  367.         pFilePath,
  368.         1023,
  369.         NULL,//titleBuffer,
  370.         NULL,//1023,
  371.         NULL,
  372.         NULL,
  373.         NULL,
  374.         NULL,
  375.         NULL,
  376.         NULL,
  377.         NULL,
  378.         NULL
  379.         };
  380.     GetOpenFileName(&ofnAttribs);
  381.     // select the string in to the IDC_COMBO_RUN ComboBox
  382.     SetDlgItemText(m_hDlg,IDC_COMBO_RUN,pFilePath);
  383.     // choose open from the IDC_COMBO_OPTION ComboBox
  384.     m_cacCommand.SelectString(-1,"open");
  385.     // set old directory back
  386.     SetCurrentDirectory(pOldCurrentDirectory);
  387. }// end OnButtonBrowse
  388.  
  389. bool CRunModule::LoadItemCommand()
  390. {// begin LoadItemCommand
  391.     int nItemIndex = 0;
  392.     bool bFound = false;
  393.     nItemIndex = m_ccObject.GetCurSel();
  394.     if(nItemIndex != CB_ERR)
  395.     {// begin item selected
  396.         char *pObject = NULL;
  397.         char pCommand[MAX_PATH] = {NULL};
  398.         char *pTmpObject = NULL;
  399.         char pCurrentSection[16] = {NULL};
  400.         int nObjectLen = m_ccObject.GetLBTextLen(nItemIndex);
  401.         pObject = new char [nObjectLen+1];
  402.         pTmpObject = new char [nObjectLen+1];
  403.         m_ccObject.GetLBText(nItemIndex,pObject);    
  404.         CRunModuleListFile ifFile;
  405.         ifFile.SetFile(m_pListFile);
  406.         for(int i = 1;!bFound && ifFile.ReadKey(Itoa(i,pCurrentSection),"object","",pTmpObject,nObjectLen);i++)
  407.         {// begin search file
  408.             if(lstrcmpi(pTmpObject,pObject) == 0)
  409.             {// begin object found
  410.                 bFound = true;
  411.                 ifFile.ReadKey(Itoa(i,pCurrentSection),"command","open",pCommand,MAX_PATH-1);
  412.             }// end object found
  413.         }// end search file
  414.         if(bFound)
  415.         {// begin select command
  416.             unsigned long int nErrorMessage = m_cacCommand.SelectString(0,pCommand);
  417.             if(nErrorMessage == CB_ERR)
  418.             {// begin error
  419.                 delete []pObject;
  420.                 delete []pTmpObject;
  421.                 return false;
  422.             }// end error
  423.         }// end select command
  424.         delete []pObject;
  425.         delete []pTmpObject;
  426.     }// end item selected
  427.     return bFound;
  428. }// end LoadItemCommand
  429.  
  430. void CRunModule::OnButtonOk()
  431. {// begin OnButtonOk
  432.     char *pObject = NULL;
  433.     char *pCommand = NULL;
  434.     int nObjectLen = GetWindowTextLength(m_ccObject.GetSafeHwnd());
  435.     int nCommandLen = GetWindowTextLength(m_cacCommand.GetSafeHwnd());
  436.     pObject = new char[nObjectLen+1];
  437.     pCommand = new char[nCommandLen+1];
  438.     GetWindowText(m_ccObject.GetSafeHwnd(),pObject,nObjectLen+1);
  439.     GetWindowText(m_cacCommand.GetSafeHwnd(),pCommand,nCommandLen+1);
  440.     if(lstrcmp(pCommand,"") == 0)
  441.     {
  442.         SetDlgItemText(m_hDlg,IDC_COMBO_OPTION,"open");
  443.     }
  444.     // disable run button
  445.     EnableWindow(m_biOkButton.GetSafeHwnd(),false);
  446.     int nErrorCode = RunProgram(pObject,pCommand);
  447.     if(nErrorCode > 32)
  448.     {// begin successful
  449.         DisplayMessage("Saving...");
  450.         CRunModuleListFile rmlfFile;
  451.         rmlfFile.SetFile(m_pListFile);
  452.         rmlfFile.AddItem(pObject,pCommand);
  453.         LoadRunComboBox();
  454.         DisplayMessage("OK");
  455.     }// end successful
  456.     else
  457.     {// begin error
  458.         char *pBuffer = NULL;
  459.         DisplayMessage(GetErrorMessage(pBuffer));
  460.         LocalFree(pBuffer);
  461.     }// end error
  462.  
  463.     // enable run button
  464.     EnableWindow(m_biOkButton.GetSafeHwnd(),true);
  465.     bool bDontClose = m_cbiCloseCheck.GetCheckState();
  466.     if(!bDontClose)
  467.         EndDialog(0);
  468.     delete []pObject;
  469.     delete []pCommand;
  470. }// end OnButtonOk
  471.  
  472. void CRunModule::DisplayMessage(const char *pMessage)
  473. {// begin DisplayMessage
  474.     if(m_bHideDescriptions)
  475.     {// begin display in title
  476.         char pTitle[] = "Run command . . . - ";
  477.         char *pTitleMessage = new char[lstrlen(pTitle)+lstrlen(pMessage)+1];
  478.         lstrcpy(pTitleMessage,pTitle);
  479.         lstrcat(pTitleMessage,pMessage);
  480.         SetWindowText(m_hDlg,pTitleMessage);
  481.     }// end display in title
  482.     SetDlgItemText(m_hDlg,IDC_STATIC_MESSAGE,pMessage);
  483.     UpdateWindow(GetDlgItem(m_hDlg,IDC_STATIC_MESSAGE));
  484. }// end DisplayMessage
  485.  
  486. bool CRunModule::HasChar(char *pString,char cChar)
  487. {// begin HasChar
  488.     for(;*pString != cChar;pString++);
  489.     if(*pString == cChar)
  490.         return true;
  491.     return false;
  492. }// end HasChar
  493.  
  494. int CRunModule::RunProgram(char *pObject,char *pCommand)
  495. {// begin RunProgram
  496.     return CExecuteProcess::RunProgram(pObject,pCommand);
  497. }// end RunProgram
  498.  
  499. int CRunModule::BatchRun(int nDelayExec, bool bIgnoreErr)
  500. {// begin BatchRun
  501.     // execute all of the objects in the data file
  502.     CRunModuleListFile ifFile;
  503.     ifFile.SetFile(m_pListFile);
  504.     char pObject[MAX_OBJECT_LENGTH] = {NULL};
  505.     char pCommand[MAX_PATH] = {NULL};
  506.     int nLastItem = 0;
  507.     CRunModuleListFile rmlfFile;
  508.     rmlfFile.SetFile(m_pListFile);
  509.     rmlfFile.FindItem("?","?",nLastItem);
  510.     nLastItem--;    // adjust so that is the last section
  511.     int nErrorCode = 0;
  512.     for(int i = 1;ifFile.GetItem(i,pObject,pCommand);i++)
  513.     {// begin execute command
  514.         if(((nErrorCode = RunProgram(pObject,pCommand)) < 33) && !bIgnoreErr)
  515.         {
  516.             char pErrorMessage[MAX_PATH] = {NULL};
  517.             char *pErrorCode = NULL;
  518.             wsprintf(pErrorMessage,"Error: Section [%i].\r\nFile: %hs\r\n------------\r\nobject = %hs\r\ncommand = %hs\r\n------------\r\nDetails: %hs\r\nWould you like to open this file for editing?\r\n[Enter]=No\r\n[Esc]=\"Cancel\"\r\n\"Cancel\"=Stop Executing",i,ifFile.GetFilePath(),pObject,pCommand,GetErrorMessage(pErrorCode));
  519.             // free the error message buffer
  520.             LocalFree(pErrorCode);
  521.             int nBtnVal = MessageBox(NULL,pErrorMessage,"RunModule - Error",MB_YESNOCANCEL|MB_ICONWARNING|MB_DEFBUTTON2|MB_SETFOREGROUND);
  522.             if(nBtnVal == IDYES)
  523.             {
  524.                 char pDir[MAX_OBJECT_LENGTH] = {NULL};
  525.                 lstrcpy(pDir,ifFile.GetFilePath());
  526.                 RunProgram(pDir,NULL);
  527.             }
  528.             else if(nBtnVal == IDCANCEL)
  529.             {
  530.                 return true;
  531.             }
  532.  
  533.         }
  534.         if(i >= nLastItem)
  535.         {
  536.             return true;    // no more objects to execute no need to delay
  537.         }
  538.         Sleep(nDelayExec);
  539.     }// end execute command
  540.     return i;    // return the section that the error occured in
  541. }// end BatchRun
  542.  
  543. const char *CRunModule::GetErrorMessage(char *pBuffer)
  544. {// begin GetErrorMessage
  545.     FormatMessage( 
  546.         FORMAT_MESSAGE_ALLOCATE_BUFFER | 
  547.         FORMAT_MESSAGE_FROM_SYSTEM | 
  548.         FORMAT_MESSAGE_IGNORE_INSERTS|
  549.         FORMAT_MESSAGE_MAX_WIDTH_MASK,    // remove this flag if you want line breaks
  550.         NULL,
  551.         GetLastError(),
  552.         MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT), // Default language
  553.         (LPTSTR) &pBuffer,
  554.         0,
  555.         NULL 
  556.     );
  557.     return pBuffer;
  558. }// end GetErrorMessage
  559.  
  560. bool CRunModule::OnSysCommand(WPARAM wParam, LPARAM lParam)
  561. {// begin OnSysCommand
  562.     unsigned long int nCmdType = wParam;
  563. //    POINT pCoord = {LOWORD(lParam),HIWORD(lParam)};   
  564.     switch(nCmdType)
  565.     {// begin parse command
  566.         case IDM_TASKMANAGER:
  567.             RunProgram("taskmgr",NULL);
  568.             break;
  569.         case IDM_CONTROLPANEL:
  570.             RunProgram("{21EC2020-3AEA-1069-A2DD-08002B30309D}",NULL);
  571.             break;
  572.         case IDM_ABOUT:
  573.             OnAbout();
  574.             break;
  575.     }// end command
  576.     return false;    // return false since we are processing the message
  577. }// end OnSysCommand
  578.  
  579. void CRunModule::OnAbout()
  580. {// begin OnAbout
  581.     CAbout aDlg;
  582.     aDlg.Init(m_hInstance,m_hDlg,IDD_DIALOG_ABOUT,true);
  583. }// end OnAbout
  584.  
  585. void CRunModule::LoadWindowPlacement(HWND hWnd,const char *pName)
  586. {// begin LoadWindowPlacement
  587.     // command combo
  588.     unsigned long int nFlags = SWP_NOOWNERZORDER;
  589.     CRunModuleData rmdSettings;
  590.     POINT ptPos = rmdSettings.GetPos(pName);
  591.     SIZE szSize = rmdSettings.GetSize(pName);
  592.     // ignore the size if it is less than 1
  593.     if(szSize.cx < 1 || szSize.cy < 1)
  594.         nFlags |= SWP_NOSIZE;
  595.     // ignore the position if it is less than 0
  596.     if(ptPos.x < 0 || ptPos.y < 0)
  597.         nFlags |= SWP_NOMOVE;
  598.     SetWindowPos(hWnd,NULL,ptPos.x,ptPos.y,szSize.cx,szSize.cy,nFlags);
  599. }// end LoadWindowPlacement
  600.  
  601. LRESULT CRunModule::OnLButtonDown(WPARAM wParam, LPARAM lParam)
  602. {// begin OnLButtonDown
  603.     POINT pt = {LOWORD(lParam),HIWORD(lParam)};
  604.     ClientToScreen(m_hDlg,&pt);
  605.     return PostMessage(m_hDlg,WM_NCLBUTTONDOWN,HTCAPTION,MAKELPARAM(pt.x,pt.y));
  606. }// end OnLButtonDown
  607.  
  608. LRESULT CRunModule::OnContextMenu(WPARAM wParam, LPARAM lParam)
  609. {// begin OnRButtonDown
  610.     HMENU hSysMenu = GetSystemMenu(m_hDlg,false);
  611.     int nSelItem = TrackPopupMenuEx(hSysMenu,TPM_LEFTALIGN|TPM_TOPALIGN|TPM_RETURNCMD|TPM_NONOTIFY|TPM_RIGHTBUTTON,LOWORD(lParam),HIWORD(lParam),m_hDlg,NULL);
  612.     return PostMessage(m_hDlg,WM_SYSCOMMAND,(WPARAM)nSelItem,lParam);
  613. }// end OnRButtonDown
  614.  
  615. void CRunModule::OnHotKey(WPARAM wParam,LPARAM lParam)
  616. {// begin OnHotKey
  617.     int nHotKey = (int)wParam;    // identifier of hot key
  618.     unsigned long int fuModifiers = (UINT)LOWORD(lParam);    // key-modifier flags
  619.     unsigned long int uVirtKey = (UINT)HIWORD(lParam);    // virtual-key code
  620.     if(nHotKey == 1 || nHotKey == 2)    // our hotkey ID
  621.     {// begin show tasks
  622.         // make the window active so the menu disappears after the focus is lost
  623.         SetForegroundWindow(m_hDlg);
  624.     }// end show tasks
  625.  }// end OnHotKey
  626.