visual c++ samples and examples blog contains tutorials on Toolbar ,statusbar, timers ,hover buttons,inflaterect, intersectrect,tooltips, dll , These applications and tutorials contains codes working programs plus explanation in steps doing these application The lessons include code ,descriptions plus images to illustrate the steps to create the application and download Each one of the modules fully explained functions to help you how to make the project
2/3/09
CFormView Example
In this Visual c++ CformView Example we used a class derived instead of CDialog
This applications contains 2 buttons one for devision and one for multiplication and it has 2 Edit controls to hold the 2 number involved in the arithmetic operation
After pressing the devision button here what you get
To create the application
1-Start a new MFC application wizard chose a name for the project let us CFORMVIEWEX or any thing u like
2-In the last step chose CFormView as the parent of your derived view class
3-Start building the dialog as shown above chose IDC_EDIT1 ,IDC_EDIT2 For the numbers on the lefts ,IDC_RESULT FOr the result number IDC_MULTIPLY FOR multiplication button finally chose IDC_DEVIDE for the devision
4-In class wizard the following member variables m_number1 for the first edit control NUM1 ;
m_number2 for the second edit control second number and finally for the result m_results do not forget to chose CString type for all of the variables
5- Add messege handler for the 2 buttons and name them Mulitiplication and Devide Respectively and edit the code of those functions
Here what you get the code is marked in Red
void CCFormViewExView::Mulitiplication()
{
double first_number , second_number , result;
UpdateData();// Read data
first_number = atof( m_number1) ;
second_number = atof( m_number2);
result = first_number * second_number ;
m_results.Format("%.3f", result) ;
UpdateData(FALSE); // WriteData
}
and the second function
as follows
void CCFormViewExView::Devide()
{
double NumA ,NumB , results ;
UpdateData();
NumA = atoi( m_number1);
NumB = atoi(m_number2);
results = NumA/NumB ;
m_results.Format("%.5f", results) ;
UpdateData(FALSE);
}
6- Finaly build the application stard putting numbers on the edit control and see the results
note the effect of using different parameters in Format function where Devision has 5 decimal numbers than Multiplication which has only 3
To download the whole project click here fullproject and if you want the exe file click here Exefile
This post contains many typos like devide and others i made them for search engines intentionaly Loll
Subscribe to:
Posts (Atom)