Visual C++ and MFC Programming 2nd Edition

(Martin Jones) #1

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


Accept the suggested name of the function and click OK. Then click Edit Code...
If you are using MSVC 7, click the most left spin button on the dialog box and, on

the Properties window, click the Controls Events button. Click the arrow of the
UDN_DELTAPOS combo box and select the only item in the list


  1. Implement the event as follows:


void CColorPreviewDlg::OnDeltaposSpinRed(NMHDR *pNMHDR, LRESULT *pResult)
{
LPNMUPDOWN pNMUpDown = reinterpret_cast<LPNMUPDOWN>(pNMHDR);
// TODO: Add your control notification handler code here
int RColor = m_SpinRed.GetPos();
int GColor = m_SpinGreen.GetPos();
int BColor = m_SpinBlue.GetPos();

PreviewColor = RGB(RColor, GColor, BColor);
UpdatePreview();

*pResult = 0;
}


  1. In the same way, add the UDN_DELTAPOS event of the IDC_SPIN_GREEN and
    the IDC_SPIN_BLUE controls and implement them as follows:


void CColorPreviewDlg::OnDeltaposSpinGreen(NMHDR *pNMHDR, LRESULT *pResult)
{
LPNMUPDOWN pNMUpDown = reinterpret_cast<LPNMUPDOWN>(pNMHDR);
// TODO: Add your control notification handler code here
int RColor = m_SpinRed.GetPos();
int GColor = m_SpinGreen.GetPos();
int BColor = m_SpinBlue.GetPos();

PreviewColor = RGB(RColor, GColor, BColor);
UpdatePreview();

*pResult = 0;
}

void CColorPreviewDlg::OnDeltaposSpinBlue(NMHDR *pNMHDR, LRESULT *pResult)
{
LPNMUPDOWN pNMUpDown = reinterpret_cast<LPNMUPDOWN>(pNMHDR);
// TODO: Add your control notification handler code here
int RColor = m_SpinRed.GetPos();
int GColor = m_SpinGreen.GetPos();
int BColor = m_SpinBlue.GetPos();

PreviewColor = RGB(RColor, GColor, BColor);
UpdatePreview();

*pResult = 0;
}


  1. Test the application:

Free download pdf