Click here to Skip to main content
Licence CPOL
First Posted 18 Oct 2006
Views 14,865
Downloads 87
Bookmarked 6 times

Windows Forms Using Managed C++

By LeathurBoy | 18 Oct 2006
How to use Windows Forms in a Win32 application using Managed C++
5 votes, 71.4%
1
1 vote, 14.3%
2

3

4
1 vote, 14.3%
5
1.46/5 - 7 votes
μ 1.46, σa 2.62 [?]

Introduction

Now that Microsoft has decided to drop the well known MFC/Win32 SDK in favour of .NET Windows Forms, many MFC/Win32 developers are attempting to move over to .NET but think they must use Managed C++ or C#.

I present here a very easy way to start with Windows Forms using Win32 applications!

Start Microsoft Visual Studio .NET and start a new Win32 application. Make the project empty. I called mine "Win32_Project". Once you have your empty Win32 application, add a new item. Choose UI -> Windows Form, and call it whatever you want; I call mine "AddedForm".

Now add a new .cpp file with a defined entry point; just for argument's sake, use the standard C (int main ()) declaration. Make sure to add the header of the Windows Form (in my case, "AddedForm.h").

Now add the following code, substituting my namespace and form name with yours:

// Enabling Windows XP visual effects before any controls are created
Application::EnableVisualStyles();
Application::SetCompatibleTextRenderingDefault(false); 

// Create the main window and run it
Application::Run(gcnew Win32_Project::AddedForm());

Make sure you have set your build configuration to use the Common Language Runtime. Run your application! It should work fine!

You may have noticed that a DOS box pops up first and then your Form on top of the window; if not, run your application. This is due to the program's entry call. Change the program entry point to the standard Win32 entry point (int APIENTRY _tWinMain(HINSTANCE hInstance,HINSTANCE hPrevInstance,LPTSTR lpCmdLine,int nCmdShow)). Make sure to add windows.h and tchar.h to your main file.

Run the program again. No DOS box! There you have it, Windows Forms in Win32!

License

This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

About the Author

LeathurBoy

Web Developer

United Kingdom United Kingdom

Member


Sign Up to vote   Poor Excellent
Add a reason or comment to your vote: x
Votes of 3 or less require a comment

Comments and Discussions

 
You must Sign In to use this message board. (secure sign-in)
 
Search this forum  
 FAQ
    Noise  Layout  Per page   
  Refresh
GeneralQuestion PinmemberRobc16:04 30 Sep '08  

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.

Permalink | Advertise | Privacy | Mobile
Web03 | 2.5.120209.1 | Last Updated 18 Oct 2006
Article Copyright 2006 by LeathurBoy
Everything else Copyright © CodeProject, 1999-2012
Terms of Use
Layout: fixed | fluid