Annotation of mstools/mfc/samples/ctrltest/featpen.cpp, revision 1.1.1.1

1.1       root        1: // featpen.cpp : pen HEdit features
                      2: //
                      3: // This is a part of the Microsoft Foundation Classes C++ library.
                      4: // Copyright (C) 1992 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 Microsoft
                      9: // QuickHelp documentation provided with the library.
                     10: // See these sources for detailed information regarding the
                     11: // Microsoft Foundation Classes product.
                     12: 
                     13: #include "ctrltest.h"
                     14: 
                     15: // we need the MFC extensions for PenWindows
                     16: #include <afxpen.h>
                     17: // we also use the MFC common dialogs for color picker
                     18: #include <afxdlgs.h>
                     19: 
                     20: /////////////////////////////////////////////////////////////////////////////
                     21: 
                     22: class CPenFeatureDlg : public CModalDialog
                     23: {
                     24: public:
                     25:        CPenFeatureDlg()
                     26:                : CModalDialog(IDD_PENEDIT_FEATURES)
                     27:                { }
                     28: 
                     29:        // just 1 HEdit to play with
                     30:        CHEdit& Edit1()
                     31:                                { return *(CHEdit*)GetDlgItem(IDC_EDIT1); }
                     32: 
                     33: // Implementation
                     34: protected:
                     35:        BOOL OnInitDialog();
                     36:        void OnOK();
                     37:        void OnConfigure();
                     38:        DECLARE_MESSAGE_MAP();
                     39: };
                     40: 
                     41: BEGIN_MESSAGE_MAP(CPenFeatureDlg, CModalDialog)
                     42:        ON_COMMAND(IDC_CONFIGURE, OnConfigure)
                     43: END_MESSAGE_MAP()
                     44: 
                     45: /////////////////////////////////////////////////////////////////////////////
                     46: 
                     47: BOOL CPenFeatureDlg::OnInitDialog()
                     48: {
                     49:        // nothing special to do
                     50:        return TRUE;
                     51: }
                     52: 
                     53: void CPenFeatureDlg::OnOK()
                     54: {
                     55: #ifdef _DEBUG
                     56:        // dump results, normally you would do something with these
                     57:        CString s;
                     58:        Edit1().GetWindowText(s);
                     59:        TRACE("edit1 = '%s'\n", (const char*) s);
                     60: #endif
                     61: 
                     62:        EndDialog(IDOK);
                     63: }
                     64: 
                     65: /////////////////////////////////////////////////////////////////////////////
                     66: // Run the test
                     67: 
                     68: void CTestWindow::OnTestPenEditFeatures()
                     69: {
                     70:        TRACE("running HEdit feature test dialog\n");
                     71:        CPenFeatureDlg dlg;
                     72:        dlg.DoModal();
                     73: }
                     74: 
                     75: 
                     76: /////////////////////////////////////////////////////////////////////////////
                     77: // Configure the HEdit edit item
                     78:        // (note: local changes only)
                     79: 
                     80: // Dialog used for the configure option
                     81: class CConfigureHEditDlg : public CModalDialog
                     82: {
                     83: protected:
                     84:        CHEdit&     m_rHEdit;       // reference to Edit item to configure
                     85:        COLORREF    m_inkColor;     // for color picker
                     86: 
                     87: public:
                     88:        CConfigureHEditDlg(CHEdit& rHEdit, CWnd* pParent = NULL)
                     89:                : CModalDialog(IDD_PENEDIT_CONFIGURE, pParent),
                     90:                        m_rHEdit(rHEdit)
                     91:                { }
                     92: 
                     93: // Implementation
                     94: protected:
                     95:        BOOL OnInitDialog();
                     96:        void OnOK();
                     97:        void OnChooseInkColor();
                     98:        DECLARE_MESSAGE_MAP();
                     99: };
                    100: 
                    101: BEGIN_MESSAGE_MAP(CConfigureHEditDlg, CModalDialog)
                    102:        ON_COMMAND(IDC_BUTTON2, OnChooseInkColor)
                    103: END_MESSAGE_MAP()
                    104: 
                    105: BOOL CConfigureHEditDlg::OnInitDialog()
                    106: {
                    107:        // fill in initial values
                    108:        RC rcInfo;
                    109:        VERIFY(m_rHEdit.GetRC(&rcInfo));            // get current settings
                    110: 
                    111:        // set the ALC bits (max of 32 of them, 1 checkbox each)
                    112:        TRACE("initial ALC = 0x%lx\n", rcInfo.alc);
                    113:        for (int i = 0; i < 32; i++)
                    114:        {
                    115:                if (rcInfo.alc & (1L<<i))
                    116:                        CheckDlgButton(IDC_ALC_FIRST+i, TRUE);
                    117:                                // check control if there is one
                    118:        }
                    119: 
                    120:        // set LeftHanded
                    121:        if (rcInfo.wRcPreferences & RCP_LEFTHAND)
                    122:                CheckDlgButton(IDC_BUTTON1, TRUE);
                    123: 
                    124:        // set ink info
                    125:        SetDlgItemInt(IDC_EDIT1, rcInfo.nInkWidth);
                    126:        m_inkColor = rcInfo.rgbInk;
                    127:        return TRUE;
                    128: }
                    129: 
                    130: void CConfigureHEditDlg::OnOK()
                    131: {
                    132:        // get info from dialog, update fields of RC as appropriate
                    133:        RC rcInfo;
                    134:        VERIFY(m_rHEdit.GetRC(&rcInfo));            // get current settings
                    135: 
                    136:        for (int i = 0; i < 32; i++)
                    137:        {
                    138:                CButton* pButton = (CButton*)GetDlgItem(IDC_ALC_FIRST + i);
                    139:                if (pButton != NULL)
                    140:                {
                    141:                        // set bit depending on checkbox content
                    142:                        if (pButton->GetCheck())
                    143:                                rcInfo.alc |= (1L << i);
                    144:                        else
                    145:                                rcInfo.alc &= ~(1L << i);
                    146:                }
                    147:        }
                    148:        TRACE("final ALC = 0x%lx\n", rcInfo.alc);
                    149: 
                    150:        if (IsDlgButtonChecked(IDC_BUTTON1))
                    151:                rcInfo.wRcPreferences |= RCP_LEFTHAND;
                    152:        else
                    153:                rcInfo.wRcPreferences &= ~RCP_LEFTHAND;
                    154: 
                    155:        BOOL bOk;
                    156:        rcInfo.nInkWidth = GetDlgItemInt(IDC_EDIT1, &bOk);
                    157:        if (!bOk || rcInfo.nInkWidth < -1 || rcInfo.nInkWidth > 15)
                    158:        {
                    159:                MessageBox("Illegal Ink Width (-1 .. 15 permitted)");
                    160:                CEdit* pEdit = (CEdit*)GetDlgItem(IDC_EDIT1);
                    161:                pEdit->SetSel(0, -1);
                    162:                pEdit->SetFocus();
                    163:                return;
                    164:        }
                    165:        rcInfo.rgbInk = m_inkColor;
                    166: 
                    167:        // set the final values
                    168:        VERIFY(m_rHEdit.SetRC(&rcInfo));
                    169:        EndDialog(IDOK);
                    170: }
                    171: 
                    172: void CConfigureHEditDlg::OnChooseInkColor()
                    173: {
                    174:        DWORD dwFlags = CC_PREVENTFULLOPEN;
                    175:        COLORREF crPrompt = (m_inkColor != RC_LDEFAULT) ? m_inkColor : 0;
                    176:                // default to 0 (black) for default color
                    177: 
                    178:        CColorDialog dlg(CC_PREVENTFULLOPEN, crPrompt, this);
                    179:        if (dlg.DoModal() == IDOK)
                    180:                m_inkColor = dlg.GetColor();
                    181: }
                    182: 
                    183: void CPenFeatureDlg::OnConfigure()
                    184: {
                    185:        CConfigureHEditDlg dlg(Edit1(), this);
                    186:        dlg.DoModal();
                    187: }
                    188: 
                    189: /////////////////////////////////////////////////////////////////////////////

unix.superglobalmegacorp.com

This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.