I bought C++ .NET step by step last friday afternoon and I'm @ p. 380 or so and all I gotta say is .NET owns!. Garbage collection, the arrays are packed with built in methods to manipulate the array (sort, binary search, reverse), and there are dictionary, hashtables too. What really got me was the ease of use to create a simple window. I remember trying to do the same 2 years ago and it wasn't this easy, and it required more lines of code. but check it out.
Also remember, this is just 1 small aspect of C++.NET. There's more to .NET than below, much more
--------------------
__gc class MyEmptyWindow: public Form
{
public:
MyEmptyWindow(){}
};
int __stdcall WinMain()
{
Application::Run(new MyEmptyWindow());
return 0;
}
-------------
Ofcourse there's some includes you gotta add at the top
#include <mscorlib.dll> (require), #include <System.dll> (required), #include <System.Windows.Forms.dll> (requried so we can inherit the class "Form") and #include <System.Drawing.dll> (need this to add stuff like buttons, combo boxes, menus, etc).
And then you need to add namespaces, notice the same name convention is used for both DLL and namespace
using namespace System; using namespace System::Windows::Forms; using namespace System:
rawing;
and if you want to add stuff like radio buttons, text boxes, labels, etc.
you just create them as objects, so if you were to modify the constructor, you'd do
MyEmptyWindow()
{
Label* someLabel = new Label();
Button* someButton = new Button();
TextBox* txtbox = new TextBox();
and you assign them properties like this
someLabel->Text = "enter name here";
Button->Text = "Click Me";
txtbox-> Text = "hi";
and there are a lot of properties you can set;
->Size (to specify the how much space it takes); ->location (to specify where in your window you want it placed); and the list goes on
to make these controls appear on your window, you do a final call
Controls->Add(someLabel);
Controls->Add(someButton);
Controls->Add(txtbox);
then you gotta add them to a multicast delegate which is a managed c++ feature, but it basically tells the program what to do when an aevent such as a click, double click, mouse hover, or something occurs. but you need to make a function for each action, and it goes like this
someButton->Click += new EventHandler(this, &MyMyEmptyWindow::button_click);
what this does is, when someone clicks "someButton", a functcion named "button_click" located in the MyEmtpyWindow class will be executed. You use "this" as the 1st paramater becuase the function is located within the class. If you want to execute a function from another class, you have to access it through an object of that class. I think that's how your supposed to do it =/
anyways, so the function for "button_click" would look like this
void button_click(Object* pObj, EventArgs* pArgs)
{
if(pObj == someButton) MessageBox::Show("button click detected", "title of messgaebox goes here");
}
It receives an object and checks to see if, the object is "someButton", the object could be something else such as "someLabel" or "txtbox" depending on how you code it.
So is this cool or what? This is just 1 small aspect of .NET, but look at how simple it is to make a windows program. No consoles. Also, look at how the properties for each control have the same name as their equivalent in VB, Is this cool or is this cool. =)
Also remember, this is just 1 small aspect of C++.NET. There's more to .NET than below, much more
--------------------
__gc class MyEmptyWindow: public Form
{
public:
MyEmptyWindow(){}
};
int __stdcall WinMain()
{
Application::Run(new MyEmptyWindow());
return 0;
}
-------------
Ofcourse there's some includes you gotta add at the top
#include <mscorlib.dll> (require), #include <System.dll> (required), #include <System.Windows.Forms.dll> (requried so we can inherit the class "Form") and #include <System.Drawing.dll> (need this to add stuff like buttons, combo boxes, menus, etc).
And then you need to add namespaces, notice the same name convention is used for both DLL and namespace
using namespace System; using namespace System::Windows::Forms; using namespace System:
and if you want to add stuff like radio buttons, text boxes, labels, etc.
you just create them as objects, so if you were to modify the constructor, you'd do
MyEmptyWindow()
{
Label* someLabel = new Label();
Button* someButton = new Button();
TextBox* txtbox = new TextBox();
and you assign them properties like this
someLabel->Text = "enter name here";
Button->Text = "Click Me";
txtbox-> Text = "hi";
and there are a lot of properties you can set;
->Size (to specify the how much space it takes); ->location (to specify where in your window you want it placed); and the list goes on
to make these controls appear on your window, you do a final call
Controls->Add(someLabel);
Controls->Add(someButton);
Controls->Add(txtbox);
then you gotta add them to a multicast delegate which is a managed c++ feature, but it basically tells the program what to do when an aevent such as a click, double click, mouse hover, or something occurs. but you need to make a function for each action, and it goes like this
someButton->Click += new EventHandler(this, &MyMyEmptyWindow::button_click);
what this does is, when someone clicks "someButton", a functcion named "button_click" located in the MyEmtpyWindow class will be executed. You use "this" as the 1st paramater becuase the function is located within the class. If you want to execute a function from another class, you have to access it through an object of that class. I think that's how your supposed to do it =/
anyways, so the function for "button_click" would look like this
void button_click(Object* pObj, EventArgs* pArgs)
{
if(pObj == someButton) MessageBox::Show("button click detected", "title of messgaebox goes here");
}
It receives an object and checks to see if, the object is "someButton", the object could be something else such as "someLabel" or "txtbox" depending on how you code it.
So is this cool or what? This is just 1 small aspect of .NET, but look at how simple it is to make a windows program. No consoles. Also, look at how the properties for each control have the same name as their equivalent in VB, Is this cool or is this cool. =)