Cyclone
Cyclone

Reputation: 15289

Visual C++ 2010 code questions

I've just started with C++ and I decided to use Visual C++.

In the application, I've selected the Windows Forms Application as my project and then I've "draw" my window using the tools menu.

Now the code looks like this:

Form1.h

#pragma once

namespace Test {

    using namespace System;
    using namespace System::ComponentModel;
    using namespace System::Collections;
    using namespace System::Windows::Forms;
    using namespace System::Data;
    using namespace System::Drawing;

    /// <summary>
    /// Summary for Form1
    /// </summary>
    public ref class Form1 : public System::Windows::Forms::Form
    {
    public:
        Form1(void)
        {
            InitializeComponent();
            //
            //TODO: Add the constructor code here
            //
        }

    protected:
        /// <summary>
        /// Clean up any resources being used.
        /// </summary>
        ~Form1()
        {
            if (components)
            {
                delete components;
            }
        }
    private: System::Windows::Forms::ProgressBar^  progressBar1;
    protected: 

    private: System::Windows::Forms::Timer^  timer1;
    private: System::Windows::Forms::Label^  label1;
    private: System::Windows::Forms::Label^  label2;





    protected: 





    private: System::ComponentModel::IContainer^  components;
    protected: 


    protected: 

    private:
        /// <summary>
        /// Required designer variable.
        /// </summary>


#pragma region Windows Form Designer generated code
        /// <summary>
        /// Required method for Designer support - do not modify
        /// the contents of this method with the code editor.
        /// </summary>
        void InitializeComponent(void)
        {
            this->components = (gcnew System::ComponentModel::Container());
            System::ComponentModel::ComponentResourceManager^  resources = (gcnew System::ComponentModel::ComponentResourceManager(Form1::typeid));
            this->progressBar1 = (gcnew System::Windows::Forms::ProgressBar());
            this->timer1 = (gcnew System::Windows::Forms::Timer(this->components));
            this->label1 = (gcnew System::Windows::Forms::Label());
            this->label2 = (gcnew System::Windows::Forms::Label());
            this->SuspendLayout();
            // 
            // progressBar1
            // 
            resources->ApplyResources(this->progressBar1, L"progressBar1");
            this->progressBar1->Name = L"progressBar1";
            // 
            // label1
            // 
            resources->ApplyResources(this->label1, L"label1");
            this->label1->BackColor = System::Drawing::Color::Transparent;
            this->label1->ForeColor = System::Drawing::Color::Red;
            this->label1->Name = L"label1";
            this->label1->Click += gcnew System::EventHandler(this, &Form1::label1_Click);
            // 
            // label2
            // 
            resources->ApplyResources(this->label2, L"label2");
            this->label2->BackColor = System::Drawing::Color::Transparent;
            this->label2->ForeColor = System::Drawing::Color::Red;
            this->label2->Name = L"label2";
            this->label2->Click += gcnew System::EventHandler(this, &Form1::label2_Click);
            // 
            // Form1
            // 
            resources->ApplyResources(this, L"$this");
            this->AutoScaleMode = System::Windows::Forms::AutoScaleMode::Font;
            this->Controls->Add(this->label2);
            this->Controls->Add(this->label1);
            this->Controls->Add(this->progressBar1);
            this->MaximizeBox = false;
            this->MinimizeBox = false;
            this->Name = L"Form1";
            this->Load += gcnew System::EventHandler(this, &Form1::Form1_Load);
            this->ResumeLayout(false);
            this->PerformLayout();

        }
#pragma endregion
    private: System::Void comboBox1_SelectedIndexChanged(System::Object^  sender, System::EventArgs^  e) {
             }
    private: System::Void webBrowser1_DocumentCompleted(System::Object^  sender, System::Windows::Forms::WebBrowserDocumentCompletedEventArgs^  e) {
             }
    private: System::Void pictureBox1_Click(System::Object^  sender, System::EventArgs^  e) {
             }
    private: System::Void Form1_Load(System::Object^  sender, System::EventArgs^  e) {
             }
    private: System::Void button1_Click(System::Object^  sender, System::EventArgs^  e) {
             }
    private: System::Void backgroundWorker1_DoWork(System::Object^  sender, System::ComponentModel::DoWorkEventArgs^  e) {
             }
    private: System::Void textBox1_TextChanged(System::Object^  sender, System::EventArgs^  e) {
             }
    private: System::Void label1_Click(System::Object^  sender, System::EventArgs^  e) {
             }
    private: System::Void label2_Click(System::Object^  sender, System::EventArgs^  e) {
             }
};
}

I don't really know what I have to do with that, because the above code seems to be very ugly, also can I name it C++? How can I use an alert box there, since none of C++'s manual functions related to message boxes worked in this code...

Where I can find any good manual related to the above code language? I just need some basics like:

Upvotes: 0

Views: 1295

Answers (1)

Ben Voigt
Ben Voigt

Reputation: 283951

If you want to learn that language (which is C++/CLI), there's Nishant's book C++/CLI In Action.

I'm surprised you had trouble with the "normal" C++ functions. They should work, including MessageBox. Did you forget to #include <windows.h>?

If you're wanting to learn C++, though, run as far away from C++/CLI as you can. The techniques are totally different. Instead, choose "Win32 Application" when creating a new project.

Upvotes: 1

Related Questions