Visual C++ and MFC Programming 2nd Edition

(Martin Jones) #1

Visual C++ and MFC Fundamentals Chapter 15: Fundamental Controls



  1. Set the Class name of the bottom custom control to Static and change its Caption to
    Burkina Faso

  2. Add a CScrollBar Control Variable to the top control and name it m_ScrollRed (if
    you are using some versions of MSVC 7 and the class name is not selected as
    CScrollBar, you may have to type it; if you are using MSVC 6, you should only
    select the class name as CScrollBar)

  3. Add a CScrollBar Control Variable to the second control from top and name it
    m_ScrollGreen

  4. Add a CScrollBar Control Variable to the third control from top and name it
    m_ScrollBlue

  5. A CStatic Control Variable (if you are using some versions of MSVC 7 and the
    class name is not selected as CStatic, you can to type it; if you are using MSVC 6,
    you should select the CStatic class name) to the bottom control and name it
    m_Country

  6. To change the identifiers of the top three controls, access the OnInitDialog() event
    of the dialog box and call the SetDlgCtrlID() method for each control giving the
    1804 , 6255 , and 42 values respectively:


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

// Set the icon for this dialog. The framework does this automatically
// when the application's main window is not a dialog
SetIcon(m_hIcon, TRUE); // Set big icon
SetIcon(m_hIcon, FALSE); // Set small icon

// TODO: Add extra initialization here
m_ScrollRed.SetDlgCtrlID(1804);
m_ScrollGreen.SetDlgCtrlID(6255);
m_ScrollBlue.SetDlgCtrlID(42);

return TRUE; // return TRUE unless you set the focus to a control
}


  1. When the user clicks one of the scroll bars, we will need to know which one was
    clicked and display a message accordingly


Using the Messages button , generate the WM_HSCROLL message for the
dialog box to <Add> an OnHScroll event.


  1. Implement it as follows:


void CIdentificationDlg::OnHScroll(UINT nSBCode, UINT nPos, CScrollBar* pScrollBar)
{
// TODO: Add your message handler code here and/or call default
CFont font;

// Change the font of the label based on which scroll bar was clicked
if( pScrollBar->GetDlgCtrlID() == 1804 )
{
font.CreatePointFont(260, "Garamond");
m_Country.SetFont(&font);
}
else if( pScrollBar->GetDlgCtrlID() == 6255 )
{
font.CreatePointFont(220, "Arial");
m_Country.SetFont(&font);
Free download pdf