Visual C++ and MFC Programming 2nd Edition

(Martin Jones) #1

Visual C++ and MFC Fundamentals Chapter 18: Progress-Based Controls


Here is how we will design the dialog box:


  1. Add a Group Box control to the dialog box and set its Caption to Elapsed Time

  2. Add a long Static Text control to the group box. Change its ID to
    IDC_COMP_TIME and its Caption to
    This computer has been ON for XXXXXXXXXXXXXXXXXXXXX

  3. Add another Static Text control to the group box. Change its ID to IDC_APP_TIME
    and its Caption to
    This application has been running for XXXXXXXXXXXXXXXXXXXX

  4. Add a Value Variable for the IDC_COMP_TIME identifier and name it
    m_CompTime

  5. Add a Value Variable for the IDC_COMP_TIME identifier and name it
    m_AppTime

  6. In the header file of the dialog box, declare an unsigned integer as follows:


public:
CString m_CompTime;
CString m_AppTime;
unsigned int CompTime;
};


  1. To create a timer control, in the OnInitDialog() event, call the SetTimer() method
    and initialize the CompTime variable as follows:


BOOL CTickCounterDlg::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
Free download pdf