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

  1. // dlgtempDlg.cpp : implementation file
  2. //
  3.  
  4. // This is a part of the Microsoft Foundation Classes C++ library.
  5. // Copyright (C) 1992-1996 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 "dlgtemp.h"
  16. #include "setupdlg.h"
  17.  
  18. #ifdef _DEBUG
  19. #define new DEBUG_NEW
  20. #undef THIS_FILE
  21. static char 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.     // ClassWizard generated virtual function overrides
  38.     //{{AFX_VIRTUAL(CAboutDlg)
  39.     protected:
  40.     virtual void DoDataExchange(CDataExchange* pDX);    // DDX/DDV support
  41.     //}}AFX_VIRTUAL
  42.  
  43. // Implementation
  44. protected:
  45.     //{{AFX_MSG(CAboutDlg)
  46.     //}}AFX_MSG
  47.     DECLARE_MESSAGE_MAP()
  48. };
  49.  
  50. CAboutDlg::CAboutDlg() : CDialog(CAboutDlg::IDD)
  51. {
  52.     //{{AFX_DATA_INIT(CAboutDlg)
  53.     //}}AFX_DATA_INIT
  54. }
  55.  
  56. void CAboutDlg::DoDataExchange(CDataExchange* pDX)
  57. {
  58.     CDialog::DoDataExchange(pDX);
  59.     //{{AFX_DATA_MAP(CAboutDlg)
  60.     //}}AFX_DATA_MAP
  61. }
  62.  
  63. BEGIN_MESSAGE_MAP(CAboutDlg, CDialog)
  64.     //{{AFX_MSG_MAP(CAboutDlg)
  65.         // No message handlers
  66.     //}}AFX_MSG_MAP
  67. END_MESSAGE_MAP()
  68.  
  69. /////////////////////////////////////////////////////////////////////////////
  70. // CDlgtempDlg dialog
  71.  
  72. CDlgtempDlg::CDlgtempDlg(CWnd* pParent /*=NULL*/)
  73.     : CDialog(CDlgtempDlg::IDD, pParent)
  74. {
  75.     m_nActiveItem = -1;
  76.  
  77.     //{{AFX_DATA_INIT(CDlgtempDlg)
  78.     m_strCaption = _T("");
  79.     m_x = 0;
  80.     m_y = 0;
  81.     m_nWidth = 0;
  82.     m_nHeight = 0;
  83.     m_nItem = -1;
  84.     m_strSelectedItem = _T("");
  85.     //}}AFX_DATA_INIT
  86.     // Note that LoadIcon does not require a subsequent DestroyIcon in Win32
  87.     m_hIcon = AfxGetApp()->LoadIcon(IDR_MAINFRAME);
  88. }
  89.  
  90. void CDlgtempDlg::DoDataExchange(CDataExchange* pDX)
  91. {
  92.     CDialog::DoDataExchange(pDX);
  93.     //{{AFX_DATA_MAP(CDlgtempDlg)
  94.     DDX_Text(pDX, IDC_CAPTION, m_strCaption);
  95.     DDX_Text(pDX, IDC_XPOS, m_x);
  96.     DDV_MinMaxUInt(pDX, m_x, 0, 300);
  97.     DDX_Text(pDX, IDC_YPOS, m_y);
  98.     DDV_MinMaxUInt(pDX, m_y, 0, 200);
  99.     DDX_Text(pDX, IDC_WIDTH, m_nWidth);
  100.     DDX_Text(pDX, IDC_HEIGHT, m_nHeight);
  101.     DDX_Radio(pDX, IDC_BUTTON, m_nItem);
  102.     DDX_Text(pDX, IDC_SELECTEDITEM, m_strSelectedItem);
  103.     //}}AFX_DATA_MAP
  104. }
  105.  
  106. BEGIN_MESSAGE_MAP(CDlgtempDlg, CDialog)
  107.     //{{AFX_MSG_MAP(CDlgtempDlg)
  108.     ON_WM_SYSCOMMAND()
  109.     ON_WM_PAINT()
  110.     ON_BN_CLICKED(IDC_DEMOIT, OnDemoIt)
  111.     ON_BN_CLICKED(IDC_BUTTON, OnButtonInformation)
  112.     ON_BN_CLICKED(IDC_STATICTEXT, OnStaticTextInformation)
  113.     ON_BN_CLICKED(IDC_EDITCONTROL, OnEditControlInformation)
  114.     //}}AFX_MSG_MAP
  115. END_MESSAGE_MAP()
  116.  
  117. /////////////////////////////////////////////////////////////////////////////
  118. // CDlgtempDlg message handlers
  119.  
  120. BOOL CDlgtempDlg::OnInitDialog()
  121. {
  122.     CDialog::OnInitDialog();
  123.  
  124.     // Add "About..." menu item to system menu.
  125.  
  126.     // IDM_ABOUTBOX must be in the system command range.
  127.     ASSERT((IDM_ABOUTBOX & 0xFFF0) == IDM_ABOUTBOX);
  128.     ASSERT(IDM_ABOUTBOX < 0xF000);
  129.  
  130.     CMenu* pSysMenu = GetSystemMenu(FALSE);
  131.     CString strAboutMenu;
  132.     strAboutMenu.LoadString(IDS_ABOUTBOX);
  133.     if (!strAboutMenu.IsEmpty())
  134.     {
  135. #ifdef _MAC
  136.         // On the Macintosh, the "About..." menu item is already there.  We
  137.         //  just need to rename it and attach it to the about command.
  138.         pSysMenu->ModifyMenu(0, MF_BYPOSITION, IDM_ABOUTBOX, strAboutMenu);
  139. #else
  140.         pSysMenu->AppendMenu(MF_SEPARATOR);
  141.         pSysMenu->AppendMenu(MF_STRING, IDM_ABOUTBOX, strAboutMenu);
  142. #endif
  143.     }
  144.  
  145.     // Set the icon for this dialog.  The framework does this automatically
  146.     //  when the application's main window is not a dialog
  147.     SetIcon(m_hIcon, TRUE);            // Set big icon
  148.     SetIcon(m_hIcon, FALSE);        // Set small icon
  149.     
  150.     m_nItem = 0;        // select the BUTTON option 
  151.     OnButtonInformation();  // fill the edit fields with corresponding values
  152.  
  153.     return TRUE;  // return TRUE  unless you set the focus to a control
  154. }
  155.  
  156. void CDlgtempDlg::OnSysCommand(UINT nID, LPARAM lParam)
  157. {
  158.     if ((nID & 0xFFF0) == IDM_ABOUTBOX)
  159.     {
  160.         CAboutDlg dlgAbout;
  161.         dlgAbout.DoModal();
  162.     }
  163.     else
  164.     {
  165.         CDialog::OnSysCommand(nID, lParam);
  166.     }
  167. }
  168.  
  169. // If you add a minimize button to your dialog, you will need the code below
  170. //  to draw the icon.  For MFC applications using the document/view model,
  171. //  this is automatically done for you by the framework.
  172.  
  173. void CDlgtempDlg::OnPaint() 
  174. {
  175.     if (IsIconic())
  176.     {
  177.         CPaintDC dc(this); // device context for painting
  178.  
  179.         SendMessage(WM_ICONERASEBKGND, (WPARAM) dc.GetSafeHdc(), 0);
  180.  
  181.         // Center icon in client rectangle
  182.         int cxIcon = GetSystemMetrics(SM_CXICON);
  183.         int cyIcon = GetSystemMetrics(SM_CYICON);
  184.         CRect rect;
  185.         GetClientRect(&rect);
  186.         int x = (rect.Width() - cxIcon + 1) / 2;
  187.         int y = (rect.Height() - cyIcon + 1) / 2;
  188.  
  189.         // Draw the icon
  190.         dc.DrawIcon(x, y, m_hIcon);
  191.     }
  192.     else
  193.     {
  194.         CDialog::OnPaint();
  195.     }
  196. }
  197.  
  198. void CDlgtempDlg::OnDemoIt() 
  199. {
  200.     InfoToDialogHelper(m_nActiveItem, NULL);
  201.     m_dlgTemplate.DemoIt();
  202. }
  203.  
  204. void CDlgtempDlg::OnButtonInformation() 
  205. {
  206.     // take the information about the button and send it to the edit 
  207.     // controls in the dialog.
  208.     InfoToDialogHelper(IBUTTON, _T("BUTTON"));
  209. }
  210.  
  211. void CDlgtempDlg::OnStaticTextInformation()
  212. {
  213.     InfoToDialogHelper(ISTATICTEXT, _T("STATIC TEXT"));
  214. }
  215.  
  216. void CDlgtempDlg::OnEditControlInformation()
  217. {
  218.     InfoToDialogHelper(IEDITCONTROL, _T("EDIT CONTROL"));
  219. }
  220.  
  221. void CDlgtempDlg::InfoToDialogHelper(int nItem, LPCTSTR lpszSelection)
  222. {
  223.     // first bring data from edit field and store in proper item
  224.     if (m_nActiveItem != -1)
  225.     {
  226.         UpdateData(TRUE/*bSaveAndValidate*/);
  227.         m_dlgTemplate.m_rgDlgItem[m_nActiveItem].m_dlgItemTemplate.x = m_x;
  228.         m_dlgTemplate.m_rgDlgItem[m_nActiveItem].m_dlgItemTemplate.y = m_y;
  229.         m_dlgTemplate.m_rgDlgItem[m_nActiveItem].m_dlgItemTemplate.cx = m_nWidth;
  230.         m_dlgTemplate.m_rgDlgItem[m_nActiveItem].m_dlgItemTemplate.cy = m_nHeight;
  231.         m_dlgTemplate.m_rgDlgItem[m_nActiveItem].m_strCaption = m_strCaption;
  232.     }
  233.  
  234.     // now bring data from item and send to edit fields
  235.     if (m_nActiveItem != nItem)
  236.     {
  237.         m_x = m_dlgTemplate.m_rgDlgItem[nItem].m_dlgItemTemplate.x;
  238.         m_y = m_dlgTemplate.m_rgDlgItem[nItem].m_dlgItemTemplate.y;
  239.         m_nWidth = m_dlgTemplate.m_rgDlgItem[nItem].m_dlgItemTemplate.cx;
  240.         m_nHeight = m_dlgTemplate.m_rgDlgItem[nItem].m_dlgItemTemplate.cy;
  241.         m_strCaption = m_dlgTemplate.m_rgDlgItem[nItem].m_strCaption;
  242.         ASSERT(lpszSelection != NULL);
  243.         m_strSelectedItem = lpszSelection;
  244.         m_nItem = nItem;
  245.         m_nActiveItem = nItem;
  246.         UpdateData(FALSE/*bSaveAndValidate*/);
  247.     }
  248.  
  249.     CWnd*    pwnd = GetDlgItem(IDC_CAPTION);
  250.     pwnd->EnableWindow(nItem != IEDITCONTROL);
  251. }
  252.  
  253.