home *** CD-ROM | disk | FTP | other *** search
/ QBasic & Borland Pascal & C / Delphi5.iso / C / BC_502 / MODELES.PAK / MODELDLG.CPP < prev    next >
Encoding:
C/C++ Source or Header  |  1997-05-06  |  5.0 KB  |  203 lines

  1. // modeldlg.cpp : implementation file
  2. //
  3.  
  4. // This is a part of the Microsoft Foundation Classes C++ library.
  5. // Copyright (C) 1992-1995 Microsoft Corporation
  6. // All rights reserved.
  7. //
  8. // This source code is only intended as a supplement to the
  9. // Microsoft Foundation Classes Reference and related
  10. // electronic documentation provided with the library.
  11. // See these sources for detailed information regarding the
  12. // Microsoft Foundation Classes product.
  13.  
  14. #include "stdafx.h"
  15. #include "modeless.h"
  16. #include "adderdlg.h"
  17. #include "modeldlg.h"
  18.   
  19. #ifdef _debug
  20. #undef this_file
  21. static char based_code THIS_FILE[] = __FILE__;
  22. #endif
  23.  
  24. /////////////////////////////////////////////////////////////////////////////
  25. // CAboutDlg dialog used for App About
  26.  
  27. class CAboutDlg : public CDialog
  28. {
  29. public:
  30.     CAboutDlg();
  31.  
  32. // Dialog Data
  33.     //{{AFX_DATA(CAboutDlg)
  34.     enum { IDD = IDD_ABOUTBOX };
  35.     //}}AFX_DATA
  36.  
  37. // Implementation
  38. protected:
  39.     virtual void DoDataExchange(CDataExchange* pDX);    // DDX/DDV support
  40.     //{{AFX_MSG(CAboutDlg)
  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. // CMainDlg dialog
  66.  
  67. CMainDlg::CMainDlg(CWnd* pParent /*=NULL*/)
  68.     : CDialog(CMainDlg::IDD, pParent)
  69. {
  70.     //{{AFX_DATA_INIT(CMainDlg)
  71.         // NOTE: the ClassWizard will add member initialization here
  72.     //}}AFX_DATA_INIT
  73.     // Note that LoadIcon does not require a subsequent DestroyIcon in Win32
  74.     m_hIcon = AfxGetApp()->LoadIcon(IDR_MAINFRAME);
  75.     m_pModeless = NULL;
  76. }
  77.  
  78. void CMainDlg::DoDataExchange(CDataExchange* pDX)
  79. {
  80.     CDialog::DoDataExchange(pDX);
  81.     //{{AFX_DATA_MAP(CMainDlg)
  82.         // NOTE: the ClassWizard will add DDX and DDV calls here
  83.     //}}AFX_DATA_MAP
  84. }
  85.  
  86. BEGIN_MESSAGE_MAP(CMainDlg, CDialog)
  87.     //{{AFX_MSG_MAP(CMainDlg)
  88.     ON_WM_SYSCOMMAND()
  89.     ON_WM_PAINT()
  90.     ON_WM_QUERYDRAGICON()
  91.     //}}AFX_MSG_MAP
  92. END_MESSAGE_MAP()
  93.  
  94. /////////////////////////////////////////////////////////////////////////////
  95. // CMainDlg message handlers
  96.  
  97. BOOL CMainDlg::OnInitDialog()
  98. {
  99.     CDialog::OnInitDialog(    );
  100.  
  101.     // Add "About..." menu item to system menu.
  102.  
  103.     // IDM_ABOUTBOX must be in the system command range.
  104.     ASSERT((IDM_ABOUTBOX & 0xFFF0) == IDM_ABOUTBOX);
  105.     ASSERT(IDM_ABOUTBOX < 0xF000);
  106.  
  107.     CMenu* pSysMenu = GetSystemMenu(FALSE);
  108.     CString strAboutMenu;
  109.     strAboutMenu.LoadString(IDS_ABOUTBOX);
  110.     if (!strAboutMenu.IsEmpty())
  111.     {
  112. #ifdef _MAC
  113.         // On the Macintosh, the "About..." menu item is already there.  We
  114.         //  just need to rename it and attach it to the about command.
  115.         pSysMenu->ModifyMenu(0, MF_BYPOSITION, IDM_ABOUTBOX, strAboutMenu);
  116. #else
  117.         pSysMenu->AppendMenu(MF_SEPARATOR);
  118.         pSysMenu->AppendMenu(MF_STRING, IDM_ABOUTBOX, strAboutMenu);
  119. #endif
  120.     }
  121.     
  122.     // TODO: Add extra initialization here
  123.     
  124.     return TRUE;  // return TRUE  unless you set the focus to a control
  125. }
  126.  
  127. void CMainDlg::OnSysCommand(UINT nID, LPARAM lParam)
  128. {
  129.     if ((nID & 0xFFF0) == IDM_ABOUTBOX)
  130.     {
  131.         CAboutDlg dlgAbout;
  132.         dlgAbout.DoModal();
  133.     }
  134.     else
  135.     {
  136.         CDialog::OnSysCommand(nID, lParam);
  137.     }
  138. }
  139.  
  140. // If you add a minimize button to your dialog, you will need the code below
  141. //  to draw the icon.  For MFC applications using the document/view model,
  142. //  this is automatically done for you by the framework.
  143.  
  144. void CMainDlg::OnPaint() 
  145. {
  146.     if (IsIconic())
  147.     {
  148.         CPaintDC dc(this); // device context for painting
  149.  
  150.         SendMessage(WM_ICONERASEBKGND, (WPARAM) dc.GetSafeHdc(), 0);
  151.  
  152.         // Center icon in client rectangle
  153.         int cxIcon = GetSystemMetrics(SM_CXICON);
  154.         int cyIcon = GetSystemMetrics(SM_CYICON);
  155.         CRect rect;
  156.         GetClientRect(&rect);
  157.         int x = (rect.Width() - cxIcon + 1) / 2;
  158.         int y = (rect.Height() - cyIcon + 1) / 2;
  159.  
  160.         // Draw the icon
  161.         dc.DrawIcon(x, y, m_hIcon);
  162.     }
  163.     else
  164.     {
  165.         CDialog::OnPaint();
  166.     }
  167. }
  168.  
  169. // The system calls this to obtain the cursor to display while the user drags
  170. //  the minimized window.
  171. HCURSOR CMainDlg::OnQueryDragIcon()
  172. {
  173.     return (HCURSOR) m_hIcon;
  174. }
  175.  
  176. void CMainDlg::OnOK() 
  177. {
  178.     // if our modeless child isn't already up, create it and display it
  179.     // otherwise, just set focus to it
  180.  
  181.     if (m_pModeless == NULL)
  182.     {
  183.         m_pModeless = new CAdderDialog(this);
  184.         if (m_pModeless->Create() == TRUE)
  185.             GetDlgItem(IDOK)->EnableWindow(FALSE);
  186.     }
  187.     else
  188.         m_pModeless->SetActiveWindow();
  189. }
  190.  
  191.  
  192. void CMainDlg::BoxDone()
  193. {
  194.     // this function is called by the modeless dialog as it terminates
  195.     // just reset our pushbutton to be enabled again.
  196.     // I _don't_ delete the MFC CDialog object because the dialog's own
  197.     // code will do that.
  198.     
  199.     m_pModeless = NULL;
  200.     // don't delete m_pModeless; !
  201.     GetDlgItem(IDOK)->EnableWindow();
  202. }
  203.