locked
Trigger Event RRS feed

  • Question

  • Hello, I'm kinda new to C++ coding, but I have experience with VB and web programming.

    I made a form and after it's created I want it to trigger an event like this:

    event()
    {
    // do things here
    }

    How can I make this possible?

    This is my whole code, but not really important for this question.

    #pragma once
    
    namespace GUIWindowsFormsApplication {
    
        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 Form2
        /// </summary>
        public ref class Form2 : public System::Windows::Forms::Form
        {
        public:
            Form2(void)
            {
                InitializeComponent();
                //
                //TODO: Add the constructor code here
                //
            }
    
        protected:
            /// <summary>
            /// Clean up any resources being used.
            /// </summary>
            ~Form2()
            {
                if (components)
                {
                    delete components;
                }
            }
        private: System::Windows::Forms::Label^  label1;
        private: System::Windows::Forms::ProgressBar^  progressBar1;
        private: System::Windows::Forms::Label^  TextUpdating;
    
        protected:
    
        private:
            /// <summary>
            /// Required designer variable.
            /// </summary>
            System::ComponentModel::Container ^components;
    
    #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->label1 = (gcnew System::Windows::Forms::Label());
                this->progressBar1 = (gcnew System::Windows::Forms::ProgressBar());
                this->TextUpdating = (gcnew System::Windows::Forms::Label());
                this->SuspendLayout();
                //
                // label1
                //
                this->label1->AutoSize = true;
                this->label1->Font = (gcnew System::Drawing::Font(L"Microsoft Sans Serif", 12, System::Drawing::FontStyle::Regular, System::Drawing::GraphicsUnit::Point,
                    static_cast<System::Byte>(0)));
                this->label1->ForeColor = System::Drawing::SystemColors::WindowText;
                this->label1->ImageAlign = System::Drawing::ContentAlignment::TopCenter;
                this->label1->Location = System::Drawing::Point(88, 50);
                this->label1->Name = L"label1";
                this->label1->Size = System::Drawing::Size(324, 20);
                this->label1->TabIndex = 3;
                this->label1->Text = L"Windows 7 Home Premium is being updated.";
                //
                // progressBar1
                //
                this->progressBar1->Location = System::Drawing::Point(70, 125);
                this->progressBar1->Name = L"progressBar1";
                this->progressBar1->Size = System::Drawing::Size(360, 60);
                this->progressBar1->TabIndex = 4;
                //
                // TextUpdating
                //
                this->TextUpdating->AutoSize = true;
                this->TextUpdating->Location = System::Drawing::Point(68, 190);
                this->TextUpdating->Name = L"TextUpdating";
                this->TextUpdating->Size = System::Drawing::Size(175, 13);
                this->TextUpdating->TabIndex = 5;
                this->TextUpdating->Text = L"8888888888888888888888888888";
                //
                // Form2
                //
                this->AutoScaleDimensions = System::Drawing::SizeF(6, 13);
                this->AutoScaleMode = System::Windows::Forms::AutoScaleMode::Font;
                this->ClientSize = System::Drawing::Size(484, 262);
                this->Controls->Add(this->TextUpdating);
                this->Controls->Add(this->progressBar1);
                this->Controls->Add(this->label1);
                this->Name = L"Form2";
                this->ResumeLayout(false);
                this->PerformLayout();
    
            }
    #pragma endregion
        };
    }

    And as last question what is the difference between class, int, bool and such? Like in:

    class event()
    int event()
    bool event()

    Thanks a lot!

    Hans

    • Edited by .HansSw Wednesday, January 18, 2012 3:46 PM
    Wednesday, January 18, 2012 3:43 PM

Answers

  • Hi .HansSw,

    Welcome to c++ world,

    Q-first question how to trigger an event?

    A-first all you have to create event by using "CreateEvent Api", then create thread name as 'event', to create thread use "CreateThread Api",

    then use "WaitForSingleObject Api" in thread to wait in 'event' thread and when ever you want trigger your thread 'event'  use "SetEvent Api",

    "CreateEvent Api" Look- http://msdn.microsoft.com/en-us/library/windows/desktop/ms682396%28v=vs.85%29.aspx

    "CreateThread Api" Look - http://msdn.microsoft.com/en-us/library/windows/desktop/ms682453%28v=vs.85%29.aspx

    "WaitForSingleObject Api" Look - http://msdn.microsoft.com/en-us/library/windows/desktop/ms687032%28v=vs.85%29.aspx

    "SetEvent Api" Look - http://msdn.microsoft.com/en-us/library/windows/desktop/ms686211%28v=vs.85%29.aspx

     

    Q- what is the difference between class, int, bool and such?

    A- class is keyword which is used to create class like "class event {};"

    for more details - http://en.wikipedia.org/wiki/C%2B%2B_classes

    Also int and bool are basic data types in c..

    for more details - http://www.tutorialspoint.com/ansi_c/c_basic_datatypes.htm
    Thanks, @SOU@
    • Proposed as answer by SOU (Sourabh Arvikar) Friday, January 20, 2012 3:54 AM
    • Marked as answer by Rob Pan Tuesday, January 31, 2012 8:37 AM
    Wednesday, January 18, 2012 5:11 PM