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

Apianbelledev 21 Reputation points
2021-05-04T21:49:31.203+00:00

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++?

Developer technologies | Windows Forms
Developer technologies | C++
{count} votes

Accepted answer
  1. Jeanine Zhang-MSFT 11,356 Reputation points Microsoft External Staff
    2021-05-05T01:41:24.043+00:00

    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. **

    1 person found this answer helpful.
    0 comments No comments

1 additional answer

Sort by: Most helpful
  1. Apianbelledev 21 Reputation points
    2021-05-05T02:01:48.49+00:00

    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.

    0 comments No comments

Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.