30

I'm really new to visual studio and programming in general. I'm using Visual Studio Community 2015 Desktop Version (from what I know). I can't find a Windows Forms Application from the C++ category, while there is one for C#.

Can anyone help, do I need to download another version, a plugin, or anything? Sorry if a stupid question, I just really can't figure it out!

10
  • 1
    There probably isn't a project template for C++ since it's not usually used for WinForma development. Commented Sep 4, 2015 at 18:23
  • 3
    Programming Windows Forms with C++ is actually C++/CLI, a dot.netified syntax for interoperability. C++/CLI is best used for dealing with exposing C or C++ code to .Net languages (instead of using p/invoke).
    – crashmstr
    Commented Sep 4, 2015 at 18:47
  • 1
    @SamiKuhmonen: there used to be a preinstalled C++ template in all previous versions of VS. Microsoft just omitted it to promote C# development.
    – user1196549
    Commented Nov 28, 2016 at 16:30
  • 2
    @YvesDaoust C++/CLI is not C++ and learning C++/CLI will not help you write idiomatic C++ programs that use standard C++ functionality. It sounds like the user (like many) mistake "C++ Windows Forms" as being plain old C++ when it is most definitely not (part of my comment!). C++/CLI is very useful, and I use it frequently to interface .Net code with C++ code. I would also question the idea of starting with Windows Forms when that is definitely on the back burner for years now. Alternatives are third party with standard C++ or go WPF and C#. Yes, best is an opinion, and that is mine.
    – crashmstr
    Commented Nov 28, 2016 at 18:08
  • 1
    @antikbd but for people with no knowledge at all of .NET/C#, C++ CLI isn't the best way to learn C++.
    – Xam
    Commented Jan 12, 2018 at 21:38

3 Answers 3

45

There are no C++ Windows Form templates in Visual Studio 2015. As I see it, you have two choices:

  • When creating a new project, You will see an online dropdown, click that and try to search for "C++ Windows Forms".
  • Create an empty C++ CLR project and add a Windows Forms to it. This link puts it like this (credit to the onContentStop, the user who posted this):

    1. Make a "CLR Empty Project".
    2. Press Ctrl-Shift-A and create a Windows Form (under UI).
    3. Inside the CPP file that is created, paste this code, replacing anything in square brackets except [STAThread] with the appropriate names:

      #include "[FORM NAME].h"
      
      using namespace System;
      using namespace System::Windows::Forms;
      
      [STAThread]//leave this as is
      void main(array<String^>^ args) {
          Application::EnableVisualStyles();
          Application::SetCompatibleTextRenderingDefault(false);
          Application::Run(gcnew [PROJECT NAME]::[FORM NAME]);
      }
      
    4. Right click your project in the Solution Explorer and click Properties.

    5. Under Configuration Properties > Linker > Advanced, change Entry Point to "main" (without quotation marks).
    6. Under Configuration Properties > Linker > System, change SubSystem to "Windows (/SUBSYSTEM:WINDOWS)" (without quotation marks).
3
  • 3
    If you want to edit the form visually, then go to Header Files -> [MY FORM].h in Solution Explorer and edit it via the Microsoft Toolbox. Commented Jan 18, 2016 at 18:10
  • And I pressed the X button and closed the designer view. Now I want to open the designer view................ How? I don't see how to open designer view. Visual Studio just turned against C++ developers.
    – Ari Seyhun
    Commented Sep 16, 2017 at 15:50
  • Thank you, but I have one question: Why should I memorize these steps? Why Visual studio does not create this piece of code automatically?
    – Velaro
    Commented Jul 18, 2019 at 13:20
10

Though this has already been answered, I feel like this might help those who stumble across this in the future. While creating a new project, directly above the text field for naming your project, there is a blue link that reads "Click here to go online and find templates" If you click that link it will direct you to templates that are available for you to download & use. Simply use the hierarchy on the left hand side and navigate to Visual C++ and you should be able to simply click "C++ Windows Forms" and it will create the new project, while also downloading and installing the template for future use. So, next time you go to create a C++ Winform you wont have to search for it again.

0
  1. Click File-New-Project
  2. Click online
  3. Click/ Expand Visual C++
  4. Click windows form application
  5. Click C++/CLR Windows Forms fur Visual Studio 201..

Write project Name And Click OK.

Download and enjoy!!

0

Your Answer

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

Not the answer you're looking for? Browse other questions tagged or ask your own question.