question

Apianbelledev-7928 avatar image
0 Votes"
Apianbelledev-7928 asked Apianbelledev-7928 answered

is there any way to do C++ winforms with just code?

hi! I am a beginner in high-level C++ as I have only ever done low-level C++ and C and application scripting like in unity and unreal engine.

I have decided to create my game in just C++ with maybe a little bit of C code in there.



my question is this. is there any way to use WinForms with just code as you can in C#?

I have looked on the internet for many hours for this problem, and I would hate to come up short.

in C# a simple windows form is

 using System.Windows.Forms;
    
 namespace baseform
 {
     class Program
     {
         static void Main(string[] args)
         {
             Form baseform = new Form();
             Button mybutton = new Button()
             {
                 Text = "Quit",
                 Location = new System.Drawing.Point(10, 10)
             };
             mybutton.Click += (o, s) =>
             {
              MessageBox.Show("Quitting Application");
               Application.Exit();
             };
    
             baseform.Controls.Add(mybutton);
             baseform.ShowDialog();
    
             while (baseform.Created)
             {
    
             }
         }
     }
 }


how would I do this is C++?

c++windows-forms
· 1
5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

You could do the equivalent using C++/CLI but I wouldn't recommend doing so. If you want to use WinForms (.NET managed code), you're best off doing it in C#. C++/CLI is really for interfacing native C/C++ code to .NET.

If you want a native C/C++ UI, use MFC or the Win32 API.

0 Votes 0 ·
JeanineZhang-MSFT avatar image
1 Vote"
JeanineZhang-MSFT answered

Hi,

I agree with David. If you want to create a C++ windows forms application, I suggest you could try to use C++/cli. And you could follow the steps in the thread: Create C++ Windows Forms application in Visual Studio 2017

If you want to use c++ to create a window interface similar to winform. I would suggest you use MFC or Win32.
I suggest you could refer to the following Docs:
Creating a Window
MFC Desktop Applications

Best Regards,

Jeanine



If the response is helpful, please click "Accept Answer" and upvote it.

Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.


5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

Apianbelledev-7928 avatar image
0 Votes"
Apianbelledev-7928 answered

after some careful consideration, I have decided to use the WIN32 API. Thanks for all the answers.

I'll also be learning C# and learning WinForms in .NET while learning all I can about WIN32.

5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.