home *** CD-ROM | disk | FTP | other *** search
/ Tricks of the Windows Gam…ming Gurus (2nd Edition) / Disc2.iso / msdn_vcb / samples / vc98 / mfc / advanced / mtgdi / mtgdi.cpp < prev    next >
Encoding:
C/C++ Source or Header  |  1998-03-27  |  3.0 KB  |  125 lines

  1. // mtgdi.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 "mtgdi.h"
  15.  
  16. #include "mainfrm.h"
  17. #include "mtgdidoc.h"
  18. #include "mtgdivw.h"
  19. #include "threads.h"
  20.  
  21. #ifdef _DEBUG
  22. #undef THIS_FILE
  23. static char BASED_CODE THIS_FILE[] = __FILE__;
  24. #endif
  25.  
  26. BEGIN_MESSAGE_MAP(CThreadApp, CWinApp)
  27.     //{{AFX_MSG_MAP(CThreadApp)
  28.     ON_COMMAND(ID_APP_ABOUT, OnAppAbout)
  29.         // NOTE - the ClassWizard will add and remove mapping macros here.
  30.         //    DO NOT EDIT what you see in these blocks of generated code!
  31.     //}}AFX_MSG_MAP
  32.     // Standard file based document commands
  33.     ON_COMMAND(ID_FILE_NEW, CWinApp::OnFileNew)
  34.     ON_COMMAND(ID_FILE_OPEN, CWinApp::OnFileOpen)
  35. END_MESSAGE_MAP()
  36.  
  37. CThreadApp::CThreadApp()
  38. {
  39. }
  40.  
  41. CThreadApp theApp;
  42.  
  43. BOOL CThreadApp::InitInstance()
  44. {
  45.     Enable3dControls();
  46.  
  47.     // Initialize static members of CGDIThread
  48.     InitializeCriticalSection(&CGDIThread::m_csGDILock);
  49.  
  50.     // Register the application's document templates.  Document templates
  51.     //  serve as the connection between documents, frame windows and views.
  52.     CSingleDocTemplate* pDocTemplate;
  53.     pDocTemplate = new CSingleDocTemplate(
  54.         IDR_MAINFRAME,
  55.         RUNTIME_CLASS(CThreadDoc),
  56.         RUNTIME_CLASS(CMainFrame),       // main SDI frame window
  57.         RUNTIME_CLASS(CThreadView));
  58.     AddDocTemplate(pDocTemplate);
  59.  
  60.     // create a new (empty) document
  61.     OnFileNew();
  62.  
  63.     if (m_lpCmdLine[0] != '\0')
  64.     {
  65.         // TODO: add command line processing here
  66.     }
  67.  
  68.     return TRUE;
  69. }
  70.  
  71. int CThreadApp::ExitInstance()
  72. {
  73.     DeleteCriticalSection(&CGDIThread::m_csGDILock);
  74.     CloseHandle(CGDIThread::m_hAnotherDead);
  75.  
  76.     return CWinApp::ExitInstance();
  77. }
  78.  
  79. /////////////////////////////////////////////////////////////////////////////
  80. // CAboutDlg dialog used for App About
  81.  
  82. class CAboutDlg : public CDialog
  83. {
  84. public:
  85.     CAboutDlg();
  86.  
  87. // Dialog Data
  88.     //{{AFX_DATA(CAboutDlg)
  89.     enum { IDD = IDD_ABOUTBOX };
  90.     //}}AFX_DATA
  91.  
  92. // Implementation
  93. protected:
  94.     virtual void DoDataExchange(CDataExchange* pDX);    // DDX/DDV support
  95.     //{{AFX_MSG(CAboutDlg)
  96.         // No message handlers
  97.     //}}AFX_MSG
  98.     DECLARE_MESSAGE_MAP()
  99. };
  100.  
  101. CAboutDlg::CAboutDlg() : CDialog(CAboutDlg::IDD)
  102. {
  103.     //{{AFX_DATA_INIT(CAboutDlg)
  104.     //}}AFX_DATA_INIT
  105. }
  106.  
  107. void CAboutDlg::DoDataExchange(CDataExchange* pDX)
  108. {
  109.     CDialog::DoDataExchange(pDX);
  110.     //{{AFX_DATA_MAP(CAboutDlg)
  111.     //}}AFX_DATA_MAP
  112. }
  113.  
  114. BEGIN_MESSAGE_MAP(CAboutDlg, CDialog)
  115.     //{{AFX_MSG_MAP(CAboutDlg)
  116.         // No message handlers
  117.     //}}AFX_MSG_MAP
  118. END_MESSAGE_MAP()
  119.  
  120. // App command to run the dialog
  121. void CThreadApp::OnAppAbout()
  122. {
  123.     CAboutDlg().DoModal();
  124. }
  125.