Add gui to c++ project (visual studio 2010)

18,160

Solution 1

There are 2 types of native C++ ways of making a gui (using the win32 api); MFC, and straight API.

MFC has a lot of pre-made components and classes - what you did (adding a form to a regular project) didn't work since the project wasn't set up for MFC.

When you create a new win32 project (not mfc or console) - the methods used to create windows+such are more similar to a tutorial here. You can visually design your windows using this approach, embedding them in resources - but you'll need at least the professional version of visual studio to do that.

If you're just starting out with GUIs however - you'd be better off using something like wxWidgets

Solution 2

Not putting you down, but accept this fact - GUI programming in C++ is pain. Though I would suggest you to start with MFC based application, since it is nicely integrated with Visual Studio, and you need not to install any third party library. MSDN is also there - samples, umpteen examples on net is also available. You should start with Dialog-based application, VS has nice facilities to have GUI-MFC mapping.

Others may advice you to start off with QT, wxWigets, which are good options, but learning curve would be more and you'd simply get tired with issues you encounter. You will need to download, install and configure the stuff.

If you aren't faint hearted, you can start with native Windows GUI development - do everything from the core, which includes setting up the Window-structures, writing message-loop, the message-map (switch-case) and all.

Solution 3

  1. If type of your application was Console Application, the best way is to start over a new Win32 Application project (as you did)

  2. Win32 Application is clean WinAPI application, you are generally cannot construct main window graphically. You can try and create "Dialog Application" (afair it's some option in Win32 Application), but dialogs are not exactly the most versatile thing for a GUI.

If you're unfamiliar with WinAPI programming, you can start a separate question where you describe your requirements for GUI and your knowledge and people will suggest the tool/framework/approach.

Share:
18,160
DudiD
Author by

DudiD

Updated on June 04, 2022

Comments

  • DudiD
    DudiD almost 2 years
    1. I created a c++ project, and now I want to add a Graphical Interface to it. When I click on Project-->Add New Item, and choose to add Windows Form, it creates a header and source file but with a lot of errors such as:

      (problems with "public, privte, this - 'this' may only be used unside a nonstatic member function", "System",...) What are these problems? How can I make the form show when the project is run?

    2. When I open a new project "Win32 Application", all I see (and can edit) is the menu and dialog box...where can I go to see the main form??

    Thanks!

  • unkulunkulu
    unkulunkulu almost 13 years
    Oh, dialog app is available in MFC only? Used that too long ago :)
  • Moo-Juice
    Moo-Juice almost 13 years
    @unkulunkulu, The standard Win32 project (non-MFC) also creates a dialog proc, and dialog template resource. I only suggested MFC as the OP mentioned C++ :)
  • imre
    imre almost 13 years
    On the other hand, once wxWidgets is installed, I think it is easier to learn and use than MFC (probably the same is true for Qt).
  • Ajay
    Ajay almost 13 years
    I seriously cannot agree with you! Compiling, linking, distributing is painful.