home *** CD-ROM | disk | FTP | other *** search
/ Tricks of the Windows Gam…ming Gurus (2nd Edition) / Disc2.iso / msdn_vcb / samples / vc98 / mfc / ole / superpad / superpad.cpp < prev    next >
C/C++ Source or Header  |  1998-03-26  |  5KB  |  215 lines

  1. // superpad.cpp : Defines the class behaviors for the application.
  2. //
  3. // This is a part of the Microsoft Foundation Classes C++ library.
  4. // Copyright (C) 1992-1998 Microsoft Corporation
  5. // All rights reserved.
  6. //
  7. // This source code is only intended as a supplement to the
  8. // Microsoft Foundation Classes Reference and related
  9. // electronic documentation provided with the library.
  10. // See these sources for detailed information regarding the
  11. // Microsoft Foundation Classes product.
  12.  
  13. #include "stdafx.h"
  14. #include "superpad.h"
  15. #include "mainfrm.h"
  16. #include "padview.h"
  17. #include "paddoc.h"
  18. #include "padframe.h"
  19. #include "ipframe.h"
  20.  
  21. #include <locale.h>
  22.  
  23. BEGIN_MESSAGE_MAP(CTheApp, CWinApp)
  24.     //{{AFX_MSG_MAP(CTheApp)
  25.     ON_COMMAND(ID_APP_ABOUT, OnAppAbout)
  26.     ON_COMMAND(ID_PAGE_SETUP, OnPageSetup)
  27.     //}}AFX_MSG_MAP
  28.     // Standard file based document commands
  29.     ON_COMMAND(ID_FILE_NEW, CWinApp::OnFileNew)
  30.     ON_COMMAND(ID_FILE_OPEN, CWinApp::OnFileOpen)
  31.     ON_COMMAND(ID_FILE_PRINT_SETUP, CWinApp::OnFilePrintSetup)
  32. END_MESSAGE_MAP()
  33.  
  34. /////////////////////////////////////////////////////////////////////////////
  35. // Superpad global data
  36.  
  37. CTheApp NEAR theApp;
  38.  
  39. // this is the GUID for OCLIENT documents
  40. static const GUID BASED_CODE clsid =
  41.     { 0x00021844, 0, 0, { 0xC0, 0, 0, 0, 0, 0, 0, 0x46 } };
  42.  
  43. /////////////////////////////////////////////////////////////////////////////
  44. // CTheApp initialization
  45.  
  46. CTheApp::CTheApp()
  47. {
  48.     // initialize locale to system default
  49.     _tsetlocale(LC_ALL, _T(""));
  50. }
  51.  
  52. BOOL CTheApp::InitInstance()
  53. {
  54.     // initialized OLE 2.0 libraries
  55.     if (!AfxOleInit())
  56.     {
  57.         AfxMessageBox(IDP_OLE_INIT_FAILED);
  58.         return FALSE;
  59.     }
  60.  
  61.     // initialization that must be done before splash dialog is shown
  62.     Enable3dControls();
  63.     CPadFrame::Initialize();
  64.  
  65.     // add doc template
  66.     CDocTemplate* pDocTemplate;
  67.     pDocTemplate = new CMultiDocTemplate(IDR_TEXTTYPE,
  68.         RUNTIME_CLASS(CPadDoc),
  69.         RUNTIME_CLASS(CPadFrame),
  70.         RUNTIME_CLASS(CPadView));
  71.     pDocTemplate->SetServerInfo(
  72.         IDR_TEXTTYPE_EMBEDDED, IDR_TEXTTYPE_INPLACE,
  73.         RUNTIME_CLASS(CInPlaceFrame));
  74.     AddDocTemplate(pDocTemplate);
  75.  
  76.     // connect the server to the document template
  77.     m_server.ConnectTemplate(clsid, pDocTemplate, FALSE);
  78.  
  79.     // create main window
  80.     CMainFrame* pMainFrame = new CMainFrame;
  81.     if (!pMainFrame->LoadFrame(IDR_MAINFRAME))
  82.         return FALSE;
  83.     m_pMainWnd = pMainFrame;
  84.     int nCmdShow = m_nCmdShow;
  85.  
  86.     // Parse command line for standard shell commands, DDE, file open
  87.     CCommandLineInfo cmdInfo;
  88.     ParseCommandLine(cmdInfo);
  89.  
  90.     // setup main window
  91.     nCmdShow = !cmdInfo.m_bRunEmbedded ? m_nCmdShow : SW_HIDE;
  92.     m_nCmdShow = SW_HIDE;
  93.     ((CMainFrame*)m_pMainWnd)->InitialShowWindow(nCmdShow);
  94.  
  95.     if (!cmdInfo.m_bRunEmbedded)
  96.     {
  97.         m_pMainWnd->UpdateWindow();
  98.  
  99.         if (!m_pMainWnd->IsIconic() && cmdInfo.m_bShowSplash &&
  100.             m_splash.Create(m_pMainWnd))
  101.         {
  102.             m_splash.ShowWindow(SW_SHOW);
  103.             m_splash.UpdateWindow();
  104.             m_splash.SetTimer(1, 500, NULL);
  105.         }
  106.         m_dwSplashTime = ::GetCurrentTime();
  107.  
  108.         // update the registry now that the splash dialog is visible
  109.         m_server.UpdateRegistry();
  110.         RegisterShellFileTypes(TRUE);
  111.     }
  112.  
  113.     // do other initialization after (possibly) creating the splash window
  114.     EnableShellOpen();
  115.     m_pMainWnd->DragAcceptFiles();
  116.  
  117.     LoadStdProfileSettings();
  118.     CPadView::Initialize();
  119.     dlgPageSetup.Initialize();
  120.  
  121.     // register any class objects we may have (for automation & OLE)
  122.     COleTemplateServer::RegisterAll();
  123.  
  124.     // open default file if command line doesn't have /Embedding
  125.     if (!cmdInfo.m_bRunEmbedded)
  126.     {
  127.         // Dispatch commands specified on the command line
  128.         if (!ProcessShellCommand(cmdInfo))
  129.             return FALSE;
  130.  
  131.         m_nCmdShow = nCmdShow;
  132.         m_pMainWnd->UpdateWindow();
  133.     }
  134.  
  135.     return TRUE;
  136. }
  137.  
  138. BOOL CTheApp::OnIdle(LONG lCount)
  139. {
  140.     // call base class idle first
  141.     BOOL bResult = CWinApp::OnIdle(lCount);
  142.  
  143.     // then do our work
  144.     if (m_splash.m_hWnd != NULL)
  145.     {
  146.         if (::GetCurrentTime() - m_dwSplashTime > 2500)
  147.         {
  148.             // timeout expired, destroy the splash window
  149.             m_splash.DestroyWindow();
  150.             m_pMainWnd->UpdateWindow();
  151.  
  152.             // NOTE: don't set bResult to FALSE,
  153.             //  CWinApp::OnIdle may have returned TRUE
  154.         }
  155.         else
  156.         {
  157.             // check again later...
  158.             bResult = TRUE;
  159.         }
  160.     }
  161.  
  162.     return bResult;
  163. }
  164.  
  165. BOOL CTheApp::PreTranslateMessage(MSG* pMsg)
  166. {
  167.     BOOL bResult = CWinApp::PreTranslateMessage(pMsg);
  168.  
  169.     if (m_splash.m_hWnd != NULL &&
  170.         (pMsg->message == WM_KEYDOWN ||
  171.          pMsg->message == WM_SYSKEYDOWN ||
  172.          pMsg->message == WM_LBUTTONDOWN ||
  173.          pMsg->message == WM_RBUTTONDOWN ||
  174.          pMsg->message == WM_MBUTTONDOWN ||
  175.          pMsg->message == WM_NCLBUTTONDOWN ||
  176.          pMsg->message == WM_NCRBUTTONDOWN ||
  177.          pMsg->message == WM_NCMBUTTONDOWN))
  178.     {
  179.         m_splash.DestroyWindow();
  180.         m_pMainWnd->UpdateWindow();
  181.     }
  182.  
  183.     return bResult;
  184. }
  185.  
  186. int CTheApp::ExitInstance()
  187. {
  188.     dlgPageSetup.Terminate();
  189.     CPadView::Terminate();
  190.     CPadFrame::Terminate();
  191.  
  192.     return CWinApp::ExitInstance();
  193. }
  194.  
  195. CTheApp::~CTheApp()
  196. {
  197. }
  198.  
  199. /////////////////////////////////////////////////////////////////////////////
  200. // CTheApp message handlers
  201.  
  202. void CTheApp::OnAppAbout()
  203. {
  204.     CAboutBox about;
  205.     about.DoModal();
  206. }
  207.  
  208. CPageSetupDlg NEAR dlgPageSetup;
  209. void CTheApp::OnPageSetup()
  210. {
  211.     dlgPageSetup.DoModal();
  212. }
  213.  
  214. /////////////////////////////////////////////////////////////////////////////
  215.