I would ultimately like to create a simple dialog-based app that does a simple calculation, like adding 1+1, and displays the result in a text box. The caveat is, that I would like the calculation performed in a separate .cpp file (Functions.cpp) so that I can isolate the calculation part of the program from everything else. So, I did the following:
1. Created an MFC dialog-based application in VS2008 called "FirstApp". The files FirstApp.cpp and FirstAppDlg.cpp were created (along with their respective header files).
2. Using the Resource View tab, I inserted a button dialog called IDC_BUTTON1. This is the button to be pushed.
3. Then I Inserted an edit control dialog called IDC_EDIT1. This is where the results of 1+1 is to be displayed. Added a variable (value) called m_strEdit1 of type String to the control.
4. I created Functions.cpp and Functions.h (no code in there yet)
5. Double clicked on the button dialog and inserted the code below
Question: How do make it so that I when I click on Button1 the program goes to Function.cpp to calculate 1+1..and then displays the result "2" in the Edit Control? I plan on adding more complex calculation functions and using more variables soon...so I would like to use classes in the solution.
UpdateData( TRUE ); // get text from edit control into 'm_strEdit1'
m_strEdit1 = intToString( addInts( 1, 1 ) );
UpdateData( FALSE ); // put the text from 'm_strEdit1' to the edit control
int addInts( int x, int y );
CString intToString( int x );
int addInts( int x, int y )
return x + y;
CString intToString( int x )
strText.Format( "%d", x );