CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 3 of 3
  1. #1
    Join Date
    Mar 2005
    Location
    Detroit MI
    Posts
    80

    Windows Form Handlers in CPP file?

    Hi,

    I'm trying to move all the windows form component handlers into a CPP from the generated Form1.h file. How can I do this? I'm using VC++ 2005.

    I have tried so far to :
    1/ Convert all the function definitions to prototypes.

    e.g.
    private: System::Void exitToolStripMenuItem_Click(System::Object^ sender, System::EventArgs^ e)
    {}
    >> to >>
    private: System::Void exitToolStripMenuItem_Click(System::Object^ sender, System::EventArgs^ e);

    2/ Create a new cpp file, include all the required namespaces and header files. Including Form1.h

    3/ Declare the function here and prefix the function name with the windows form class name.

    e.g. System::Void Form1::exitToolStripMenuItem_Click (System::Object^ sender, System::EventArgs^ e)
    {
    // some code
    }

    Then, when I compile, I get the following error:
    error C2653: 'Form1' : is not a class or namespace name

    Any ideas what I am missing?
    Regards,

    Big Winston

  2. #2
    Join Date
    Mar 2005
    Location
    Detroit MI
    Posts
    80

    Re: Windows Form Handlers in CPP file?

    I figured this one out, so for anyone who's interested, here's the solution:

    You need to include the namespace for your project in the cpp file you use. You can get this by going to the main cpp file for your project. Copy the namespace decleration there and insert it after the other namespaces used for windows forms.

    e.g.

    Code:
    #include "stdafx.h"
    #include "Form1.h"
    
    
    using namespace System;
    using namespace System::ComponentModel;
    using namespace System::Collections;
    using namespace System::Windows::Forms;
    using namespace System::Data;
    using namespace System::Drawing;
    using namespace <project name>;
    
    System::Void Form1::exitToolStripMenuItem_Click(System::Object^  sender, System::EventArgs^  e)
    {
    	playBtn->Enabled = false;
    }
    Regards,

    Big Winston

  3. #3
    Join Date
    Mar 2005
    Location
    Detroit MI
    Posts
    80

    Re: Windows Form Handlers in CPP file?

    Infact, you can also get rid of the other namespace declerations, namely these in the example above. They're not needed here as they're declared in the header.

    So your example will now look like this :

    Code:
     #include "stdafx.h"
    #include "Form1.h"
    
    using namespace <project name>;
    
    System::Void Form1::exitToolStripMenuItem_Click(System::Object^  sender, System::EventArgs^  e)
    {
    	playBtn->Enabled = false;
    }
    Regards,

    Big Winston

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured