Annotation of mstools/mfc/samples/ctrltest/derpen.cpp, revision 1.1

1.1     ! root        1: // derpen.cpp : C++ derived HEdit/BEdit control example
        !             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: 
        !            18: /////////////////////////////////////////////////////////////////////////////
        !            19: 
        !            20: class CDerPenEditDlg : public CModalDialog
        !            21: {
        !            22: protected:
        !            23:        // 2 Handwriting edit items
        !            24:        CHEdit edit1, edit2;
        !            25:        // 2 Boxed Handwriting edit items
        !            26:        CBEdit edit3, edit4;
        !            27:        // static labels for them all
        !            28:        CStatic static1, static2, static3, static4;
        !            29: 
        !            30:        // font for the dialog
        !            31:        CFont*  m_pFont;
        !            32: public:
        !            33:        CDerPenEditDlg()
        !            34:                : CModalDialog(IDD_DERIVED_EDIT)
        !            35:                { }
        !            36: 
        !            37:        BOOL OnInitDialog();
        !            38:        void OnSetFont(CFont* pFont)
        !            39:                        { m_pFont = pFont; }
        !            40:        void OnOK();
        !            41: };
        !            42: 
        !            43: /////////////////////////////////////////////////////////////////////////////
        !            44: // pen helpers
        !            45: 
        !            46: void SetAlc(CHEdit& rHEdit, ALC alcNew)
        !            47: {
        !            48:        RC rc;      // recognition context
        !            49:        VERIFY(rHEdit.GetRC(&rc));
        !            50:        rc.alc = alcNew;
        !            51:        VERIFY(rHEdit.SetRC(&rc));
        !            52: }
        !            53: 
        !            54: /////////////////////////////////////////////////////////////////////////////
        !            55: 
        !            56: BOOL CDerPenEditDlg::OnInitDialog()
        !            57: {
        !            58:        // This is an example of the _incorrect_ way to create a dialog
        !            59:        // see other comments in DERTEST.CPP
        !            60:        const int yStart = 8;
        !            61:        const int height = 36;
        !            62: 
        !            63:        CPoint whereLabel(10, yStart + 4);
        !            64:        CSize sizeLabel(80, 24);
        !            65: 
        !            66:        CPoint whereEdit(90, yStart);
        !            67:        CSize sizeEdit(140, 30);
        !            68: 
        !            69:        static1.Create("Letters:", WS_VISIBLE | WS_CHILD | SS_LEFT,
        !            70:                CRect(whereLabel, sizeLabel), this, -1);
        !            71:        static1.SetFont(m_pFont);
        !            72:        whereLabel.y += height;
        !            73:        edit1.Create(WS_VISIBLE | WS_CHILD | WS_TABSTOP | WS_BORDER,
        !            74:                CRect(whereEdit, sizeEdit), this, IDC_EDIT1);
        !            75:        edit1.SetFont(m_pFont);
        !            76:        SetAlc(edit1, ALC_ALPHA);
        !            77:        whereEdit.y += height;
        !            78: 
        !            79:        static2.Create("Numbers:", WS_VISIBLE | WS_CHILD | SS_LEFT,
        !            80:                CRect(whereLabel, sizeLabel), this, -1);
        !            81:        static2.SetFont(m_pFont);
        !            82:        whereLabel.y += height;
        !            83:        edit2.Create(WS_VISIBLE | WS_CHILD | WS_TABSTOP | WS_BORDER,
        !            84:                CRect(whereEdit, sizeEdit), this, IDC_EDIT2);
        !            85:        edit2.SetFont(m_pFont);
        !            86:        SetAlc(edit2, ALC_NUMERIC);
        !            87:        whereEdit.y += height;
        !            88: 
        !            89:        // followed by 2 boxed edit items
        !            90:        static3.Create("Letters:", WS_VISIBLE | WS_CHILD | SS_LEFT,
        !            91:                CRect(whereLabel, sizeLabel), this, -1);
        !            92:        static3.SetFont(m_pFont);
        !            93:        whereLabel.y += height;
        !            94:        edit3.Create(WS_VISIBLE | WS_CHILD | WS_TABSTOP | WS_BORDER,
        !            95:                CRect(whereEdit, sizeEdit), this, IDC_EDIT3);
        !            96:        edit3.SetFont(m_pFont);
        !            97:        SetAlc(edit3, ALC_ALPHA);
        !            98:        whereEdit.y += height;
        !            99: 
        !           100:        static4.Create("Numbers:", WS_VISIBLE | WS_CHILD | SS_LEFT,
        !           101:                CRect(whereLabel, sizeLabel), this, -1);
        !           102:        whereLabel.y += height;
        !           103:        static4.SetFont(m_pFont);
        !           104:        edit4.Create(WS_VISIBLE | WS_CHILD | WS_TABSTOP | WS_BORDER,
        !           105:                CRect(whereEdit, sizeEdit), this, IDC_EDIT4);
        !           106:        edit4.SetFont(m_pFont);
        !           107:        SetAlc(edit4, ALC_NUMERIC);
        !           108:        whereEdit.y += height;
        !           109: 
        !           110:        // change the dialog height so everything fits
        !           111:        int yBottom = whereEdit.y + height * 2; // extra space
        !           112:        CRect rect;
        !           113:        GetWindowRect(rect);
        !           114:        VERIFY(SetWindowPos(NULL, -1, -1, rect.Width(), yBottom,
        !           115:                SWP_NOMOVE|SWP_NOZORDER|SWP_NOREDRAW|SWP_NOACTIVATE));
        !           116: 
        !           117:        // set focus to first one
        !           118:        edit1.SetFocus();
        !           119:        return FALSE;   // focus set
        !           120: }
        !           121: 
        !           122: void CDerPenEditDlg::OnOK()
        !           123: {
        !           124: #ifdef _DEBUG
        !           125:        // dump results, normally you would do something with these
        !           126:        CString s;
        !           127:        edit1.GetWindowText(s);
        !           128:        TRACE("edit1 = '%s'\n", (const char*) s);
        !           129:        edit2.GetWindowText(s);
        !           130:        TRACE("edit2 = '%s'\n", (const char*) s);
        !           131:        edit3.GetWindowText(s);
        !           132:        TRACE("edit3 = '%s'\n", (const char*) s);
        !           133:        edit4.GetWindowText(s);
        !           134:        TRACE("edit4 = '%s'\n", (const char*) s);
        !           135: #endif
        !           136: 
        !           137:        EndDialog(IDOK);
        !           138: }
        !           139: 
        !           140: /////////////////////////////////////////////////////////////////////////////
        !           141: // Run the test
        !           142: 
        !           143: void CTestWindow::OnTestPenEditFromCode()
        !           144: {
        !           145:        TRACE("running dialog containing CBEdit objects\n");
        !           146:        CDerPenEditDlg dlg;
        !           147:        dlg.DoModal();
        !           148: }
        !           149: 
        !           150: 
        !           151: /////////////////////////////////////////////////////////////////////////////

unix.superglobalmegacorp.com

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