VS Express 2012: No C++ Windows Forms Application?
-
Friday, September 21, 2012 4:23 AM
I excitedly installed Visual Studio Express 2012 for Windows Desktop on my fresh Windows 7 installation a couple days ago. I opened it and quickly found, to my dismay, that there is no native support for a C++ Windows Forms Application. When creating a new project, under "Templates", you can choose between:
Visual Basic, Visual C#, and Visual C++.
Under Visual Basic and Visual C#, you can choose between:
Windows Forms Application, WPF Application, Console Application, or Class Library.
However, under Visual C++, you can choose between:
Win32 Console Application, Win32 Project, Empty Project, or Makefile Project.
I want to make a Visual C++ Windows Forms Application. How can I do that?
All Replies
-
Friday, September 21, 2012 4:43 AM
The Windows Forms project template has been removed in VS2012 but you can still add forms to your project, see the Project\Add New Item menu, it has Windows Form in the UI section.
You can create a Console or Empty CLR project, add a form to it and then add the necessary code in main to display the form, something like:
#include "MyForm.h" using namespace System; using namespace System::Windows::Forms; [STAThread] void main(array<String^>^ args) { Application::EnableVisualStyles(); Application::SetCompatibleTextRenderingDefault(false); Project1::MyForm form; Application::Run(%form); }You'll also want to change the linker subsystem (Project Properties\Configuration Properties\Linker\System\SubSystem) to Windows.- Marked As Answer by Valley.Forge Saturday, September 22, 2012 2:51 PM
-
Friday, September 21, 2012 4:54 PM
Thanks for the reply. I just now tried that, and got two errors:
Error 1 error LNK2019: unresolved external symbol _WinMain@16 referenced in function ___tmainCRTStartup c:\Users\Jeremy\documents\visual studio 2012\Projects\Project1\Project1\MSVCRTD.lib(crtexew.obj) Project1
Error 2 error LNK1120: 1 unresolved externals c:\users\username\documents\visual studio 2012\Projects\Project1\Debug\Project1.exe Project1
Any idea how to fix this? Thanks for your help so far.
-
Friday, September 21, 2012 9:15 PMAre you sure you created a CLR project? From the error I suspect it's a Win32 Project.
-
Friday, September 21, 2012 10:32 PM
1. I created a new "CLR Empty Project"
2. I clicked Project > Add New Item... > Windows Form > Add
3. I opened MyForm.cpp and made it look exactly like this:
#include "MyForm.h" using namespace System; using namespace System::Windows::Forms; [STAThread] int main(array<String^>^ args) { Application::EnableVisualStyles(); Application::SetCompatibleTextRenderingDefault(false); mySiriInstaller::MyForm form; Application::Run(%form); }Then I hit Build and got those errors. -
Saturday, September 22, 2012 6:16 AM
Check the linker options in Project Properties, Configuration Properties, Linker, Advanced, Entry Point. Try setting that property to main.- Marked As Answer by Valley.Forge Saturday, September 22, 2012 2:51 PM
-
Saturday, September 22, 2012 2:51 PMWow, it worked! Thanks!
-
Tuesday, November 06, 2012 10:28 PM
It should be like this I think
#include "MyForm.h" using namespace Project1; [STAThreadAttribute] int main(array<System::String ^> ^args) { Application::EnableVisualStyles(); Application::SetCompatibleTextRenderingDefault(false); Application::Run(gcnew MyForm()); return 0; }
-
Friday, December 21, 2012 7:25 PM
I tried the both solution and got no errors. The problem is before the main form is displayed,
a console form appeared. How could I eliminate that console form?
mjra
-
Friday, December 21, 2012 8:42 PM
I tried the both solution and got no errors. The problem is before the main form is displayed,
a console form appeared. How could I eliminate that console form?
It sounds like you used one of the "console" templates.
Check the project properties:
Configuration Properties->Linker->System: "SubSystem"
and make it "Not Set"
Do a Rebuild.
- Wayne
-
Saturday, December 22, 2012 3:10 PM
It's still not working, I tried project Properties->Configuration Properties->Linker->System->SubSystem and choose Not Set
mjra
-
Saturday, December 22, 2012 3:29 PM
#include "MyForm.h" #include "stdafx.h" #include <windows.h> using namespace System; using namespace Windows::Forms; using namespace win2012; [STAThreadAttribute] int APIENTRY _tWinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPTSTR lpCmdLine, int nCmdShow) { System::Threading::Thread::CurrentThread->ApartmentState = System::Threading::ApartmentState::STA; Application::EnableVisualStyles(); Application::SetCompatibleTextRenderingDefault(false); Application::Run(gcnew MyForm()); return 0; }I tried researching and got this from another website, and this one works with me. I don't know how to extract the commandline arguments,like your solutions. Thanks for replying.
God Bless
mjra

