Reputation: 215
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?
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!
Upvotes: 3
Views: 18646
Reputation: 18431
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.
Upvotes: 2
Reputation: 3873
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
Upvotes: 3
Reputation: 11922
If type of your application was Console Application, the best way is to start over a new Win32 Application project (as you did)
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.
Upvotes: 1
Reputation: 38820
It would be far easier to start a new project, and select "MFC Application" as the application type. The project will then be properly configured for you. You can choose to have a dialog application (the main window is a single dialog box, or "form" if you're used to .NET), a single-document application (ala notepad), or an MDI document application (ala Visual Studio).
Upvotes: 0