home *** CD-ROM | disk | FTP | other *** search
/ Mastering Visual Basic 5 / MasteringVisualBasic5.iso / protview / demowinx / data.2 / maskedit / samples / MFC / MASKDEMO / MASKDLG.CPP < prev    next >
Encoding:
C/C++ Source or Header  |  1996-10-28  |  7.1 KB  |  245 lines

  1. // MaskDlg.cpp : implementation file
  2. //
  3.  
  4. #include "stdafx.h"
  5. #include "MaskDemo.h"
  6. #include "MaskDlg.h"
  7. #include "MaskEdit.h"
  8.  
  9. #ifdef _DEBUG
  10. #define new DEBUG_NEW
  11. #undef THIS_FILE
  12. static char THIS_FILE[] = __FILE__;
  13. #endif
  14.  
  15. /////////////////////////////////////////////////////////////////////////////
  16. // CMaskDlg dialog
  17.  
  18. CMaskDlg::CMaskDlg(CWnd* pParent /*=NULL*/)
  19.     : CDialog(CMaskDlg::IDD, pParent)
  20. {
  21.     //{{AFX_DATA_INIT(CMaskDlg)
  22.         // NOTE: the ClassWizard will add member initialization here
  23.     //}}AFX_DATA_INIT
  24.     // Note that LoadIcon does not require a subsequent DestroyIcon in Win32
  25.     m_hIcon = AfxGetApp()->LoadIcon(IDR_MAINFRAME);
  26. }
  27.  
  28. void CMaskDlg::DoDataExchange(CDataExchange* pDX)
  29. {
  30.     CDialog::DoDataExchange(pDX);
  31.     //{{AFX_DATA_MAP(CMaskDlg)
  32.         // NOTE: the ClassWizard will add DDX and DDV calls here
  33.     //}}AFX_DATA_MAP
  34. }
  35.  
  36. BEGIN_MESSAGE_MAP(CMaskDlg, CDialog)
  37.     //{{AFX_MSG_MAP(CMaskDlg)
  38.     ON_WM_PAINT()
  39.     ON_WM_QUERYDRAGICON()
  40.     ON_BN_CLICKED(IDC_SETMASKTEXT, OnSetmasktext)
  41.     ON_CBN_SELCHANGE(IDC_BACKCOLOR, OnSelchangeBackcolor)
  42.     ON_CBN_SELCHANGE(IDC_DISPLAY, OnSelchangeDisplay)
  43.     ON_CBN_SELCHANGE(IDC_FORECOLOR, OnSelchangeForecolor)
  44.     ON_CBN_SELCHANGE(IDC_HIGHLIGHTCOLOR, OnSelchangeHighlightcolor)
  45.     ON_BN_CLICKED(IDC_INVERTED, OnInverted)
  46.     ON_BN_CLICKED(IDC_FLAT, OnFlat)
  47.     ON_BN_CLICKED(IDC_BORDER, OnBorder)
  48.     //}}AFX_MSG_MAP
  49. END_MESSAGE_MAP()
  50.  
  51. /////////////////////////////////////////////////////////////////////////////
  52. // CMaskDlg message handlers
  53.  
  54. BOOL CMaskDlg::OnInitDialog()
  55. {
  56.     CDialog::OnInitDialog();
  57.  
  58.     // Set the icon for this dialog.  The framework does this automatically
  59.     //  when the application's main window is not a dialog
  60.     SetIcon(m_hIcon, TRUE);            // Set big icon
  61.     SetIcon(m_hIcon, FALSE);        // Set small icon
  62.     
  63.     // TODO: Add extra initialization here
  64.     RECT       r;
  65.     CMaskEdit  *pME = (CMaskEdit*)GetDlgItem(IDC_MASKEDIT);
  66.     pME->GetClientRect(&r);
  67.     //-------------------------------------------
  68.     // memorize size of control window
  69.     m_iWidth = r.right;
  70.     m_iHeight = r.bottom;
  71.     
  72.     CComboBox *pCombo = (CComboBox*)GetDlgItem(IDC_DISPLAY);
  73.     pCombo->SetCurSel(0);  //normal
  74.     pCombo = (CComboBox*)GetDlgItem(IDC_FORECOLOR);
  75.     pCombo->SetCurSel(11); //black
  76.     pCombo = (CComboBox*)GetDlgItem(IDC_BACKCOLOR);
  77.     pCombo->SetCurSel(0);  //white
  78.     pCombo = (CComboBox*)GetDlgItem(IDC_HIGHLIGHTCOLOR);
  79.     pCombo->SetCurSel(8);  //blue
  80.  
  81.     return TRUE;  // return TRUE  unless you set the focus to a control
  82. }
  83.  
  84. // If you add a minimize button to your dialog, you will need the code below
  85. //  to draw the icon.  For MFC applications using the document/view model,
  86. //  this is automatically done for you by the framework.
  87.  
  88. void CMaskDlg::OnPaint() 
  89. {
  90.     if (IsIconic())
  91.     {
  92.         CPaintDC dc(this); // device context for painting
  93.  
  94.         SendMessage(WM_ICONERASEBKGND, (WPARAM) dc.GetSafeHdc(), 0);
  95.  
  96.         // Center icon in client rectangle
  97.         int cxIcon = GetSystemMetrics(SM_CXICON);
  98.         int cyIcon = GetSystemMetrics(SM_CYICON);
  99.         CRect rect;
  100.         GetClientRect(&rect);
  101.         int x = (rect.Width() - cxIcon + 1) / 2;
  102.         int y = (rect.Height() - cyIcon + 1) / 2;
  103.  
  104.         // Draw the icon
  105.         dc.DrawIcon(x, y, m_hIcon);
  106.     }
  107.     else
  108.     {
  109.         CDialog::OnPaint();
  110.     }
  111. }
  112.  
  113. // The system calls this to obtain the cursor to display while the user drags
  114. //  the minimized window.
  115. HCURSOR CMaskDlg::OnQueryDragIcon()
  116. {
  117.     return (HCURSOR) m_hIcon;
  118. }
  119.  
  120. BEGIN_EVENTSINK_MAP(CMaskDlg, CDialog)
  121.     //{{AFX_EVENTSINK_MAP(CMaskDlg)
  122.     ON_EVENT(CMaskDlg, IDC_MASKEDIT1, -604 /* KeyUp */, OnKeyUpMaskedit1, VTS_PI2 VTS_I2)
  123.     ON_EVENT(CMaskDlg, IDC_MASKEDIT2, -604 /* KeyUp */, OnKeyUpMaskedit2, VTS_PI2 VTS_I2)
  124.     ON_EVENT(CMaskDlg, IDC_MASKEDIT3, -604 /* KeyUp */, OnKeyUpMaskedit3, VTS_PI2 VTS_I2)
  125.     ON_EVENT(CMaskDlg, IDC_MASKEDIT4, -604 /* KeyUp */, OnKeyUpMaskedit4, VTS_PI2 VTS_I2)
  126.     //}}AFX_EVENTSINK_MAP
  127. END_EVENTSINK_MAP()
  128.  
  129. void CMaskDlg::OnKeyUpMaskedit1(short FAR* KeyCode, short Shift) 
  130. {
  131.     CMaskEdit *pMask = (CMaskEdit*)GetDlgItem(IDC_MASKEDIT2);
  132.     pMask->SetTextWithMask((LPCTSTR)((CMaskEdit*)GetDlgItem(IDC_MASKEDIT1))->GetTextWithMask());
  133. }
  134.  
  135. void CMaskDlg::OnKeyUpMaskedit2(short FAR* KeyCode, short Shift) 
  136. {
  137.     CMaskEdit *pMask = (CMaskEdit*)GetDlgItem(IDC_MASKEDIT1);
  138.     pMask->SetTextWithMask(((CMaskEdit*)GetDlgItem(IDC_MASKEDIT2))->GetTextWithMask());
  139. }
  140.  
  141. void CMaskDlg::OnKeyUpMaskedit3(short FAR* KeyCode, short Shift) 
  142. {
  143.     CMaskEdit *pMask = (CMaskEdit*)GetDlgItem(IDC_MASKEDIT4);
  144.     pMask->SetText(((CMaskEdit*)GetDlgItem(IDC_MASKEDIT3))->GetText());
  145. }
  146.  
  147. void CMaskDlg::OnKeyUpMaskedit4(short FAR* KeyCode, short Shift) 
  148. {
  149.     CMaskEdit *pMask = (CMaskEdit*)GetDlgItem(IDC_MASKEDIT3);
  150.     CString str;
  151.     GetDlgItemText(IDC_MASKEDIT4, str);
  152.     pMask->SetText(str);
  153. }
  154.  
  155. void CMaskDlg::OnSetmasktext() 
  156. {
  157.     CMaskEdit *pTarget = (CMaskEdit*)GetDlgItem(IDC_TARGET);
  158.     CString str;
  159.     GetDlgItemText(IDC_MASK, str);
  160.     pTarget->SetMask(str);
  161.     GetDlgItemText(IDC_TEXT, str);
  162.     pTarget->SetText(str);
  163. }
  164.  
  165. void CMaskDlg::OnSelchangeBackcolor() 
  166. {
  167.     CMaskEdit *pME = (CMaskEdit*)GetDlgItem(IDC_MASKEDIT);
  168.     CComboBox *pColor = (CComboBox*)GetDlgItem(IDC_BACKCOLOR);
  169.     pME->SetBackColor(GetColor(pColor->GetCurSel()));
  170. }
  171.  
  172. void CMaskDlg::OnSelchangeDisplay() 
  173. {
  174.     CMaskEdit *pME = (CMaskEdit*)GetDlgItem(IDC_MASKEDIT);
  175.     CComboBox *pDisplay = (CComboBox*)GetDlgItem(IDC_DISPLAY);
  176.     pME->SetDisplayFormat(pDisplay->GetCurSel());
  177.     //--------------------------------------------------
  178.     // restore initial size of control window
  179.     pME->SetWindowPos(&wndTop, 0, 0, m_iWidth, m_iHeight, 
  180.         SWP_NOMOVE | SWP_NOZORDER);
  181.     //--------------------------------------------------
  182.     // set selected colors
  183.     OnSelchangeHighlightcolor();
  184.     OnSelchangeForecolor();
  185.     OnSelchangeBackcolor();
  186. }
  187.  
  188. void CMaskDlg::OnSelchangeForecolor() 
  189. {
  190.     CMaskEdit *pME = (CMaskEdit*)GetDlgItem(IDC_MASKEDIT);
  191.     CComboBox *pColor = (CComboBox*)GetDlgItem(IDC_FORECOLOR);
  192.     pME->SetForeColor(GetColor(pColor->GetCurSel()));
  193. }
  194.  
  195. void CMaskDlg::OnSelchangeHighlightcolor() 
  196. {
  197.     CMaskEdit *pME = (CMaskEdit*)GetDlgItem(IDC_MASKEDIT);
  198.     CComboBox *pColor = (CComboBox*)GetDlgItem(IDC_HIGHLIGHTCOLOR);
  199.     pME->SetHighlightColor(GetColor(pColor->GetCurSel()));
  200. }
  201.  
  202. void CMaskDlg::OnInverted() 
  203. {
  204.     CMaskEdit *pME = (CMaskEdit*)GetDlgItem(IDC_MASKEDIT);
  205.     pME->SetHighlightInverted(((CButton*)GetDlgItem(IDC_INVERTED))->GetCheck());
  206. }
  207.  
  208. void CMaskDlg::OnFlat() 
  209. {
  210.     CMaskEdit *pME = (CMaskEdit*)GetDlgItem(IDC_MASKEDIT);
  211.     if(((CButton*)GetDlgItem(IDC_FLAT))->GetCheck())
  212.         pME->SetAppearance(0);
  213.     else
  214.         pME->SetAppearance(1);
  215. }
  216.  
  217. COLORREF CMaskDlg::GetColor(int id)
  218. {
  219.     switch(id)
  220.     {
  221.         case 0:  return 0x02ffffff;
  222.         case 1:  return 0x02c0c0c0;
  223.         case 2:  return 0x02808080;
  224.         case 3:  return 0x02ffff00;
  225.         case 4:  return 0x02ff0000;
  226.         case 5:  return 0x0200ff00;
  227.         case 6:  return 0x02008000;
  228.         case 7:  return 0x0200ffff;
  229.         case 8:  return 0x020000ff;
  230.         case 9:  return 0x02ff00ff;
  231.         case 10: return 0x02000080;
  232.         case 11: return 0x02000000;
  233.     }
  234.     return 0x02000000;
  235. }
  236.  
  237. void CMaskDlg::OnBorder() 
  238. {
  239.     CMaskEdit *pME = (CMaskEdit*)GetDlgItem(IDC_MASKEDIT);
  240.     if(((CButton*)GetDlgItem(IDC_BORDER))->GetCheck())
  241.         pME->SetBorderStyle(1);
  242.     else
  243.         pME->SetBorderStyle(0);
  244. }
  245.