Visual C++ and MFC Programming 2nd Edition

(Martin Jones) #1

Visual C++ and MFC Fundamentals Chapter 17: Track-Based Controls


BOOL CSpinDlg::OnInitDialog()
{
CDialog::OnInitDialog();

// TODO: Add extra initialization here
CSpinButtonCtrl *SpinCtrl = new CSpinButtonCtrl;

SpinCtrl->Create(WS_CHILD | WS_VISIBLE, CRect(60, 10, 80, 35), this, 0x128);

return TRUE; // return TRUE unless you set the focus to a control
// EXCEPTION: OCX Property Pages should return FALSE
}

Practical Learning: Creating Spin Buttons


Here is the dialog box as we will design it:


  1. On the Controls toolbox, click the Edit Box button and click under the picture
    control and on the left side of the dialog box

  2. On the Control toolbox, click the Spin button and click to the right side of the
    IDC_EDIT1 control on the dialog box

  3. While the spin button is still selected, press and hold Ctrl. Click the previously added
    edit box and release Ctrl

  4. Press Ctrl + C to copy and press Ctrl + V to paste

  5. Move the newly two pasted controls to the right

  6. Press Ctrl + V to paste again and move the new controls to the right side of the
    others

  7. Using the properties window, change the identifiers of the controls, from left to right,
    to IDC_EDIT_RED, IDC_SPIN_RED, IDC_EDIT_GREEN,
    IDC_SPIN_GREEN, IDC_EDIT_BLUE, and IDC_SPIN_BLUE

Free download pdf