home *** CD-ROM | disk | FTP | other *** search
/ Tricks of the Windows Gam…ming Gurus (2nd Edition) / Disc2.iso / msdn_vcb / samples / vc98 / appwiz / logowiz / template / dialog.cpp < prev    next >
C/C++ Source or Header  |  1998-03-05  |  7KB  |  289 lines

  1. // $$dlg_ifile$$.cpp : implementation file
  2. //
  3. // This is a part of the Microsoft Foundation Classes C++ library.
  4. // Copyright (C) 1995-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 "$$root$$.h"
  15. #include "$$dlg_hfile$$.h"
  16. $$IF(AUTOMATION)
  17. #include "$$dlgautoproxy_hfile$$.h"
  18. $$ENDIF //AUTOMATION
  19. $$IF(PRESS_ME_DIALOG)
  20. #include "pressdlg.h"
  21. $$ENDIF //PRESS_ME_DIALOG
  22.  
  23. #ifdef _DEBUG
  24. #define new DEBUG_NEW
  25. #undef THIS_FILE
  26. static char THIS_FILE[] = __FILE__;
  27. #endif
  28.  
  29. $$IF(ABOUT)
  30. /////////////////////////////////////////////////////////////////////////////
  31. // CAboutDlg dialog used for App About
  32.  
  33. class CAboutDlg : public CDialog
  34. {
  35. public:
  36.     CAboutDlg();
  37.  
  38. // Dialog Data
  39.     //{{AFX_DATA(CAboutDlg)
  40.     enum { IDD = IDD_ABOUTBOX };
  41.     //}}AFX_DATA
  42.  
  43.     // ClassWizard generated virtual function overrides
  44.     //{{AFX_VIRTUAL(CAboutDlg)
  45. protected:
  46.     virtual void DoDataExchange(CDataExchange* pDX);    // DDX/DDV support
  47.     //}}AFX_VIRTUAL
  48.  
  49. // Implementation
  50. protected:
  51.     //{{AFX_MSG(CAboutDlg)
  52.     //}}AFX_MSG
  53.     DECLARE_MESSAGE_MAP()
  54. };
  55.  
  56. CAboutDlg::CAboutDlg() : CDialog(CAboutDlg::IDD)
  57. {
  58.     //{{AFX_DATA_INIT(CAboutDlg)
  59.     //}}AFX_DATA_INIT
  60. }
  61.  
  62. void CAboutDlg::DoDataExchange(CDataExchange* pDX)
  63. {
  64.     CDialog::DoDataExchange(pDX);
  65.     //{{AFX_DATA_MAP(CAboutDlg)
  66.     //}}AFX_DATA_MAP
  67. }
  68.  
  69. BEGIN_MESSAGE_MAP(CAboutDlg, CDialog)
  70.     //{{AFX_MSG_MAP(CAboutDlg)
  71.         // No message handlers
  72.     //}}AFX_MSG_MAP
  73. END_MESSAGE_MAP()
  74.  
  75. $$ENDIF //ABOUT
  76. /////////////////////////////////////////////////////////////////////////////
  77. // $$DLG_CLASS$$ dialog
  78. $$IF(AUTOMATION)
  79.  
  80. IMPLEMENT_DYNAMIC($$DLG_CLASS$$, $$DLG_BASE_CLASS$$);
  81. $$ENDIF //AUTOMATION
  82.  
  83. $$DLG_CLASS$$::$$DLG_CLASS$$(CWnd* pParent /*=NULL*/)
  84.     : $$DLG_BASE_CLASS$$($$DLG_CLASS$$::IDD, pParent)
  85. {
  86.     //{{AFX_DATA_INIT($$DLG_CLASS$$)
  87.         // NOTE: the ClassWizard will add member initialization here
  88.     //}}AFX_DATA_INIT
  89. $$IF(VERBOSE)
  90.     // Note that LoadIcon does not require a subsequent DestroyIcon in Win32
  91. $$ENDIF
  92.     m_hIcon = AfxGetApp()->LoadIcon(IDR_MAINFRAME);
  93. $$IF(AUTOMATION)
  94.     m_pAutoProxy = NULL;
  95. $$ENDIF //AUTOMATION
  96. }
  97. $$IF(AUTOMATION)
  98.  
  99. $$DLG_CLASS$$::~$$DLG_CLASS$$()
  100. {
  101. $$IF(VERBOSE)
  102.     // If there is an automation proxy for this dialog, set
  103.     //  its back pointer to this dialog to NULL, so it knows
  104.     //  the dialog has been deleted.
  105. $$ENDIF //VERBOSE
  106.     if (m_pAutoProxy != NULL)
  107.         m_pAutoProxy->m_pDialog = NULL;
  108. }
  109. $$ENDIF //AUTOMATION
  110.  
  111. void $$DLG_CLASS$$::DoDataExchange(CDataExchange* pDX)
  112. {
  113.     $$DLG_BASE_CLASS$$::DoDataExchange(pDX);
  114.     //{{AFX_DATA_MAP($$DLG_CLASS$$)
  115.         // NOTE: the ClassWizard will add DDX and DDV calls here
  116.     //}}AFX_DATA_MAP
  117. }
  118.  
  119. BEGIN_MESSAGE_MAP($$DLG_CLASS$$, $$DLG_BASE_CLASS$$)
  120.     //{{AFX_MSG_MAP($$DLG_CLASS$$)
  121. $$IF(ABOUT)
  122.     ON_WM_SYSCOMMAND()
  123. $$ENDIF
  124. $$IF(HELP)
  125.     ON_WM_DESTROY()
  126. $$ENDIF
  127. $$IF(AUTOMATION)
  128.     ON_WM_CLOSE()
  129. $$ENDIF
  130. $$IF(PRESS_ME_DIALOG)
  131.     ON_COMMAND(IDC_PRESS_ME, OnPressMe)
  132. $$ENDIF
  133.     ON_WM_PAINT()
  134.     ON_WM_QUERYDRAGICON()
  135.     //}}AFX_MSG_MAP
  136. END_MESSAGE_MAP()
  137.  
  138. /////////////////////////////////////////////////////////////////////////////
  139. // $$DLG_CLASS$$ message handlers
  140.  
  141. BOOL $$DLG_CLASS$$::OnInitDialog()
  142. {
  143.     $$DLG_BASE_CLASS$$::OnInitDialog();
  144. $$IF(ABOUT)
  145.  
  146.     // Add "About..." menu item to system menu.
  147.  
  148.     // IDM_ABOUTBOX must be in the system command range.
  149.     ASSERT((IDM_ABOUTBOX & 0xFFF0) == IDM_ABOUTBOX);
  150.     ASSERT(IDM_ABOUTBOX < 0xF000);
  151.  
  152.     CMenu* pSysMenu = GetSystemMenu(FALSE);
  153.     if (pSysMenu != NULL)
  154.     {
  155.         CString strAboutMenu;
  156.         strAboutMenu.LoadString(IDS_ABOUTBOX);
  157.         if (!strAboutMenu.IsEmpty())
  158.         {
  159.             pSysMenu->AppendMenu(MF_SEPARATOR);
  160.             pSysMenu->AppendMenu(MF_STRING, IDM_ABOUTBOX, strAboutMenu);
  161.         }
  162.     }
  163. $$ENDIF //ABOUT
  164.  
  165. $$IF(VERBOSE)
  166.     // Set the icon for this dialog.  The framework does this automatically
  167.     //  when the application's main window is not a dialog
  168. $$ENDIF //VERBOSE
  169.     SetIcon(m_hIcon, TRUE);         // Set big icon
  170.     SetIcon(m_hIcon, FALSE);        // Set small icon
  171.  
  172.     // TODO: Add extra initialization here
  173.  
  174.     return TRUE;  // return TRUE  unless you set the focus to a control
  175. }
  176. $$IF(ABOUT)
  177.  
  178. void $$DLG_CLASS$$::OnSysCommand(UINT nID, LPARAM lParam)
  179. {
  180.     if ((nID & 0xFFF0) == IDM_ABOUTBOX)
  181.     {
  182.         CAboutDlg dlgAbout;
  183.         dlgAbout.DoModal();
  184.     }
  185.     else
  186.     {
  187.         $$DLG_BASE_CLASS$$::OnSysCommand(nID, lParam);
  188.     }
  189. }
  190. $$ENDIF //ABOUT
  191. $$IF(HELP)
  192.  
  193. void $$DLG_CLASS$$::OnDestroy()
  194. {
  195.     WinHelp(0L, HELP_QUIT);
  196.     $$DLG_BASE_CLASS$$::OnDestroy();
  197. }
  198. $$ENDIF //HELP
  199. $$IF(PRESS_ME_DIALOG)
  200.  
  201. void $$DLG_CLASS$$::OnPressMe()
  202. {
  203.     CPressMeDlg dlg;
  204.     dlg.DoModal();
  205. }
  206. $$ENDIF //PRESS_ME_DIALOG
  207.  
  208. // If you add a minimize button to your dialog, you will need the code below
  209. //  to draw the icon.  For MFC applications using the document/view model,
  210. //  this is automatically done for you by the framework.
  211.  
  212. void $$DLG_CLASS$$::OnPaint()
  213. {
  214.     if (IsIconic())
  215.     {
  216.         CPaintDC dc(this); // device context for painting
  217.  
  218.         SendMessage(WM_ICONERASEBKGND, (WPARAM) dc.GetSafeHdc(), 0);
  219.  
  220.         // Center icon in client rectangle
  221.         int cxIcon = GetSystemMetrics(SM_CXICON);
  222.         int cyIcon = GetSystemMetrics(SM_CYICON);
  223.         CRect rect;
  224.         GetClientRect(&rect);
  225.         int x = (rect.Width() - cxIcon + 1) / 2;
  226.         int y = (rect.Height() - cyIcon + 1) / 2;
  227.  
  228.         // Draw the icon
  229.         dc.DrawIcon(x, y, m_hIcon);
  230.     }
  231.     else
  232.     {
  233.         $$DLG_BASE_CLASS$$::OnPaint();
  234.     }
  235. }
  236.  
  237. $$IF(VERBOSE)
  238. // The system calls this to obtain the cursor to display while the user drags
  239. //  the minimized window.
  240. $$ENDIF
  241. HCURSOR $$DLG_CLASS$$::OnQueryDragIcon()
  242. {
  243.     return (HCURSOR) m_hIcon;
  244. }
  245. $$IF(AUTOMATION)
  246. $$IF(VERBOSE)
  247.  
  248. // Automation servers should not exit when a user closes the UI
  249. //  if a controller still holds on to one of its objects.  These
  250. //  message handlers make sure that if the proxy is still in use,
  251. //  then the UI is hidden but the dialog remains around if it
  252. //  is dismissed.
  253. $$ENDIF //VERBOSE
  254.  
  255. void $$DLG_CLASS$$::OnClose()
  256. {
  257.     if (CanExit())
  258.         $$DLG_BASE_CLASS$$::OnClose();
  259. }
  260.  
  261. void $$DLG_CLASS$$::OnOK()
  262. {
  263.     if (CanExit())
  264.         $$DLG_BASE_CLASS$$::OnOK();
  265. }
  266.  
  267. void $$DLG_CLASS$$::OnCancel()
  268. {
  269.     if (CanExit())
  270.         $$DLG_BASE_CLASS$$::OnCancel();
  271. }
  272.  
  273. BOOL $$DLG_CLASS$$::CanExit()
  274. {
  275. $$IF(VERBOSE)
  276.     // If the proxy object is still around, then the automation
  277.     //  controller is still holding on to this application.  Leave
  278.     //  the dialog around, but hide its UI.
  279. $$ENDIF //VERBOSE
  280.     if (m_pAutoProxy != NULL)
  281.     {
  282.         ShowWindow(SW_HIDE);
  283.         return FALSE;
  284.     }
  285.  
  286.     return TRUE;
  287. }
  288. $$ENDIF //AUTOMATION
  289.