Import a class form
-
Hi, i've a visualc++ project( window form application). I've created a class in a cpp file ( and its .h file)with this simple structure: class Myclass{ public: Myclass(); ~Myclass(); func1(); func2(int n); private: int n; }; and i've implemented the functions. Then i've my graphic interface composed by some form application. This is one...Camlive.h #pragma once using namespace System; using namespace System::ComponentModel; using namespace System::Collections; using namespace System::Windows::Forms; using namespace System::Data; using namespace System::Drawing; namespace WinCam { public ref class Camlive : public System::Windows::Forms::Form { public: Camlive(void) { InitializeComponent(); } protected: ~Camlive() { if (components) { delete components; } } private: /// /// Required designer variable. /// System::ComponentModel::Container ^components; #pragma region Windows Form Designer generated code /// /// Required method for Designer support - do not modify /// the contents of this method with the code editor. /// void InitializeComponent(void) { this->components = gcnew System::ComponentModel::Container(); this->Size = System::Drawing::Size(300,300); this->Text = L"Camlive"; this->Padding = System::Windows::Forms::Padding(0); this->AutoScaleMode = System::Windows::Forms::AutoScaleMode::Font; } #pragma endregion }; } I want to use it and its components(like a button control or a textlabel) in Myclass. For example i want that func() of myclass can modify a textlabel of camlive.h. When i try to make a new object of class Camlive( Camlive^ cml in Myclass, it returns a compile error. How can i do? Thanks, regards.
-
Hi, i've a visualc++ project( window form application). I've created a class in a cpp file ( and its .h file)with this simple structure: class Myclass{ public: Myclass(); ~Myclass(); func1(); func2(int n); private: int n; }; and i've implemented the functions. Then i've my graphic interface composed by some form application. This is one...Camlive.h #pragma once using namespace System; using namespace System::ComponentModel; using namespace System::Collections; using namespace System::Windows::Forms; using namespace System::Data; using namespace System::Drawing; namespace WinCam { public ref class Camlive : public System::Windows::Forms::Form { public: Camlive(void) { InitializeComponent(); } protected: ~Camlive() { if (components) { delete components; } } private: /// /// Required designer variable. /// System::ComponentModel::Container ^components; #pragma region Windows Form Designer generated code /// /// Required method for Designer support - do not modify /// the contents of this method with the code editor. /// void InitializeComponent(void) { this->components = gcnew System::ComponentModel::Container(); this->Size = System::Drawing::Size(300,300); this->Text = L"Camlive"; this->Padding = System::Windows::Forms::Padding(0); this->AutoScaleMode = System::Windows::Forms::AutoScaleMode::Font; } #pragma endregion }; } I want to use it and its components(like a button control or a textlabel) in Myclass. For example i want that func() of myclass can modify a textlabel of camlive.h. When i try to make a new object of class Camlive( Camlive^ cml in Myclass, it returns a compile error. How can i do? Thanks, regards.
dodoxor wrote:
I want to use it and its components(like a button control or a textlabel) in Myclass. For example i want that func() of myclass can modify a textlabel of camlive.h.
The buttons and labels, generally all controls, are private members by default. Change it to public.
dodoxor wrote:
When i try to make a new object of class Camlive( Camlive^ cml in Myclass, it returns a compile error. How can i do?
Camlive^ cml = gcnew Camlive(); cml->ShowDialog();
P.S: you should include the Camlive.h header at the top of your class.#include "Camlive.h"
-
dodoxor wrote:
I want to use it and its components(like a button control or a textlabel) in Myclass. For example i want that func() of myclass can modify a textlabel of camlive.h.
The buttons and labels, generally all controls, are private members by default. Change it to public.
dodoxor wrote:
When i try to make a new object of class Camlive( Camlive^ cml in Myclass, it returns a compile error. How can i do?
Camlive^ cml = gcnew Camlive(); cml->ShowDialog();
P.S: you should include the Camlive.h header at the top of your class.#include "Camlive.h"
I try but it returns some compiler errors... #ifndef CAMOBJ_H #define CAMOBJ_H #include "Camlive.h" //other include.. #define WIDTH (100) #define HEIGHT (100) class Camobj { public: Camobj(); ~Camobj(void); void capture(void); private: camaddr_t camaddr; Camlive^ cml;///compiler error }; #endif And in the camobj.cpp #include "stdafx.h" #include "Camobj.h" using namespace System; using namespace System::IO; Camobj::Camobj() { cml=new Camlive();//compiler error } Camobj::~Camobj(void){ ... } The compiler errors are: ...\Camobj.h(56) : error C2143: syntax error : missing ';' before '^' ...\Camobj.h(56) : error C4430: missing type specifier - int assumed. Note: C++ does not support default-int ...\Camobj.h(56) : error C4430: missing type specifier - int assumed. Note: C++ does not support default-int ...\Camobj.h(56) : error C3265: cannot declare a managed 'cml' in an unmanaged 'Camobj' .\Camobj.cpp(15) : error C2065: 'cml' : undeclared identifier .\Camobj.cpp(15) : error C2061: syntax error : identifier 'Camlive' How can i relsolve it? Thanks regards.