|
Add some C++ Code to your Project
Now we'll begin adding some code to our project.
First we need to add member variables for our controls. Right click on the 'Symbol Factory Standard
Control Pump Symbol' and click 'ClassWizard' as shown below.
This brings up the 'MFC ClassWizard' dialog. Click on the 'Member Variables'
tab and highlight 'IDC_STDCTRL1'. Now click on the 'Add Variable' button to add a member variable for the control. Type 'm_StdCtrl1' in the 'Member variable name'
edit box and click 'OK' as shown below.
Similarly add member variables for 'IDC_STDCTRL3', 'IDC_CUTAWAYCTRL1'
and 'IDC_EDIT1'. Make sure you set the 'IDC_EDIT1' variable type to 'double' because the 'Symbol Factory Cutaway Control'
fill value is a double data type.
Now we need to add the functions for the Symbol Factory activeX control events. Click on the
'Message Maps' tab. For this project we need the 'Click' events for 'IDC_STDCTRL1' and 'IDC_STDCTRL3' and the 'EN_CHANGE'
event for the 'IDC_EDIT1' edit box. Click 'IDC_STDCTRL1' in the 'Object Ids:' dialog and 'Click' in the 'Messages:'
dialog. Now click the 'Add Function' button. This brings up the 'Add Member Function' dialog. The default name 'OnClickStdCtrl1' in the 'Member function name:'
dialog is fine. Click 'OK'. Now add a 'Click' function for 'IDC_STDCTRL3' and the 'EN_CHANGE' function for the 'IDC_EDIT1'
edit box. Use the default function names 'OnClickStdCtrl3' and 'OnChangeEdit1' respectively as shown below.
 |
Now we're getting somewhere! Open the' "Project Name" Dlg.cpp'
file. All the functions we added in the MFC Class Wizard are in this file. Thanks to MFC Class Wizard the only code we need to write is for the OnClickStdctrl1()
,OnClickStdctrl3() and OnChangeEdit1() functions. Scroll down in the file window until you find the OnClickStdctrl1() function as shown below.
Type the following code in the OnClickStdctrl1() procedure.
void CSymbolFactoryExampleDlg::OnClickStdctrl1() {
// see if control is blinking or not long Blink = m_StdCtrl1.GetBlinkMode();
// if blinking then stop blinking, if not blinking then start blinking
if (Blink == 0) { Blink = 2; m_StdCtrl1.SetBlinkMode(Blink); } else { Blink = 0; m_StdCtrl1.SetBlinkMode(Blink);
} }
Type the following code in the OnClickStdctrl3() procedure.
void CSymbolFactoryExampleDlg::OnClickStdctrl3() {
long Flip = m_StdCtrl3.GetFlip(); if (Flip == 0) { Flip = 1; m_StdCtrl3.SetFlip(Flip); } else { Flip = 0;
m_StdCtrl3.SetFlip(Flip); } }
Type the following code in the OnChangeEdit1() procedure.
void CSymbolFactoryExampleDlg::OnChangeEdit1() { UpdateData(TRUE);
m_CutawayCtrl1.SetLevel(m_FillValue); }
CONGRATULATIONS - You're Done Setting Up the Project - Now Let's Compile and Run it
Previous Step - Configure the Controls | Next Step - Compile and Run
|