December 29, 2009
In this hour you created two applications that perform the same task. One application was created with MFC and the other with the .NET Framework. Both application display a hello message when a push button is clicked. You also learned about the differences between the two application implementations.
Being familiar with how things are implemented in [...]
December 26, 2009
Another major difference you should notice while looking at both applications is that the .NET application does not delete anything it allocates with new. This is because the .NET Framework frees all objects once they are no longer referenced. This is done by the garbage collector automatically. This eliminates the problems of memory leaks in [...]
December 23, 2009
Although the process of building the MFC application was more automated with wizards and form designers, the resulting code of the two applications shows that the MFC application is much more complex. If you take into consideration that the .NET application has no resource file to describe the Windows Form and remove the form definition [...]
December 20, 2009
Listing 3.3 Adding Event Handler Declarations
1: #pragma once
2:
3: #using
4:
5: #using
6: #using
7: #using
8:
9: using namespace System;
10: using namespace System::Windows::Forms;
11:
12: __gc class CHelloNETForm : public Form
13: {
14: public:
15: CHelloNETForm(void);
16: ~CHelloNETForm(void);
17: protected:
18: Button* m_pbtnMessage;
19: [...]
December 17, 2009
In order for your form to respond to user events, you’ll need to capture the button click events. Events that were previously handled with the MFC message map are handled quite differently in the .NET Framework. Events are handled by delegates within your class. A delegate is quite similar to a C/C++ function pointer. You [...]
December 14, 2009
46: m_pbtnDone->Location = System::Drawing::Point(240, 40);
47: m_pbtnDone->Name = “Done”;
48: m_pbtnDone->TabIndex = 1;
49: m_pbtnDone->Text = “Done”;
50: m_pbtnDone->add_Click(
51 new System::EventHandler( this, &CHelloNETForm::OnDoneClick ) );
52: //
53: // Message Label
54: //
55: [...]
December 11, 2009
Listing 3.2 Creating the Form
1: #include “stdafx.h”
2: #include “hellonetform.h”
3: #include
4:
5: #using
6: CHelloNETForm::CHelloNETForm(void)
7: : m_pbtnMessage(NULL)
8: , m_pbtnDone(NULL)
9: , m_pstMessage(NULL)
10: , m_pComponents(NULL)
11: {
12: m_pComponents = new System::ComponentModel::Container();
13:
14: // Initialize the Form
15: InitForm();
16: }
17:
18: CHelloNETForm::~CHelloNETForm()
19: {
20: }
21:
22: void [...]
December 8, 2009
Now it’s time to fill in the functions you just created. Refer to Listing 3.2 as you read through this section. To begin with, try and compile your project. One thing you’ll notice is that the compiler complains that NULL is undefined. One great addition to Visual C++ .NET is that when you’re adding member [...]
December 5, 2009
Now that you’ve added the member variables, its time to add some member functions. Right-click the CHelloNETForm class again, but this time select Add, Add Function. Enter void as the return type, InitForm as the function name, and an access level of protected. Click Finish to close the dialog.
The last step to finish the design [...]
December 2, 2009
The next step is to declare a class that represents the form for the application. Select Project, Add Class from the main menu. In the list of available templates in the dialog that is displayed, select the Generic C++ Class template and click the Open button. Name the class CHelloNETForm and specify the base class [...]