home *** CD-ROM | disk | FTP | other *** search
/ Using Visual C++ 4 (Special Edition) / Using_Visual_C_4_Special_Edition_QUE_1996.iso / ch09 / autoclik.cpp < prev    next >
Encoding:
C/C++ Source or Header  |  1994-08-13  |  5.3 KB  |  193 lines

  1. // autoclik.cpp : Defines the class behaviors for the application.
  2. //
  3.  
  4. #include "stdafx.h"
  5. #include "autoclik.h"
  6.  
  7. #include "mainfrm.h"
  8. #include "autocdoc.h"
  9. #include "autocvw.h"
  10.  
  11. #ifdef _DEBUG
  12. #undef THIS_FILE
  13. static char BASED_CODE THIS_FILE[] = __FILE__;
  14. #endif
  15.  
  16. /////////////////////////////////////////////////////////////////////////////
  17. // CClikApp
  18.  
  19. BEGIN_MESSAGE_MAP(CClikApp, CWinApp)
  20.     //{{AFX_MSG_MAP(CClikApp)
  21.     ON_COMMAND(ID_APP_ABOUT, OnAppAbout)
  22.         // NOTE - the ClassWizard will add and remove mapping macros here.
  23.         //    DO NOT EDIT what you see in these blocks of generated code!
  24.     //}}AFX_MSG_MAP
  25.     // Standard file based document commands
  26.     ON_COMMAND(ID_FILE_NEW, CWinApp::OnFileNew)
  27.     ON_COMMAND(ID_FILE_OPEN, CWinApp::OnFileOpen)
  28.     // Standard print setup command
  29.     ON_COMMAND(ID_FILE_PRINT_SETUP, CWinApp::OnFilePrintSetup)
  30. END_MESSAGE_MAP()
  31.  
  32. /////////////////////////////////////////////////////////////////////////////
  33. // CClikApp construction
  34.  
  35. CClikApp::CClikApp()
  36. {
  37.     // TODO: add construction code here,
  38.     // Place all significant initialization in InitInstance
  39. }
  40.  
  41. /////////////////////////////////////////////////////////////////////////////
  42. // The one and only CClikApp object
  43.  
  44. CClikApp theApp;
  45.  
  46. // This identifier was generated to be statistically unique for your app.
  47. // You may change it if you prefer to choose a specific identifier.
  48. static const CLSID BASED_CODE clsid =
  49. { 0x0002180b, 0x0000, 0x0000, { 0xC0, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x46 } };
  50.  
  51. /////////////////////////////////////////////////////////////////////////////
  52. // CClikApp initialization
  53.  
  54. BOOL CClikApp::InitInstance()
  55. {
  56.     // Initialize OLE libraries
  57.     if (!AfxOleInit())
  58.     {
  59.         AfxMessageBox(IDP_OLE_INIT_FAILED);
  60.         return FALSE;
  61.     }
  62.  
  63.     // Standard initialization
  64.     // If you are not using these features and wish to reduce the size
  65.     //  of your final executable, you should remove from the following
  66.     //  the specific initialization routines you do not need.
  67.  
  68.     Enable3dControls();
  69.  
  70.     LoadStdProfileSettings();  // Load standard INI file options (including MRU)
  71.  
  72.     // Register the application's document templates.  Document templates
  73.     //  serve as the connection between documents, frame windows and views.
  74.  
  75.     CMultiDocTemplate* pDocTemplate;
  76.     pDocTemplate = new CMultiDocTemplate(
  77.         IDR_ACLIKTYPE,
  78.         RUNTIME_CLASS(CClikDoc),
  79.         RUNTIME_CLASS(CMDIChildWnd),        // standard MDI child frame
  80.         RUNTIME_CLASS(CClikView));
  81.     AddDocTemplate(pDocTemplate);
  82.  
  83.     // Connect the COleTemplateServer to the document template.
  84.     //  The COleTemplateServer creates new documents on behalf
  85.     //  of requesting OLE containers by using information
  86.     //  specified in the document template.
  87.     m_server.ConnectTemplate(clsid, pDocTemplate, FALSE);
  88.  
  89.     // Register all OLE server factories as running.  This enables the
  90.     //  OLE libraries to create objects from other applications.
  91.     COleTemplateServer::RegisterAll();
  92.         // Note: MDI applications register all server objects without regard
  93.         //  to the /Embedding or /Automation on the command line.
  94.  
  95.     // create main MDI Frame window
  96.     CMainFrame* pMainFrame = new CMainFrame;
  97.     if (!pMainFrame->LoadFrame(IDR_MAINFRAME))
  98.         return FALSE;
  99.     m_pMainWnd = pMainFrame;
  100.  
  101.     // Enable DDE Execute open
  102.     EnableShellOpen();
  103.     RegisterShellFileTypes();
  104.  
  105.     // Parse the command line to see if launched as OLE server
  106.     if (RunEmbedded() || RunAutomated())
  107.     {
  108.         // Application was run with /Embedding or /Automation.  Don't show the
  109.         //  main window in this case.
  110.         return TRUE;
  111.     }
  112.  
  113.     // When a server application is launched stand-alone, it is a good idea
  114.     //  to update the system registry in case it has been damaged.
  115.     m_server.UpdateRegistry(OAT_DISPATCH_OBJECT);
  116.     COleObjectFactory::UpdateRegistryAll();
  117.  
  118.     // simple command line parsing
  119.     if (m_lpCmdLine[0] == '\0')
  120.     {
  121.         // create a new (empty) document
  122. #ifndef _MAC
  123.         // On the Macintosh, this call isn't required, since the Finder is
  124.         //  already sending the app a message to open a new document.
  125.         OnFileNew();
  126. #endif
  127.     }
  128.     else
  129.     {
  130.         // open an existing document
  131.         OpenDocumentFile(m_lpCmdLine);
  132.     }
  133.     
  134.     // Enable drag/drop open
  135.     m_pMainWnd->DragAcceptFiles();
  136.     // The main window has been initialized, so show and update it.
  137.     pMainFrame->ShowWindow(m_nCmdShow);
  138.     pMainFrame->UpdateWindow();
  139.  
  140.     return TRUE;
  141. }
  142.  
  143. /////////////////////////////////////////////////////////////////////////////
  144. // CAboutDlg dialog used for App About
  145.  
  146. class CAboutDlg : public CDialog
  147. {
  148. public:
  149.     CAboutDlg();
  150.  
  151. // Dialog Data
  152.     //{{AFX_DATA(CAboutDlg)
  153.     enum { IDD = IDD_ABOUTBOX };
  154.     //}}AFX_DATA
  155.  
  156. // Implementation
  157. protected:
  158.     virtual void DoDataExchange(CDataExchange* pDX);    // DDX/DDV support
  159.     //{{AFX_MSG(CAboutDlg)
  160.         // No message handlers
  161.     //}}AFX_MSG
  162.     DECLARE_MESSAGE_MAP()
  163. };
  164.  
  165. CAboutDlg::CAboutDlg() : CDialog(CAboutDlg::IDD)
  166. {
  167.     //{{AFX_DATA_INIT(CAboutDlg)
  168.     //}}AFX_DATA_INIT
  169. }
  170.  
  171. void CAboutDlg::DoDataExchange(CDataExchange* pDX)
  172. {
  173.     CDialog::DoDataExchange(pDX);
  174.     //{{AFX_DATA_MAP(CAboutDlg)
  175.     //}}AFX_DATA_MAP
  176. }
  177.  
  178. BEGIN_MESSAGE_MAP(CAboutDlg, CDialog)
  179.     //{{AFX_MSG_MAP(CAboutDlg)
  180.         // No message handlers
  181.     //}}AFX_MSG_MAP
  182. END_MESSAGE_MAP()
  183.  
  184. // App command to run the dialog
  185. void CClikApp::OnAppAbout()
  186. {
  187.     CAboutDlg aboutDlg;
  188.     aboutDlg.DoModal();
  189. }
  190.  
  191. /////////////////////////////////////////////////////////////////////////////
  192. // CClikApp commands
  193.