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

1.1     ! root        1: // muscroll.cpp : New control example - MicroScroller
        !             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: #include "paredit.h"
        !            16: #include "spin.h"
        !            17: 
        !            18: /////////////////////////////////////////////////////////////////////////////
        !            19: // Example of a dialog with special controls in it
        !            20: 
        !            21: #define NUM_EDIT        4
        !            22: #define IDC_EDIT_MIN    IDC_EDIT1
        !            23: #define IDC_BUTTON_MIN  IDC_BUTTON1
        !            24:        // IDC_EDIT1->IDC_EDIT4 and IDC_BUTTON1->IDC_BUTTON4 must be contiguous
        !            25: 
        !            26: class CSpinEditDlg : public CModalDialog
        !            27: {
        !            28: protected:
        !            29:        CParsedEdit edit[NUM_EDIT];
        !            30: public:
        !            31:        CSpinEditDlg()
        !            32:                : CModalDialog(IDD_SPIN_EDIT)
        !            33:                        { }
        !            34: 
        !            35:        BOOL OnInitDialog();
        !            36:        void OnOK();
        !            37: };
        !            38: 
        !            39: BOOL CSpinEditDlg::OnInitDialog()
        !            40: {
        !            41:        int value = 1;
        !            42:        for (int i = 0; i < NUM_EDIT; i++)
        !            43:        {
        !            44:                UINT nID = IDC_EDIT_MIN + i;
        !            45:                edit[i].SubclassEdit(nID, this, PES_NUMBERS);
        !            46:                SetDlgItemInt(nID, value);
        !            47:                value++;        // 1, 2, 3, 4
        !            48: 
        !            49:                // associate button with edit item
        !            50:                CSpinControl* pSpin = (CSpinControl*)GetDlgItem(IDC_BUTTON_MIN + i);
        !            51:                ASSERT(pSpin != NULL);
        !            52:                        pSpin->SetAssociate(&edit[i]);
        !            53:        }
        !            54:        return TRUE;
        !            55: }
        !            56: 
        !            57: void CSpinEditDlg::OnOK()
        !            58: {
        !            59:        int values[NUM_EDIT];
        !            60:        UINT nID;
        !            61:        BOOL bOk = TRUE;
        !            62:        for (int i = 0; bOk && i < NUM_EDIT; i++)
        !            63:        {
        !            64:                nID = IDC_EDIT_MIN + i;
        !            65:                values[i] = GetDlgItemInt(nID, &bOk);
        !            66:        }
        !            67: 
        !            68:        if (!bOk)
        !            69:        {
        !            70:                // report illegal value
        !            71:                MessageBox("illegal value\n");
        !            72:                CEdit& badEdit = *(CEdit*)GetDlgItem(nID);
        !            73:                badEdit.SetSel(0, -1);
        !            74:                badEdit.SetFocus();
        !            75:                return;     // don't end dialog
        !            76:        }
        !            77: 
        !            78: #ifdef _DEBUG
        !            79:        // dump results, normally you would do something with these
        !            80:        TRACE("Final values:\n");
        !            81:        for (i = 0; i < NUM_EDIT; i++)
        !            82:                TRACE("\t%d\n", values[i]);
        !            83: #endif
        !            84:        EndDialog(IDOK);
        !            85: }
        !            86: 
        !            87: /////////////////////////////////////////////////////////////////////////////
        !            88: // Run the test
        !            89: 
        !            90: void CTestWindow::OnTestSpinEdit()
        !            91: {
        !            92: #ifdef _NTWIN
        !            93:        // Use of 16 bit DLLs from a 32 bit app is not currently supported 
        !            94:        GetMenu()->EnableMenuItem(IDM_TEST_SPIN_EDIT, MF_DISABLED|MF_GRAYED);
        !            95:        MessageBox("Feature not supported on Windows NT");
        !            96: #else
        !            97:        HINSTANCE hLibrary;
        !            98:        if ((hLibrary = LoadLibrary("MUSCROLL.DLL")) < HINSTANCE_ERROR)
        !            99:        {
        !           100:                MessageBox("Can not do this test without custom control library");
        !           101: 
        !           102:                // prevent it from happening again
        !           103:                GetMenu()->EnableMenuItem(IDM_TEST_SPIN_EDIT, MF_DISABLED|MF_GRAYED);
        !           104:                return;
        !           105:        }
        !           106: 
        !           107:        TRACE("running dialog with spin controls in it\n");
        !           108:        CSpinEditDlg dlg;
        !           109:        dlg.DoModal();
        !           110: 
        !           111:        FreeLibrary(hLibrary);
        !           112: #endif
        !           113: }
        !           114: 
        !           115: 
        !           116: /////////////////////////////////////////////////////////////////////////////

unix.superglobalmegacorp.com

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