Contents‎ > ‎

C++/CLI template of Windows Form Application in Visual Studio Express 2012

Recently, I installed the new version of Visual Studio.
Microsoft released Visual Studio Express 2012 for Windows Desktop even though some people predicted that MS would release only for Web and windows 8, which has a new GUI or Metro.
VS Express 2012 for Windows Desktop makes it possible to develop applications running on Desktop PCs by using VB, C#, and C++/CLI.
In addition, it finally regains IntelliSense for C++/CLI! IntelliSense is important for programming with .Net framework. I refrained to use the previous version, Visual C++ 2010 Express because it has no IntelliSense.

But, there is a problem. While you can find VB and C# project templates of Windows Form Application, there is NO C++/CLI template for GUI. It has only CUI template and empty one.
It is possible to make GUI with C++/CLI if you set up by yourself. But it is burdensome to do so every when you start new project.
So I made a template for C++/CLI.
    WinCLI.zip
Download the zip file and put it in <your user folder>\Documents\Visual Studio 2012\Templates\ProjectTemplates\
Then, you can use it as well as other templates.



===============================================================
Here is the instruction about how to create the template.

At first, make an empty CLR project.



You can see there is no files to display in solution explorer. Now you need to add a main source file which will be called at the first.


The name of the file should be that of the template.


Next, you need to add a form. A form is defined in a header file, so you need to add one.


The name of it can be anything.


Then, type these code in the file:

-------------------------------------------------------------------------------------
#include "MyForm.h" //the header name for your form

using namespace Project1; //the project name in your header file

[STAThreadAttribute]
int main(array<System::String ^> ^args)
{
    Application::EnableVisualStyles();
    Application::SetCompatibleTextRenderingDefault(false);

    Application::Run(gcnew MyForm());
    return 0;
}
-------------------------------------------------------------------------------------
*Note: you need to change the first and seconde lines as defined by your header file of the form.




Now you can run your program. But a console also appears. It is not cool.
To hide this, it is necessary to change the setting of the project.

Open the property.


Before setting, you should change Configuration option to "All Configuration."
Follow [Configuration Properties] -> [Linker] -> [System]. At the "SubSystem," change the setting to "Windows (/SUBSYSTEM:WINDOWS)."


In addition, follow [Configuration Properties] -> [Linker] -> [Advanced]. At the "Entry Point," put the name of the function which will be called at first. (In this case, it is "main" without parentheses)


OK, you have setting done. You may check if it works correctly.
After that, open the Export Template Wizard from "FILE."


At the entry, you can put some explanation about your template.
It will be shown when you open the wizard of template. In the image, I used a similar icon as this template.


As a result, you can create a C++/CLI project for Windows Forms Application.






Created : 09/25/2012
Last update : 10/25/2014