locked
Visual Studio 2017 - Windows Forms RRS feed

  • Question

  • I want to create a Windows Form Project using C++ but this option is not avaiable. It is avaiable only if I use C#. What I have to do do solve this situation? I suppose other people had the same problem and maybe can help me.

    Wednesday, May 31, 2017 8:41 PM

All replies

  • Hi Rafael,

    Please refer to the following complete discussion thread for this requirement:

    Create C++ Windows Forms application in Visual Studio 2017

    In this thread, I will be divided into several replies to your question because each reply can only paste up to 9 pictures.

    If you want to create a Windows Form Project using C++, then please refer to the detailed tutorial below step by step:

    1, Make sure your Visual Studio 2017 have installed C++ package with C++/CLR:

    2, If you have installed all the package and components, then open Visual Studio 2017 and create a new project:

    Right click on the Project1 and choose Properties option:

    Then:


    MSDN Community Support
    Please remember to click "Mark as Answer" the responses that resolved your issue, and to click "Unmark as Answer" if not. This can be beneficial to other community members reading this thread. If you have any compliments or complaints to MSDN Support, feel free to contact MSDNFSF@microsoft.com.

    • Proposed as answer by Stanly Fan Monday, June 5, 2017 5:48 AM
    • Edited by Stanly Fan Monday, January 14, 2019 6:10 AM
    Thursday, June 1, 2017 4:29 AM
  • 3, Add a new item:

    Choose the Windows Form:

    And now you will say the below error:

    Don't worry, close it and add the following code to the MyForm.cpp:

    using namespace System;
    using namespace System::Windows::Forms;
    
    [STAThreadAttribute]
    void Main(array<String^>^ args) {
    	Application::EnableVisualStyles();
    	Application::SetCompatibleTextRenderingDefault(false);
    	Project1::MyForm form;
    	Application::Run(%form);
    }

    Then save it and close the Visual Studio 2017, then reopen your Project1.

    4, When you reopen your Project1, then debug it first:

    And the display:

    5, Now you can do your options in the form by double click MyForm.h:

    That's all, hope this helps!

    Best Regards,

    Stanly


    MSDN Community Support
    Please remember to click "Mark as Answer" the responses that resolved your issue, and to click "Unmark as Answer" if not. This can be beneficial to other community members reading this thread. If you have any compliments or complaints to MSDN Support, feel free to contact MSDNFSF@microsoft.com.

    • Proposed as answer by Bob Ding Friday, June 2, 2017 8:28 AM
    Thursday, June 1, 2017 4:32 AM
  • A lot of thanks for your help on this question. I had the same problem. 
    • Proposed as answer by y.bi Tuesday, January 1, 2019 12:43 PM
    Sunday, February 25, 2018 5:26 PM
  • Thanks, It worked 100 % at first trial! Louis from Brossard, Quebec, Canada
    Friday, March 9, 2018 9:45 PM
  • The answer given no longer works.

    MS does not want programmers writing forms applications for windows in c++, please use QT or another window manager for programming with windows.

    As a benefit, you'll be 100% portable to all the other operating systems out there, allowing your users the option to stop using windows.

    Just a fyi, the pasted code now gives a 'std::array' too fet template arguments on the line

    main(array<String^>^ args)...so the solution proposed has been squashed by MSH, please look at using QT or another option.

    Monday, March 19, 2018 11:08 AM
  • I don't know what this person is talking about.  I just did it and it worked perfectly, thank you very much.

    Thursday, March 22, 2018 6:10 PM
  • yes this method is not working for me i tried with many codes from internet no code supported to creat a windows form in c++
    Thursday, June 14, 2018 7:18 AM
  • Thank you, worked fine for me.

    (I am changing from C# to C++ now)

    Wednesday, June 20, 2018 5:19 PM
  •  unable to start program

    system cant find the file specified..

    this error is making me trouble??

    any solution 

    visual studio c++ windows form

    • Proposed as answer by Sharath S.P Wednesday, June 27, 2018 4:13 PM
    • Unproposed as answer by Sharath S.P Wednesday, June 27, 2018 4:13 PM
    • Proposed as answer by Firebolt Death Saturday, August 18, 2018 6:34 AM
    • Unproposed as answer by Firebolt Death Saturday, August 18, 2018 6:34 AM
    • Proposed as answer by Firebolt Death Saturday, August 18, 2018 6:34 AM
    • Unproposed as answer by Firebolt Death Saturday, August 18, 2018 6:34 AM
    • Proposed as answer by Firebolt Death Saturday, August 18, 2018 6:34 AM
    • Unproposed as answer by Firebolt Death Saturday, August 18, 2018 6:34 AM
    • Proposed as answer by Firebolt Death Saturday, August 18, 2018 6:34 AM
    • Unproposed as answer by Firebolt Death Saturday, August 18, 2018 6:34 AM
    • Proposed as answer by Firebolt Death Saturday, August 18, 2018 6:34 AM
    • Unproposed as answer by Firebolt Death Saturday, August 18, 2018 6:34 AM
    Thursday, June 21, 2018 11:09 AM
  • In code instead of void type int and instead of project1 type your windows form application name that you have typed and also type return o; after the step Application::Run(%form);


    • Proposed as answer by Sharath S.P Wednesday, June 27, 2018 4:16 PM
    • Edited by Sharath S.P Wednesday, June 27, 2018 4:51 PM
    Wednesday, June 27, 2018 4:16 PM
  • Look at his screen name, CD.  That person is biased against Microsoft.  Maybe he sells QT.
    Friday, August 24, 2018 4:43 PM
  • Thanks a lot!!! Concise and precise!

    Solved my issue!

    Friday, September 7, 2018 3:51 PM
  • Hello,

    1. How do I set the Entry Point: Main ? 

    I have no such choice so how do I set it manually?

    2. Also I get en error while debugging "There were build errors. Would you like to continue and run the last successful build?", and clicking yes throws this exception: "Unable to start program 'C:\\Users\User\source\repos\Project1\Debug\Project1.exe'. The system cannot find the file specified."



    Thursday, October 25, 2018 4:07 PM
  • I'm Also having the same issue, did you get it working?
    • Edited by JrLB02 Sunday, November 4, 2018 8:59 AM
    Sunday, November 4, 2018 8:59 AM
  • Thank you, been trying to work this one for ages.  Now have the answer and this solution works just fine.  Yes, I have used C# previously but the power and speed of C++ is fantastic and it was only the lack of forms control that stopped me doing anything serious in it.  Thanks again.

    Nigel..

    Friday, November 9, 2018 10:05 AM
  • not too keen on QT as it isn't 100% pure C++ anyway...

    Nigel..

    Friday, November 9, 2018 12:01 PM
  • I would look into QT as another person wrote but I needed a quick application and I worked with windows Forms before. There were a few things that needed to be changed in the code before it would work.

    when I right clicked on my project and changed properties under Advanced->Entry point I was only allowed to enter lower case so it was main NOT Main

    #include "(enter your form file name)"

    using namespace System;
    using namespace System::Windows::Forms;

    [STAThreadAttribute]
    void main(array<String^>^ args) {
    Application::EnableVisualStyles();
    Application::SetCompatibleTextRenderingDefault(false);
    (enter your form file name)::frmUpdater WCMCALUpdater;
    Application::Run(%(enter your form file name));
    }


    VB begin

    Monday, November 12, 2018 8:11 AM
  • Sir, everything was okey, but the code is not working for me.. i even don't understand what it says :(

    it says: 

    LNK2001 unresolved external symbol _main

    LNK1120 1 unresolved externals
    Monday, November 19, 2018 2:14 PM
  • step 5 not working. when I double click on MyForm.h instead of MyForm[design], MyForm is opened.
    Tuesday, November 20, 2018 5:03 PM
  • Hi everyone! 

    I was doing just like Stanly showed but I can not build solution. I was wondering if someone had that problem and managed to solve it.

    Error message: Element <SubSystem> has an invalid value of "Windows(/SUBSYSTEM:WINDOWS)".

    File: Microsoft.CppCommon.targets

    Line: 720

    If somebody would help me solve this problem it would be nice.

    Best regards

    Tuesday, December 25, 2018 11:30 AM
  • For those who can get it to work and/or have a compile error, try to type "main" in lower case in your form's cpp file (I cannot type upper case in the properties so my project never started the form.cpp). After that comment out the main project's cpp content or delete this file or you will have two mains declared in the project.

    It should compile and your form sould appear now.




    • Edited by Zouizoui Saturday, December 29, 2018 8:43 AM typo
    Saturday, December 29, 2018 8:34 AM
  • Worked for me!  Much Thanks!
    Sunday, February 3, 2019 10:17 PM
  • Worked for me fine. But x86 code only.

    Is it possible to use x64?

    Friday, February 8, 2019 1:29 AM
  • I couldn't get it to work either. Maybe I'll try out Embarcadero's C++ Builder (formerly Borland). Why on Earth would MS get rid of C++ support for building Windows apps? Not interested in C#.
    Friday, March 1, 2019 1:00 AM
  • If you can't reopen the Form in design mode, just reload the project and I'll work.
    Saturday, May 4, 2019 8:58 PM
  • (this is the right code copy it)

    using namespace System;
    using namespace System::Windows::Forms;

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

    Project1::MyForm form;
    Application::Run(% form);
    return 0;
    }

    • Proposed as answer by Haji Kurd Tuesday, May 28, 2019 12:56 AM
    Tuesday, May 28, 2019 12:55 AM
  • I have did all the steps as shown.
    But

    • I have change the name of the my project as "RailwayticketingSys"
    • Form name as "Railwayticketing"
    • and location to the Desktop.

    then when I press "Local Windows Debugger" it shows A error like this

    LNK2001    unresolved external symbol _main

    LNK1120    1 unresolved externals



    Wednesday, April 15, 2020 7:42 AM