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:
Application::EnableVisualStyles();
Application::SetCompatibleTextRenderingDefault(false);
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!