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

  1. // wclsedit.cpp : registered WNDCLASS Edit control example
  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 "ctrltest.h"
  15.  
  16. #include "paredit.h"
  17.  
  18. /////////////////////////////////////////////////////////////////////////////
  19. // Dialog class
  20.  
  21. class CWclsEditDlg : public CDialog
  22. {
  23. public:
  24.     //{{AFX_DATA(CWclsEditDlg)
  25.         enum { IDD = IDD_WNDCLASS_EDIT };
  26.     //}}AFX_DATA
  27.     CWclsEditDlg()
  28.         : CDialog(CWclsEditDlg::IDD)
  29.         { }
  30.  
  31.     // access to controls is through inline helpers
  32.     CEdit&  Edit1()
  33.                 { return *(CEdit*)GetDlgItem(IDC_EDIT1); }
  34.     CEdit&  Edit2()
  35.                 { return *(CEdit*)GetDlgItem(IDC_EDIT2); }
  36.     CEdit&  Edit3()
  37.                 { return *(CEdit*)GetDlgItem(IDC_EDIT3); }
  38.     CEdit&  Edit4()
  39.                 { return *(CEdit*)GetDlgItem(IDC_EDIT4); }
  40.  
  41.     BOOL OnInitDialog();
  42.     //{{AFX_MSG(CWclsEditDlg)
  43.     virtual void OnOK();
  44.     afx_msg void OnIllegalChar();
  45.     //}}AFX_MSG
  46.     DECLARE_MESSAGE_MAP();
  47. };
  48.  
  49. BOOL CWclsEditDlg::OnInitDialog()
  50. {
  51.     // nothing special to do
  52.     return TRUE;
  53. }
  54.  
  55. void CWclsEditDlg::OnOK()
  56. {
  57. #ifdef _DEBUG
  58.     // dump results, normally you would do something with these
  59.     CString s;
  60.     Edit1().GetWindowText(s);
  61.     TRACE1("edit1 = '%s'\n", s);
  62.     Edit2().GetWindowText(s);
  63.     TRACE1("edit2 = '%s'\n", s);
  64.     Edit3().GetWindowText(s);
  65.     TRACE1("edit3 = '%s'\n", s);
  66.     Edit4().GetWindowText(s);
  67.     TRACE1("edit4 = '%s'\n", s);
  68. #endif
  69.  
  70.     EndDialog(IDOK);
  71. }
  72.  
  73. /////////////////////////////////////////////////////////////////////////////
  74. // Handle custom control notification here
  75.  
  76. BEGIN_MESSAGE_MAP(CWclsEditDlg, CDialog)
  77.     //{{AFX_MSG_MAP(CWclsEditDlg)
  78.     ON_CONTROL(PEN_ILLEGALCHAR, IDC_EDIT1, OnIllegalChar)
  79.     ON_CONTROL(PEN_ILLEGALCHAR, IDC_EDIT2, OnIllegalChar)
  80.     ON_CONTROL(PEN_ILLEGALCHAR, IDC_EDIT3, OnIllegalChar)
  81.     ON_CONTROL(PEN_ILLEGALCHAR, IDC_EDIT4, OnIllegalChar)
  82.     //}}AFX_MSG_MAP
  83. END_MESSAGE_MAP()
  84.  
  85.  
  86. void  CWclsEditDlg::OnIllegalChar()
  87. {
  88.     TRACE0("Don't do that!\n");
  89.     // add extra reporting here...
  90. }
  91.  
  92. /////////////////////////////////////////////////////////////////////////////
  93. // Run the test
  94.  
  95. void CTestWindow::OnTestWndClassEdit()
  96. {
  97.     TRACE0("running dialog containing WNDCLASS special edit items\n");
  98.     if (!CParsedEdit::RegisterControlClass())
  99.     {
  100.         CString strMsg;
  101.         strMsg.LoadString(IDS_WNDCLASS_NOT_REGISTERED);
  102.         MessageBox(strMsg);
  103.         return;
  104.     }
  105.     CWclsEditDlg dlg;
  106.     dlg.DoModal();
  107. }
  108.  
  109.  
  110. /////////////////////////////////////////////////////////////////////////////
  111.