home *** CD-ROM | disk | FTP | other *** search
- // MaskDlg.cpp : implementation file
- //
-
- #include "stdafx.h"
- #include "MaskDemo.h"
- #include "MaskDlg.h"
- #include "MaskEdit.h"
-
- #ifdef _DEBUG
- #define new DEBUG_NEW
- #undef THIS_FILE
- static char THIS_FILE[] = __FILE__;
- #endif
-
- /////////////////////////////////////////////////////////////////////////////
- // CMaskDlg dialog
-
- CMaskDlg::CMaskDlg(CWnd* pParent /*=NULL*/)
- : CDialog(CMaskDlg::IDD, pParent)
- {
- //{{AFX_DATA_INIT(CMaskDlg)
- // NOTE: the ClassWizard will add member initialization here
- //}}AFX_DATA_INIT
- // Note that LoadIcon does not require a subsequent DestroyIcon in Win32
- m_hIcon = AfxGetApp()->LoadIcon(IDR_MAINFRAME);
- }
-
- void CMaskDlg::DoDataExchange(CDataExchange* pDX)
- {
- CDialog::DoDataExchange(pDX);
- //{{AFX_DATA_MAP(CMaskDlg)
- // NOTE: the ClassWizard will add DDX and DDV calls here
- //}}AFX_DATA_MAP
- }
-
- BEGIN_MESSAGE_MAP(CMaskDlg, CDialog)
- //{{AFX_MSG_MAP(CMaskDlg)
- ON_WM_PAINT()
- ON_WM_QUERYDRAGICON()
- ON_BN_CLICKED(IDC_SETMASKTEXT, OnSetmasktext)
- ON_CBN_SELCHANGE(IDC_BACKCOLOR, OnSelchangeBackcolor)
- ON_CBN_SELCHANGE(IDC_DISPLAY, OnSelchangeDisplay)
- ON_CBN_SELCHANGE(IDC_FORECOLOR, OnSelchangeForecolor)
- ON_CBN_SELCHANGE(IDC_HIGHLIGHTCOLOR, OnSelchangeHighlightcolor)
- ON_BN_CLICKED(IDC_INVERTED, OnInverted)
- ON_BN_CLICKED(IDC_FLAT, OnFlat)
- ON_BN_CLICKED(IDC_BORDER, OnBorder)
- //}}AFX_MSG_MAP
- END_MESSAGE_MAP()
-
- /////////////////////////////////////////////////////////////////////////////
- // CMaskDlg message handlers
-
- BOOL CMaskDlg::OnInitDialog()
- {
- CDialog::OnInitDialog();
-
- // Set the icon for this dialog. The framework does this automatically
- // when the application's main window is not a dialog
- SetIcon(m_hIcon, TRUE); // Set big icon
- SetIcon(m_hIcon, FALSE); // Set small icon
-
- // TODO: Add extra initialization here
- RECT r;
- CMaskEdit *pME = (CMaskEdit*)GetDlgItem(IDC_MASKEDIT);
- pME->GetClientRect(&r);
- //-------------------------------------------
- // memorize size of control window
- m_iWidth = r.right;
- m_iHeight = r.bottom;
-
- CComboBox *pCombo = (CComboBox*)GetDlgItem(IDC_DISPLAY);
- pCombo->SetCurSel(0); //normal
- pCombo = (CComboBox*)GetDlgItem(IDC_FORECOLOR);
- pCombo->SetCurSel(11); //black
- pCombo = (CComboBox*)GetDlgItem(IDC_BACKCOLOR);
- pCombo->SetCurSel(0); //white
- pCombo = (CComboBox*)GetDlgItem(IDC_HIGHLIGHTCOLOR);
- pCombo->SetCurSel(8); //blue
-
- return TRUE; // return TRUE unless you set the focus to a control
- }
-
- // If you add a minimize button to your dialog, you will need the code below
- // to draw the icon. For MFC applications using the document/view model,
- // this is automatically done for you by the framework.
-
- void CMaskDlg::OnPaint()
- {
- if (IsIconic())
- {
- CPaintDC dc(this); // device context for painting
-
- SendMessage(WM_ICONERASEBKGND, (WPARAM) dc.GetSafeHdc(), 0);
-
- // Center icon in client rectangle
- int cxIcon = GetSystemMetrics(SM_CXICON);
- int cyIcon = GetSystemMetrics(SM_CYICON);
- CRect rect;
- GetClientRect(&rect);
- int x = (rect.Width() - cxIcon + 1) / 2;
- int y = (rect.Height() - cyIcon + 1) / 2;
-
- // Draw the icon
- dc.DrawIcon(x, y, m_hIcon);
- }
- else
- {
- CDialog::OnPaint();
- }
- }
-
- // The system calls this to obtain the cursor to display while the user drags
- // the minimized window.
- HCURSOR CMaskDlg::OnQueryDragIcon()
- {
- return (HCURSOR) m_hIcon;
- }
-
- BEGIN_EVENTSINK_MAP(CMaskDlg, CDialog)
- //{{AFX_EVENTSINK_MAP(CMaskDlg)
- ON_EVENT(CMaskDlg, IDC_MASKEDIT1, -604 /* KeyUp */, OnKeyUpMaskedit1, VTS_PI2 VTS_I2)
- ON_EVENT(CMaskDlg, IDC_MASKEDIT2, -604 /* KeyUp */, OnKeyUpMaskedit2, VTS_PI2 VTS_I2)
- ON_EVENT(CMaskDlg, IDC_MASKEDIT3, -604 /* KeyUp */, OnKeyUpMaskedit3, VTS_PI2 VTS_I2)
- ON_EVENT(CMaskDlg, IDC_MASKEDIT4, -604 /* KeyUp */, OnKeyUpMaskedit4, VTS_PI2 VTS_I2)
- //}}AFX_EVENTSINK_MAP
- END_EVENTSINK_MAP()
-
- void CMaskDlg::OnKeyUpMaskedit1(short FAR* KeyCode, short Shift)
- {
- CMaskEdit *pMask = (CMaskEdit*)GetDlgItem(IDC_MASKEDIT2);
- pMask->SetTextWithMask((LPCTSTR)((CMaskEdit*)GetDlgItem(IDC_MASKEDIT1))->GetTextWithMask());
- }
-
- void CMaskDlg::OnKeyUpMaskedit2(short FAR* KeyCode, short Shift)
- {
- CMaskEdit *pMask = (CMaskEdit*)GetDlgItem(IDC_MASKEDIT1);
- pMask->SetTextWithMask(((CMaskEdit*)GetDlgItem(IDC_MASKEDIT2))->GetTextWithMask());
- }
-
- void CMaskDlg::OnKeyUpMaskedit3(short FAR* KeyCode, short Shift)
- {
- CMaskEdit *pMask = (CMaskEdit*)GetDlgItem(IDC_MASKEDIT4);
- pMask->SetText(((CMaskEdit*)GetDlgItem(IDC_MASKEDIT3))->GetText());
- }
-
- void CMaskDlg::OnKeyUpMaskedit4(short FAR* KeyCode, short Shift)
- {
- CMaskEdit *pMask = (CMaskEdit*)GetDlgItem(IDC_MASKEDIT3);
- CString str;
- GetDlgItemText(IDC_MASKEDIT4, str);
- pMask->SetText(str);
- }
-
- void CMaskDlg::OnSetmasktext()
- {
- CMaskEdit *pTarget = (CMaskEdit*)GetDlgItem(IDC_TARGET);
- CString str;
- GetDlgItemText(IDC_MASK, str);
- pTarget->SetMask(str);
- GetDlgItemText(IDC_TEXT, str);
- pTarget->SetText(str);
- }
-
- void CMaskDlg::OnSelchangeBackcolor()
- {
- CMaskEdit *pME = (CMaskEdit*)GetDlgItem(IDC_MASKEDIT);
- CComboBox *pColor = (CComboBox*)GetDlgItem(IDC_BACKCOLOR);
- pME->SetBackColor(GetColor(pColor->GetCurSel()));
- }
-
- void CMaskDlg::OnSelchangeDisplay()
- {
- CMaskEdit *pME = (CMaskEdit*)GetDlgItem(IDC_MASKEDIT);
- CComboBox *pDisplay = (CComboBox*)GetDlgItem(IDC_DISPLAY);
- pME->SetDisplayFormat(pDisplay->GetCurSel());
- //--------------------------------------------------
- // restore initial size of control window
- pME->SetWindowPos(&wndTop, 0, 0, m_iWidth, m_iHeight,
- SWP_NOMOVE | SWP_NOZORDER);
- //--------------------------------------------------
- // set selected colors
- OnSelchangeHighlightcolor();
- OnSelchangeForecolor();
- OnSelchangeBackcolor();
- }
-
- void CMaskDlg::OnSelchangeForecolor()
- {
- CMaskEdit *pME = (CMaskEdit*)GetDlgItem(IDC_MASKEDIT);
- CComboBox *pColor = (CComboBox*)GetDlgItem(IDC_FORECOLOR);
- pME->SetForeColor(GetColor(pColor->GetCurSel()));
- }
-
- void CMaskDlg::OnSelchangeHighlightcolor()
- {
- CMaskEdit *pME = (CMaskEdit*)GetDlgItem(IDC_MASKEDIT);
- CComboBox *pColor = (CComboBox*)GetDlgItem(IDC_HIGHLIGHTCOLOR);
- pME->SetHighlightColor(GetColor(pColor->GetCurSel()));
- }
-
- void CMaskDlg::OnInverted()
- {
- CMaskEdit *pME = (CMaskEdit*)GetDlgItem(IDC_MASKEDIT);
- pME->SetHighlightInverted(((CButton*)GetDlgItem(IDC_INVERTED))->GetCheck());
- }
-
- void CMaskDlg::OnFlat()
- {
- CMaskEdit *pME = (CMaskEdit*)GetDlgItem(IDC_MASKEDIT);
- if(((CButton*)GetDlgItem(IDC_FLAT))->GetCheck())
- pME->SetAppearance(0);
- else
- pME->SetAppearance(1);
- }
-
- COLORREF CMaskDlg::GetColor(int id)
- {
- switch(id)
- {
- case 0: return 0x02ffffff;
- case 1: return 0x02c0c0c0;
- case 2: return 0x02808080;
- case 3: return 0x02ffff00;
- case 4: return 0x02ff0000;
- case 5: return 0x0200ff00;
- case 6: return 0x02008000;
- case 7: return 0x0200ffff;
- case 8: return 0x020000ff;
- case 9: return 0x02ff00ff;
- case 10: return 0x02000080;
- case 11: return 0x02000000;
- }
- return 0x02000000;
- }
-
- void CMaskDlg::OnBorder()
- {
- CMaskEdit *pME = (CMaskEdit*)GetDlgItem(IDC_MASKEDIT);
- if(((CButton*)GetDlgItem(IDC_BORDER))->GetCheck())
- pME->SetBorderStyle(1);
- else
- pME->SetBorderStyle(0);
- }
-