4

I just installed Visual Studio 2012 express for Desktop. I can't see any place to create a GUI application with C++ ! Where is this "Windows Form Application" used to exists in Visual C++ 2010 ? Where are these drag and drop controls? I installed this because I got details telling this supports GUI intellisense (Visual C++: Unable to invoke method from another class)

3
  • @chris: :O :O ... OK, but where is this? Commented Mar 3, 2013 at 18:00
  • I'm not sure about the GUI builder, but it will probably work hardcoded with a CLR project. Commented Mar 3, 2013 at 18:06
  • This looks promising. Commented Mar 3, 2013 at 18:06

2 Answers 2

17

It is an unsubtle hint that they want you to stop creating C++/CLI Winforms applications. The plumbing is still in place however, at least for VS2012 and VS2013. This might not be the case in a future one.

You can turn a CLR console application into a Winforms application with these steps:

  • Start with File + New + Project, CLR node, CLR Console Application
  • Project + Add New Item, UI node, Windows Form
  • Project + Properties, Linker, System, SubSystem = Windows
  • Project + Properties, Linker, Advanced, Entry Point = main

Change the pre-generated .cpp file to look like this:

#include "stdafx.h"
#include "MyForm.h"

namespace ConsoleApplication45 {    // Change this!!
    using namespace System;
    using namespace System::Windows::Forms;

    [STAThread]
    int main(array<System::String ^> ^args)
    {
        Application::EnableVisualStyles();
        Application::SetCompatibleTextRenderingDefault(false); 
        Application::Run(gcnew MyForm());
        return 0;
    }
}

Note that you'll need to change the namespace name to your project name. Press F5 to test. You can design the form as normal once everything checks out.


NOTE, Visual Studio 2015 has a nasty static initialization order bug in the CRT that can cause the app to crash instantly with an AVE at startup if the project contains any native C++ code. As yet an unfixed bug, the somewhat inevitable hazard of having these project templates removed. A possible workaround is to change the Entry Point (4th bullet).

For a project that targets x86, copy paste this string:

?mainCRTStartupStrArray@@$$FYMHP$01AP$AAVString@System@@@Z

For a project that targets x64, copy paste:

?mainCRTStartupStrArray@@$$FYMHP$01EAPE$AAVString@System@@@Z

Somewhere around VS2017 the designer fails to open a new form with a cryptic error message. Workaround is to build the project first, use Build > Build.

Sign up to request clarification or add additional context in comments.

4 Comments

Thanks for the reply. I am going to give up C++/CLI :(
@ Hans Passant Do they want you to create Windows Store apps instead?
@Hans Passant, can we get more information on this? What is Microsofts alternative for C++ if they are trying to phase it out?
You ought to ask Microsoft. Their only obvious intentions for C++ are MFC and WinRT, the vast majority of programmers use languages like C# or Javascript to create a GUI.
1

Remove the #include "stdafx.h" and this works well for VS 2022. The form must be hand coded since the Form Designer support was removed starting with VS 2012.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.