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

  1. // dialog.cpp : implementation file
  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 "stdreg.h"
  15. #include "typeinfo.h"
  16. #include "dialog.h"
  17.  
  18. #ifdef _DEBUG
  19. #undef THIS_FILE
  20. static char BASED_CODE THIS_FILE[] = __FILE__;
  21. #endif
  22.  
  23. /////////////////////////////////////////////////////////////////////////////
  24. // CAboutDlg dialog used for App About
  25.  
  26. class CAboutDlg : public CDialog
  27. {
  28. public:
  29.     CAboutDlg();
  30.  
  31. // Dialog Data
  32.     //{{AFX_DATA(CAboutDlg)
  33.     enum { IDD = IDD_ABOUTBOX };
  34.     //}}AFX_DATA
  35.  
  36. // Implementation
  37. protected:
  38.     virtual void DoDataExchange(CDataExchange* pDX);    // DDX/DDV support
  39.     //{{AFX_MSG(CAboutDlg)
  40.     virtual BOOL OnInitDialog();
  41.     //}}AFX_MSG
  42.     DECLARE_MESSAGE_MAP()
  43. };
  44.  
  45. CAboutDlg::CAboutDlg() : CDialog(CAboutDlg::IDD)
  46. {
  47.     //{{AFX_DATA_INIT(CAboutDlg)
  48.     //}}AFX_DATA_INIT
  49. }
  50.  
  51. void CAboutDlg::DoDataExchange(CDataExchange* pDX)
  52. {
  53.     CDialog::DoDataExchange(pDX);
  54.     //{{AFX_DATA_MAP(CAboutDlg)
  55.     //}}AFX_DATA_MAP
  56. }
  57.  
  58. BEGIN_MESSAGE_MAP(CAboutDlg, CDialog)
  59.     //{{AFX_MSG_MAP(CAboutDlg)
  60.         // No message handlers
  61.     //}}AFX_MSG_MAP
  62. END_MESSAGE_MAP()
  63.  
  64. /////////////////////////////////////////////////////////////////////////////
  65. // CAboutDlg message handlers
  66.  
  67. BOOL CAboutDlg::OnInitDialog()
  68. {
  69.     CDialog::OnInitDialog();
  70.     CenterWindow();
  71.  
  72.     // TODO: Add extra about dlg initialization here
  73.  
  74.     return TRUE;  // return TRUE  unless you set the focus to a control
  75. }
  76.  
  77. /////////////////////////////////////////////////////////////////////////////
  78. // CStdRegSetupDlg dialog
  79.  
  80. CStdRegSetupDlg::CStdRegSetupDlg(CWnd* pParent /*=NULL*/)
  81.     : CDialog(CStdRegSetupDlg::IDD, pParent)
  82. {
  83.     //{{AFX_DATA_INIT(CStdRegSetupDlg)
  84.         // NOTE: the ClassWizard will add member initialization here
  85.     //}}AFX_DATA_INIT
  86.     m_hIcon = AfxGetApp()->LoadIcon(IDR_MAINFRAME);
  87. }
  88.  
  89. void CStdRegSetupDlg::DoDataExchange(CDataExchange* pDX)
  90. {
  91.     CDialog::DoDataExchange(pDX);
  92.     //{{AFX_DATA_MAP(CStdRegSetupDlg)
  93.     DDX_Control(pDX, IDC_PROGRESS, m_ctlProgress);
  94.     //}}AFX_DATA_MAP
  95. }
  96.  
  97. BEGIN_MESSAGE_MAP(CStdRegSetupDlg, CDialog)
  98.     //{{AFX_MSG_MAP(CStdRegSetupDlg)
  99.     ON_WM_SYSCOMMAND()
  100.     ON_WM_PAINT()
  101.     ON_WM_QUERYDRAGICON()
  102.     ON_BN_CLICKED(IDC_ADD_DATA_SOURCE, OnAddDataSource)
  103.     ON_BN_CLICKED(IDC_INITIALIZE_DATA, OnInitializeData)
  104.     //}}AFX_MSG_MAP
  105. END_MESSAGE_MAP()
  106.  
  107. /////////////////////////////////////////////////////////////////////////////
  108. // CStdRegSetupDlg message handlers
  109.  
  110. BOOL CStdRegSetupDlg::OnInitDialog()
  111. {
  112.     CDialog::OnInitDialog();
  113.     CenterWindow();
  114.  
  115.     // Add "About..." menu item to system menu.
  116.  
  117.     // IDM_ABOUTBOX must be in the system command range.
  118.     ASSERT((IDM_ABOUTBOX & 0xFFF0) == IDM_ABOUTBOX);
  119.     ASSERT(IDM_ABOUTBOX < 0xF000);
  120.  
  121.     CMenu* pSysMenu = GetSystemMenu(FALSE);
  122.     CString strAboutMenu;
  123.     strAboutMenu.LoadString(IDS_ABOUTBOX);
  124.     if (!strAboutMenu.IsEmpty())
  125.     {
  126.         pSysMenu->AppendMenu(MF_SEPARATOR);
  127.         pSysMenu->AppendMenu(MF_STRING, IDM_ABOUTBOX, strAboutMenu);
  128.     }
  129.  
  130.     // TODO: Add extra initialization here
  131.  
  132.     return TRUE;  // return TRUE  unless you set the focus to a control
  133. }
  134.  
  135. void CStdRegSetupDlg::OnSysCommand(UINT nID, LPARAM lParam)
  136. {
  137.     if ((nID & 0xFFF0) == IDM_ABOUTBOX)
  138.     {
  139.         CAboutDlg dlgAbout;
  140.         dlgAbout.DoModal();
  141.     }
  142.     else
  143.     {
  144.         CDialog::OnSysCommand(nID, lParam);
  145.     }
  146. }
  147.  
  148. void CStdRegSetupDlg::OnPaint()
  149. {
  150.     CPaintDC dc(this); // device context for painting
  151.  
  152.     if (IsIconic())
  153.     {
  154.         SendMessage(WM_ICONERASEBKGND, (WPARAM) dc.GetSafeHdc(), 0);
  155.  
  156.         // Center icon in client rectangle
  157.         int xIcon = GetSystemMetrics(SM_CXICON);
  158.         int yIcon = GetSystemMetrics(SM_CYICON);
  159.         RECT rect;
  160.         GetClientRect(&rect);
  161.         int x = ((rect.right - rect.left + 1) - xIcon) / 2;
  162.         int y = ((rect.bottom - rect.top + 1) - yIcon) / 2;
  163.  
  164.         // Draw the icon
  165.         int nOldMapMode = dc.SetMapMode(MM_TEXT);
  166.         dc.DrawIcon(x, y, m_hIcon);
  167.         dc.SetMapMode(nOldMapMode);
  168.     }
  169. }
  170.  
  171. afx_msg HCURSOR CStdRegSetupDlg::OnQueryDragIcon()
  172. {
  173.     return (HCURSOR) m_hIcon;
  174. }
  175.  
  176. void CStdRegSetupDlg::OnAddDataSource()
  177. {
  178.     ((CStdRegSetupApp*)AfxGetApp())->AddDataSource();
  179. }
  180.  
  181. void CStdRegSetupDlg::OnInitializeData()
  182. {
  183.     ((CStdRegSetupApp*)AfxGetApp())->InitializeData();
  184. }
  185.  
  186. void CStdRegSetupDlg::OnOK()
  187. {
  188.     // Exit the app
  189.     CDialog::OnOK();
  190. }
  191.