MFC Step-by-Step Guide

Tutorial 5

Input/Output GUI Elements


GOAL: Work and gain experience using GUI elements that serve as both input and output from the application and user
PREREQUISITES: Tutorial 4

Create Check Box
  1. Drag a Check Box to the dialog window, inside the Properties window, change
    1. ID to "IDC_TIMER_CONTROL_SLIDERS"
    2. Caption to "Timer Control Sliders"
    3. Auto to True
  2. Add an output Control Variable to the "Timer Control Sliders" text box, with
    1. Access to private
    2. Category to Value
    3. Variable Name to "m_TimerCtrlSliders"
    4. Variable Type to BOOL
  3. In 'TutorialDlg.cpp', initialize the boolean inside the OnInitDialog() function:
    BOOL CTutorialDlg::OnInitDialog(){
       ...
       m_TimerCtrlSliders = TRUE;
       UpdateData(FALSE);
    }
  4. Add Event Handler to the "Timer Control Sliders" check box, change
    1. Message Type to BN_CLICKED
    2. Class List to CTutorialDlg
    3. Function Handler Name to OnBnClickedTimerControlSliders
    4. Click Add and Edit
  5. In 'TutorialDlg.cpp', inside OnBnClickedTimerControlSliders(), add
    void CTutorialDlg::OnBnClickedTimerControlSliders(){
       UpdateData(TRUE);
       // This will fill all UI-connected variables with whatever
       // value that is showing on the UI control objects.
    }
Service Slider and Timer updates
  1. In 'TutorialDlg.cpp', inside OnTimer(...), add
    ...
    if (m_TimerCtrlSliders){
       // Get ready to decrease the sliders ...
       int hvalue = m_HSliderBar.GetPos();
       if (hvalue > 0){
         m_HSliderBar.SetPos(hvalue-1);
         m_HSliderEcho.Format("%d", hvalue-1);
       }
       // do the same for the vertical slider
       int vvalue = m_VSliderBar.GetPos();
       ...
       if ( (hvalue==0) && (vvalue==0) ){
         m_TimerCtrlSliders = false;
       }
       ...
    }


» Written by William Frankhouser (wjf2@washington.edu)
» Advised by Kelvin Sung (ksung@washington.edu) as part of the project sponsored by the National Science Foundation under Grant No. 0442420. Any opinions, findings, and conclusions or recommendations expressed in this material are those of the author(s) and do not necessarily reflect the views of the National Science Foundation.
» Produced in the "Essential Concepts for Building Interactive Computer Graphics Applications", A.K. Peters, Ltd.