Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. Windows Forms
  4. Import a class form

Import a class form

Scheduled Pinned Locked Moved Windows Forms
c++questiongraphicsdockerhelp
3 Posts 2 Posters 2 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • D Offline
    D Offline
    dodoxor
    wrote on last edited by
    #1

    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.

    S 1 Reply Last reply
    0
    • D dodoxor

      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.

      S Offline
      S Offline
      sarah_malik
      wrote on last edited by
      #2

      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"

      D 1 Reply Last reply
      0
      • S sarah_malik

        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"

        D Offline
        D Offline
        dodoxor
        wrote on last edited by
        #3

        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.

        1 Reply Last reply
        0
        Reply
        • Reply as topic
        Log in to reply
        • Oldest to Newest
        • Newest to Oldest
        • Most Votes


        • Login

        • Don't have an account? Register

        • Login or register to search.
        • First post
          Last post
        0
        • Categories
        • Recent
        • Tags
        • Popular
        • World
        • Users
        • Groups