home *** CD-ROM | disk | FTP | other *** search
/ QBasic & Borland Pascal & C / Delphi5.iso / C / BC_502 / BATCH.PAK / BATCH.CPP next >
Encoding:
C/C++ Source or Header  |  1997-05-06  |  7.0 KB  |  273 lines

  1. /**************************************************************************
  2.  *
  3.  *  THIS CODE AND INFORMATION IS PROVIDED "AS IS" WITHOUT WARRANTY OF ANY
  4.  *  KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE
  5.  *  IMPLIED WARRANTIES OF MERCHANTABILITY AND/OR FITNESS FOR A PARTICULAR
  6.  *  PURPOSE.
  7.  *
  8.  *  Copyright (c) 1994 - 1995    Microsoft Corporation.    All Rights Reserved.
  9.  *
  10.  **************************************************************************/
  11. // batch.cpp : Defines the class behaviors for the application.
  12. //
  13.  
  14. #define INC_OLE2
  15. #include "stdafx.h"
  16. #include "batch.h"
  17.  
  18. #include "mainfrm.h"
  19. #include "batchdoc.h"
  20. #include "batchvw.h"
  21.  
  22. #ifdef _DEBUG
  23. #undef THIS_FILE
  24. static char BASED_CODE THIS_FILE[] = __FILE__;
  25. #endif
  26.  
  27. // For Thread Local Storage in the AVISave callback
  28. DWORD gdwTlsCookie;
  29.  
  30. /////////////////////////////////////////////////////////////////////////////
  31. // CBatchApp
  32.  
  33. BEGIN_MESSAGE_MAP(CBatchApp, CWinApp)
  34.     //{{AFX_MSG_MAP(CBatchApp)
  35.     ON_COMMAND(ID_APP_ABOUT, OnAppAbout)
  36.     ON_COMMAND(ID_OPTIONS_COMPRESSALL, OnOptionsCompressAll)
  37.     ON_COMMAND(ID_OPTIONS_STOP, OnOptionsStop)
  38.     ON_UPDATE_COMMAND_UI(ID_OPTIONS_STOP, OnUpdateStop)
  39.     ON_UPDATE_COMMAND_UI(ID_OPTIONS_COMPRESSALL, OnUpdateCompressAll)
  40.     ON_UPDATE_COMMAND_UI(ID_APP_EXIT, OnUpdateAppExit)
  41.     //}}AFX_MSG_MAP
  42.     // Standard file based document commands
  43.     ON_COMMAND(ID_FILE_NEW, CWinApp::OnFileNew)
  44.     ON_COMMAND(ID_FILE_OPEN, CWinApp::OnFileOpen)
  45. END_MESSAGE_MAP()
  46.  
  47. /////////////////////////////////////////////////////////////////////////////
  48. // CBatchApp construction
  49.  
  50. CBatchApp::CBatchApp()
  51. {
  52.     // TODO: add construction code here,
  53.     // Place all significant initialization in InitInstance
  54. }
  55.  
  56. /////////////////////////////////////////////////////////////////////////////
  57. // The one and only CBatchApp object
  58.  
  59. CBatchApp theApp;
  60.  
  61. /////////////////////////////////////////////////////////////////////////////
  62. // CBatchApp initialization
  63.  
  64. BOOL CBatchApp::InitInstance()
  65. {
  66.     // Initialize TLS
  67.     gdwTlsCookie = TlsAlloc();
  68.  
  69.     // Initialize the AVIFile junk
  70.     AVIFileInit();
  71.  
  72.     Enable3dControls();
  73.  
  74.     LoadStdProfileSettings();  // Load standard INI file options (including MRU)
  75.  
  76.     // Register the application's document templates.  Document templates
  77.     //  serve as the connection between documents, frame windows and views.
  78.  
  79.     CMultiDocTemplate* pDocTemplate;
  80.     pDocTemplate = new CMultiDocTemplate(
  81.         IDR_BATCHTYPE,
  82.         RUNTIME_CLASS(CBatchDoc),
  83.         RUNTIME_CLASS(CMDIChildWnd),          // standard MDI child frame
  84.         RUNTIME_CLASS(CBatchView));
  85.     AddDocTemplate(pDocTemplate);
  86.  
  87.     // create main MDI Frame window
  88.     CMainFrame* pMainFrame = new CMainFrame;
  89.     if (!pMainFrame->LoadFrame(IDR_MAINFRAME))
  90.         return FALSE;
  91.     m_pMainWnd = pMainFrame;
  92.  
  93.     // Enable DDE Execute open
  94.     EnableShellOpen();
  95.     RegisterShellFileTypes(TRUE);
  96.  
  97.     // Parse command line for standard shell commands, DDE, file open
  98.     CCommandLineInfo cmdInfo;
  99.     ParseCommandLine(cmdInfo);
  100.  
  101.     // Dispatch commands specified on the command line
  102.     if (!ProcessShellCommand(cmdInfo))
  103.         return FALSE;
  104.  
  105.     // Enable drag/drop open
  106.     m_pMainWnd->DragAcceptFiles();
  107.  
  108.     // The main window has been initialized, so show and update it.
  109.     pMainFrame->ShowWindow(m_nCmdShow);
  110.     pMainFrame->UpdateWindow();
  111.  
  112.     return TRUE;
  113. }
  114.  
  115. int CBatchApp::ExitInstance()
  116. {
  117.     // Free our AVIFile stuff
  118.  
  119.     AVIFileExit();
  120.     return CWinApp::ExitInstance();
  121. }
  122.  
  123. /////////////////////////////////////////////////////////////////////////////
  124. // CAboutDlg dialog used for App About
  125.  
  126. class CAboutDlg : public CDialog
  127. {
  128. public:
  129.     CAboutDlg();
  130.  
  131. // Dialog Data
  132.     //{{AFX_DATA(CAboutDlg)
  133.     enum { IDD = IDD_ABOUTBOX };
  134.     //}}AFX_DATA
  135.  
  136. // Implementation
  137. protected:
  138.     virtual void DoDataExchange(CDataExchange* pDX);    // DDX/DDV support
  139.     //{{AFX_MSG(CAboutDlg)
  140.         // No message handlers
  141.     //}}AFX_MSG
  142.     DECLARE_MESSAGE_MAP()
  143. };
  144.  
  145. CAboutDlg::CAboutDlg() : CDialog(CAboutDlg::IDD)
  146. {
  147.     //{{AFX_DATA_INIT(CAboutDlg)
  148.     //}}AFX_DATA_INIT
  149. }
  150.  
  151. void CAboutDlg::DoDataExchange(CDataExchange* pDX)
  152. {
  153.     CDialog::DoDataExchange(pDX);
  154.     //{{AFX_DATA_MAP(CAboutDlg)
  155.     //}}AFX_DATA_MAP
  156. }
  157.  
  158. BEGIN_MESSAGE_MAP(CAboutDlg, CDialog)
  159.     //{{AFX_MSG_MAP(CAboutDlg)
  160.         // No message handlers
  161.     //}}AFX_MSG_MAP
  162. END_MESSAGE_MAP()
  163.  
  164. // App command to run the dialog
  165. void CBatchApp::OnAppAbout()
  166. {
  167.     CAboutDlg aboutDlg;
  168.     aboutDlg.DoModal();
  169. }
  170.  
  171. /////////////////////////////////////////////////////////////////////////////
  172. // CBatchApp commands
  173.             
  174. //
  175. // Compress everything.  Walk through all the documents in the application
  176. // and if they're not already compressing, compress that list.
  177. //
  178. void CBatchApp::OnOptionsCompressAll() 
  179. {
  180.     CWinApp* pApp = AfxGetApp();
  181.     POSITION pos = pApp->GetFirstDocTemplatePosition();
  182.     CDocTemplate* pTemplate = pApp->GetNextDocTemplate(pos);
  183.     CBatchDoc *pDoc;
  184.  
  185.     
  186.     pos = pTemplate->GetFirstDocPosition();
  187.     while (pos != NULL) {
  188.         pDoc = (CBatchDoc *)pTemplate->GetNextDoc(pos);
  189.         if (!pDoc->fCompressing)
  190.             pDoc->CompressList();
  191.     }
  192. }
  193.  
  194. //
  195. // Enable the Compress All option if there's any document window that isn't
  196. // already compressing.
  197. //
  198. void CBatchApp::OnUpdateCompressAll(CCmdUI* pCmdUI) 
  199. {
  200.     CWinApp* pApp = AfxGetApp();
  201.     POSITION pos = pApp->GetFirstDocTemplatePosition();
  202.     CDocTemplate* pTemplate = pApp->GetNextDocTemplate(pos);
  203.     CBatchDoc *pDoc;
  204.     BOOL fCanCompress = FALSE;
  205.     
  206.     pos = pTemplate->GetFirstDocPosition();
  207.     while (pos != NULL) {
  208.         pDoc = (CBatchDoc *)pTemplate->GetNextDoc(pos);
  209.         if (!pDoc->fCompressing)
  210.             fCanCompress = TRUE;
  211.     }
  212.     pCmdUI->Enable(fCanCompress);
  213. }
  214.  
  215. // 
  216. // Stop any compressions in progress
  217. //
  218. void CBatchApp::OnOptionsStop() 
  219. {
  220.     CWinApp* pApp = AfxGetApp();
  221.     POSITION pos = pApp->GetFirstDocTemplatePosition();
  222.     CDocTemplate* pTemplate = pApp->GetNextDocTemplate(pos);
  223.     CBatchDoc *pDoc;
  224.     
  225.     pos = pTemplate->GetFirstDocPosition();
  226.     while (pos != NULL) {
  227.         pDoc = (CBatchDoc *)pTemplate->GetNextDoc(pos);
  228.         if (pDoc->fCompressing)
  229.             pDoc->fStopPlease = TRUE;
  230.     }    
  231. }
  232.  
  233. //
  234. // Enable the Stop Compressing option if any document window is compressing.
  235. //
  236. void CBatchApp::OnUpdateStop(CCmdUI* pCmdUI) 
  237. {
  238.     CWinApp* pApp = AfxGetApp();
  239.     POSITION pos = pApp->GetFirstDocTemplatePosition();
  240.     CDocTemplate* pTemplate = pApp->GetNextDocTemplate(pos);
  241.     CBatchDoc *pDoc;
  242.     BOOL fCanStop = FALSE;
  243.     
  244.     pos = pTemplate->GetFirstDocPosition();
  245.     while (pos != NULL) {
  246.         pDoc = (CBatchDoc *)pTemplate->GetNextDoc(pos);
  247.         if (pDoc->fCompressing)
  248.             fCanStop = TRUE;
  249.     }
  250.     pCmdUI->Enable(fCanStop);    
  251. }
  252.  
  253. //
  254. // If anybody is compressing, don't allow FileExit
  255. //
  256. void CBatchApp::OnUpdateAppExit(CCmdUI* pCmdUI) 
  257. {
  258.     CWinApp* pApp = AfxGetApp();
  259.     POSITION pos = pApp->GetFirstDocTemplatePosition();
  260.     CDocTemplate* pTemplate = pApp->GetNextDocTemplate(pos);
  261.     CBatchDoc *pDoc;
  262.     
  263.     pos = pTemplate->GetFirstDocPosition();
  264.     while (pos != NULL) {
  265.         pDoc = (CBatchDoc *)pTemplate->GetNextDoc(pos);
  266.         if (pDoc->fCompressing) {
  267.             pCmdUI->Enable(FALSE);
  268.             return;
  269.         }
  270.     }    
  271.     pCmdUI->Enable(TRUE);
  272. }
  273.