Bulls Bars

July 21, 2010

You ride front side the front protection are the key. Has to your vehicle’ to cause possibility; S-damage many dangerous there. CARiD is in its crown, is, why we lock the work roughness and makes modern high-grade steel improvement available. The grill protection, the bull staff and press the defense, to which the staff makes available you to the necessity, and we place the quality, from the star for example to Romik®, Westin® and T& for the order; For characteristic; H®. The great summary and all had made to measure hardness did and could find model here.

The bull bars always looked, that its portion of a ditch of all vehicle’ shifts choice. Badly and temptation, the habit corresponds to the staff, in order to repair front side, which you rode expenditure a statement, over to say; Bull bars; Mine leaves way” . If the sparkling chromium plating or the layer of the black propellant supplies the way, a number of the high-grade steel specified above offers the protection. It counted drafts expressly for its riding, the necessity not most safety levels, in order to keep away. Does not leave and defenseless netting and head lamps: netting to wait to offer protection which stops wandering in its tracks. Ultra-mode and arranged exactly to your vehicle, netting guards to bowl prepared and ready to intensify your security with stainless steel boldness.

0

Summary

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 .NET as compared to MFC will help you in making better decisions when the time comes to convert legacy applications to the .NET platform.

Q&A
Q1: Is using Windows Forms the only way to produce a user interface within .NET?

A1: Windows Forms represent windows of all types, not just dialogs. They can be MDI frame windows, pop-up windows, tool windows, and so on. They are the only means within the .NET Framework to represent a Windows-based user interface.

Q2: Is it possible to create a dialog in MFC and use it from a .NET application?

A2: Yes, it is possible to do so. In fact, in Hour 5, “Understanding Managed Versus Unmanaged Code,” there is a lesson on mixing managed (.NET Framework) code with unmanaged (MFC/Win32) code that will help you understand how this is done.

Workshop
The Workshop provides quiz questions to help solidify your understanding of what was covered in this chapter. Answers are provided in Appendix A, “Quiz Answers.”

Quiz
1: What is the base class for a Windows Form?

2: How is a delegate related to an event?

3: How are events different in MFC versus the .NET Framework?

Taken From: SAMS-Tech Yourself MS Visual C++.NET in 24 Hours

0

Comparing the Differences (2)

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 your applications.

Finally, the way that events are handled is quite different between the two applications. With MFC, a message map entry is added to the class’s message map, which maps an event or Windows message to a class function. In the .NET Framework, there is no message map; therefore, each object has events associated with it to which you can attach an event handler that is called when the events occur.

For a further comparison of the two applications, look at the code for the applications on the accompanying CD and compare them in more detail. In the end, you should find the .NET application cleaner and easier to work with than the MFC application.

Taken From: SAMS-Tech Yourself MS Visual C++.NET in 24 Hours

0

Comparing the Differences (1)

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 from the comparison, the .NET application is significantly smaller and even easier to read.

Looking at a few of the major differences between the applications shows a fundamental distinction in the way a .NET application is developed versus how an MFC/Win32 application is developed.

The first main difference is that an MFC Windows application always starts with a CWinApp derivative. The InitInstance() method is overridden and provides the startup initialization for the application. By contrast, the .NET application doesn’t require an application class. The .NET application’s entry point is the main() function, whereas an MFC/Win32 application’s entry point is a WinMain() function encapsulated within the MFC library.

Taken From: SAMS-Tech Yourself MS Visual C++.NET in 24 Hours

0

Building a Managed .NET Framework Application (8)

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: Button* m_pbtnDone;
20: Label* m_pstMessage;
21: System::ComponentModel::Container* m_pComponents;
22: void InitForm();
23: void OnMessageClick( Object* source, EventArgs* e);
24: void OnDoneClick( Object* source, EventArgs* e);
25: };

Now open the HelloNETForm.cpp file. The two functions you just added will be at the bottom of the file. In OnMessageClick, set the m_pstMessage Text property to “Hello from the .NET World.” For the OnDoneClick function, call the function Close, which shuts down the application. The two functions should appear similar to the following:

1: void CHelloNETForm::OnMessageClick( Object* source, EventArgs* e )
2: {
3: m_pstMessage->Text = “Hello from the .NET World.”;
4: }
5:
6: void CHelloNETForm::OnDoneClick( Object* source, EventArgs* e )
7: {
8: Close();
9: }

The final change to the application is to have the main() function create and run the new Windows Form class. Make the changes shown in the following code segment:

#include “helloNETform.h”
int _tmain(void)
{
Application::Run(new CHelloNETForm());
return 0;
}

With those final additions, the application is ready to compile and run. This is the same as with the MFC application. Simply press the F5 key or select the Debug, Start menu command. The resulting Visual C++ .NET application should have the same appearance as the MFC application created earlier.

Taken From: SAMS-Tech Yourself MS Visual C++.NET in 24 Hours

0

Building a Managed .NET Framework Application (7)

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 assign delegates to handle object events with the following statement:

m_pbtnMessage->add_Click(
new System::EventHandler( this, &CHelloNETForm::OnMessageClick ) );

Every time the Message button is clicked, the CHelloNETForm::OnMessageClick() method is called. In your project, you will add two event handlers to the two buttons.

Event handlers must have a specific set of parameters, much in the same way they did for MFC message map handlers. For most events, pointers to a generic Object and an EventArgs object are passed as parameters. The generic Object pointer is a pointer to the object that caused the event, whereas the EventArgs object contains information specific to the event. Following the instructions given earlier, add two member functions. The first function is named OnMessageClick, and the second function is named OnDoneClick. Both functions have a void return type, protected access level, and two parameters: Object* source and EventArgs* e. Listing 3.3 shows the final version of the HelloNETForm.h file.

Taken From: SAMS-Tech Yourself MS Visual C++.NET in 24 Hours

0

Building a Managed .NET Framework Application (6)

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: m_pstMessage->Location = System::Drawing::Point(8, 8);
56: m_pstMessage->Name = “Label”;
57: m_pstMessage->Size = System::Drawing::Size(192, 40);
58: m_pstMessage->TabIndex = 2;
59: m_pstMessage->Text = “”;
60:
61: // Set form properties and add controls to form
62: //
63: // Form1
64: //
65: AutoScaleBaseSize = System::Drawing::Size(5, 13);
66: ClientSize = System::Drawing::Size(322, 87);
67: Controls->Add( m_pstMessage );
68: Controls->Add( m_pbtnDone );
69: Controls->Add( m_pbtnMessage );
70:
71: FormBorderStyle = System::Windows::Forms::FormBorderStyle::FixedDialog;
72: Name = “HelloNET”;
73: Text = “HelloNET”;
74:
75: ResumeLayout(false);
76: }

Taken From: SAMS-Tech Yourself MS Visual C++.NET in 24 Hours

0

Building a Managed .NET Framework Application (5)

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 CHelloNETForm::InitForm()
23: {
24:
25: // Allocate the controls
26: m_pbtnMessage = new Button();
27: m_pbtnDone = new Button();
28: m_pstMessage = new Label();
29:
30: SuspendLayout();
31:
32: // Initialize all control properties
33: //
34: // Message Button
35: //
36: m_pbtnMessage->Location = System::Drawing::Point(240, 8);
37: m_pbtnMessage->Name = “Message”;
38: m_pbtnMessage->TabIndex = 0;
39: m_pbtnMessage->Text = “Message”;
40: m_pbtnMessage->add_Click(
41: new System::EventHandler( this, &CHelloNETForm::OnMessageClick ) );
42:
43: //
44: // Done Button
45: //

Taken From: SAMS-Tech Yourself MS Visual C++.NET in 24 Hours

0

Building a Managed .NET Framework Application (4)

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 variables to a class like we did earlier, the generated code also includes class initializers for these variables. In this case, because we declared pointers, the generated code set these variables to NULL. However, it didn’t add the appropriate #include statement. To fix this problem, include the header file stdlib.h at the top of the HelloNETForm.cpp file. Your program should now compile with zero errors and zero warnings.

Begin by filling in the constructor code. Because the member variables you added are simply pointers, you need to create the objects before you can use them. Therefore, create the form control container member variable (m_pComponents) by using the C++ keyword new. The remaining line in the constructor calls the InitForm function.

In the InitForm() function, create the three controls, one by one, and set the properties appropriately. After all the controls are created, they are added to the form with the Form::Controls->Add() method. The order in which the controls are added has an effect on the tab order if the tab order isn’t specified for the controls. In this case, it is specified and therefore doesn’t matter.

Taken From: SAMS-Tech Yourself MS Visual C++.NET in 24 Hours

0

Building a Managed .NET Framework Application (3)

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 of the class is to add the necessary elements that are not supported by wizards within the IDE. Using Listing 3.1 as a guide, add the appropriate using statements and add the __gc keyword immediately preceding the class keyword. This indicates to the compiler that the class is managed by the .NET Framework and its memory manager.

When you are finished, you’re HelloNETForm.h file should look similar to Listing 3.1.

Listing 3.1 Transforming a Generic C++ class into Managed Code
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: Button* m_pbtnDone;
20: Label* m_pstMessage;
21: System::ComponentModel::Container* m_pComponents;
22: void InitForm();
23: };

Taken From: SAMS-Tech Yourself MS Visual C++.NET in 24 Hours

0