|
|
Click here to download this example (a zip file containing project workspace and source files, 32,3 kb).
- Step 0: Make sure that the "Digital 7 Segments Display ActiveX Control Module"
is registered. To do that, follow the instructions in the FAQ section.
- Step 1: Open Visual C++ 6.0; from the "File" menu select "New",
then in the dialog window that appears (figure below), select "MFC AppWizard (exe)" and
fill in the "Project name" with a name of your choice, for example "SampleWatch".
Press OK.

- Step 2: In the "AppWizard - Step 1" dialog, select "Dialog based" and press "Next".

- Step 3: In the "AppWizard - Step 1" dialog, make sure that the "ActiveX Controls"
checkbox is activated. Freely customize the other parameters, then press "Next".
Just press "Next" and "Finish" in the following two dialog windows.

- Step 4: From the "Project" menu, select "Add to Project" and then "Component and controls...".
The "Components and Controls Gallery" dialog window appear (figure below): double click
"Registered ActiveX Controls", then find and click "Precision Digital 7 Segments Display",
then press "Insert". Confirm the next two dialogs (not depicted here) by pressing "OK".
Then close the "Components and Controls Gallery" dialog.

- Step 5:
In the Workspace docked window on the left, in the "Resources" tab, open the dialog resource
"IDD_SAMPLEWATCH_DIALOG" by double-clicking its name, then select the icon indicated by the
right arrow (figure below), which correspons to Digital 7 Segments Display, in
the "Controls" window.
Please note that this tool window is "floating" in the figure, but it could be also docked
in the form of a toolbar or missing, in the last case right-click on the menu bar and
check "Controls" in the context menu that appears.

- Step 6: The cursor will take the form of a cross-hair: lay out the new control on
the window by selecting a rectangle. Dispose of the "TODO:..." static text and of the "OK"
button by clicking them and pressing the "Del" key.
Your window should now resemble the following figure.

- Step 7: Now invoke ClassWizard by pressing "CTRL+W" or selecting it in the "View" menu.
Select the "Member Variables" tab, click on identifier "IDC_DIGITAL7SEGMENTSDISPLAYCTRL1" and
on "Add Variable". A new window appears, fill in the "member variable name" field with a
suitable name like "m_control", then click "OK".

- Step 8: Now go to the "Message Maps" tab of ClassWizard.
Select the object "CSampleWatchDlg", then the message "WM_TIMER", then
the "Add Function" button. You can now close ClassWizard.

- Step 9: Let's write some code now.
To proceed through this step you will need a valid licence number.
If you will not call SetLicense providing a valid license number to the component,
it will simply fail to show at runtime.
Locate the following method: CSampleWatchDlg::OnInitDialog(), it should contain
a comment like the following:
// TODO: Add extra initialization here
After this comment add the following two lines:
SetTimer(0,1000,NULL);
m_control.SetLicense( <put here your license number> );
Now locate the following method: void CSampleWatchDlg::OnTimer(UINT nIDEvent),
it should contain a comment like the following:
// TODO: Add your message handler code here and/or call default
After this comment add the following three lines:
CTime time = CTime::GetCurrentTime();
CString strTemp = time.Format("%H:%M:%S");
m_control.SetDisplayedString(strTemp);
- Step 10: Finished! Simply run your program by pressing F5 to see your new digital clock running!

|