Visual C++ and MFC Fundamentals Chapter 18: Progress-Based Controls
Here is how we will design the dialog box:
- Add a Group Box control to the dialog box and set its Caption to Elapsed Time
- 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 - 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 - Add a Value Variable for the IDC_COMP_TIME identifier and name it
m_CompTime - Add a Value Variable for the IDC_COMP_TIME identifier and name it
m_AppTime - In the header file of the dialog box, declare an unsigned integer as follows:
public:
CString m_CompTime;
CString m_AppTime;
unsigned int CompTime;
};
- 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