Modern, native way of creating WinAPI GUI apps in C++ [closed] - c++

Closed. This question is opinion-based. It is not currently accepting answers.
Want to improve this question? Update the question so it can be answered with facts and citations by editing this post.
Closed 7 years ago.
Improve this question
First, I know this is kind of common question, but I could not find the exact answer I am looking for.
I have done many projects in Java using Swing. Starting by just coding the GUI, then later moving onto GUI designers. This proved to be a very quick and easy way to build GUI apps.
But now, I need to move to C++. I am beginning a project which uses a lot of HW resources (DirectX, OpenCV, etc...) I know there are Java libraries for these technologies. However, C++ is definitely the right way to go, considering the internals of this project.
I know C and C++ languages well from MCU programming. Also, I have read many articles on native WinAPI programming, Windows internals, etc. I think I have enough knowledge to start. I don´t want to worry much about GUI design, but it must look appropriate.
I know there are few basic options: Pure WinAPI, MFC, WTL, Qt... I would be very glad if there were some kind of GUI designer tool, but from my research, there is not. There is the MFC wizard which helps to create a basic window, but it is not a designer. The closest thing I found was Qt. But from what I read, it is not using WinAPI for drawing, for in future look and feel of Qt written app can differ from native Windows look.
So, to summarize, please, if you are experienced with creating native Windows C++ Apps with GUI, what would you recommend to me? Specifically, is there any tool or designer I missed?
(I am using Visual Studio 2010 professional, since I have it free thanks to the DreamSpark project)

I recently used Qt4 and was very pleased with the API. I found it straightforward, well documented, and the code is extremely concise.
Qt does an extremely good job of emulating the target OS look and feel (as #In silico pointed out in the comments, Qt actually draws everything itself and does not use native components) Regardless, this can be coded by hand or visually through the GUI editor in their IDE, Qt Creator. If you go this route, I recommend creating your initial GUI project (.pro file) there, then importing it into Visual Studio via the Qt Visual Studio Add-In.
Slots and signals, Qt's event/messaging system, is also worth mentioning. Yes, it's critical to GUI programming, but could also be extremely useful in lower-level code.
I expect Qt would work well in your project, but as always, create a few simple tests to ensure the technologies will work together feasibly.

Here are a few hints:
Don't lock yourself into C++. C# and Java (for instance) can be easily interop'ed with C/C++. (Through PInvoke or C++/CLI for the former and JNI for the later). C++ may not be the ideal language to write a GUI quickly.
Your requirement for "native windows look" is arbitrary and you should think it over. Is that really what you need ?
Winforms. It's an older technology but is still widely used. You use the API from C++/CLI or C# (or any .NET) language.
WPF, a more recent API but that will be harder to deal with from C++, (better with C# or VB)
One of the many GUI toolkit available on the market that have a C or C++ API (QT, GTK, wxWidgets, the VCL, ... list here). Some have "native" looks, some don't. Some have designers some don't. Some are free, some aren't.

If you need simple user interface i recommend use WTL - is simple, lightweight, header-only library, very good wrapper over WinAPI. In Visual Studio you can use form designer for creating windows and use WTL classes for implement interaction with user. WTL have poor documentation but WTL is looking like MFC.
If you want rich possibilities i recommend use Qt. It's very powerful GUI framework with great community.

You can use the C++Builder XE2 (Part of the Rad Studio IDE), which includes the VCL (Visual Component Library), the VCL is a wrapper over the Windows controls (and also includes custom controls) which increase the development productivity.

The wxWidgets c++ class library comes with a screen builder.

VCL is a good way to go. It has a GUI designer tool (Embarcadero Rad Studio XE6) fully native gui developer for C++ and Delphi

Depending on how strict your definition is, you could use .NET Windows Forms or Windows Presentation Foundation and plug logic in from C++, C++/CLI, and C#. That would not be a pure C++ solution. In fact, I wouldn't even necessarily advise using C++ in that situation. Simply using C# would be more intuitive and maintainable. WinForms and WPF have pretty awesome GUI designers though.

Related

Need help understanding c++ windows for a Java guy [closed]

Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 8 years ago.
Improve this question
Thing is I'm learning how develop Win32 applications in C++. I'm using Visual Studio and windows.h and I'm having a bad time.
I come from Java and Android, where you create a class like MainWindow or OptionsWindow and then you write inside the behavior and instantiate them whenever you want.
But now I'm in C++ and I'm lost.
All examples I see with windows.h library are codes where Main is WinMain inside the window. So, here's is my question: Is there any way where you write different classes for different windows and instantiate them when you need it? something like
OptionWindow ow = new OptionWindow
Or should I write all the code of every window I will need inside the WinMain and then make it visible?
Help Is much appreciated. Thanks.
If you are committed to using just C++, I'd recommend creating a C++/MFC Application with VS2013. Microsoft Foundation Classes (MFC) was a framework that hides much of the drudgery of creating and manipulating windows. It is much easier to get started with than raw Win32 programming.
MSDN has a number of tutorials and articles that may help you get started. I also found this reasonable step-by-step guide to MFC programming. If you search for MFC Programming you should find a fair amount of information/code/examples.
Since you are using Visual Studio 2013 one suggestion by commenters isn't applicable to you. There is a suggestion you could use C++/CLI (it is effectively .NET C++). C++/CLI is often a shim that is used as a gateway for C++ developer migrating to C#. Microsoft no longer supports Winforms through the IDE for C++/CLI applications. There is no longer a Winforms application project for C++/CLI either. If you have VS2010 winforms is availale through the IDE.
If you are writing a GUI and don't wish to use MFC with C++ I would recommend jumping to C#. Find a good book on the subject. Microsoft has an online guide that is for Java developers migrating to C#.
Based on the OPs comment that he'd like to do things more programatically. There is a solution that was created by Microsoft and is still maintained by the open source community. That option is Windows Template Library (WTL). I personally still use it for light weight applications where I don't want to overhead of MFC. It is a set of Windows templates that sit a top ATL (Active Template Library). ATL was originally designed as a set of C++ templates to build reusable binary components using COM.
You can add WTL to VS2013 (it is not part of standard Visual Studio anymore). You can download WTL from http://sourceforge.net/projects/wtl/ . Installation is not straight forward but it does work once installed properly.
Winapi uses a plain C interface, so there are no premade classes available.
If you want to write .net Applications in C++ you can use wpf (Windows Presentation Foundation) or winforms as huseyin wrote in his comment.
If you want to develop native win32/64 applications you have to use a library/framework. Microsoft has the MFC (Microsoft Foundation Classes), but IMHO they are complicated and thus don't like them.
You also could have a look at cross-platform frameworks as qt, gtk or wxWidgets. However there you have to take care the license (qt is available as GPL, LGPL or a commercial license, so you either have to buy developer licenses, put your code also under the GPL or comply with the LGPL).

Advantages of Windows API for C++ GUI Programming [closed]

Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 8 years ago.
Improve this question
I started C++ programming not long before and I want to learn GUI programming in C++. I looked at windows programming and the syntax looks really difficult. So my question is, should I use windows api at all? If so, what are the advantages of windows api over a toolkit like Qt or Direct2D?
It somewhat depends what sort of application you are trying to build. Most frameworks provide a level of abstraction over the Windows API but do so at the cost of flexibility. You should try and pick a framework that's designed to build the sort of application that you are trying to build.
For building Windows client applications then the Windows API (I assume you mean the Win32 API) will do the job but is very low level. The advantage is it gives you a great deal of control and also forces you to learn how a Windows application really works. For a lot of people these aren't always positives.
If you are trying to create a more graphically rich application then Direct2D gives you this but also means that you have to learn COM and some would say this API is also quite complex.
If you are just learning C++ and want to build simple graphical applications then I would recommend checking out Cinder. It's perfectly possible to build simple graphically rich applications and games in a few hundred lines of C++. Here's an example of the Conway's Game of Life written in a couple of hundred lines.
Qt is also an option but I've not used it. Again it depends on you goal. For example one of Qt's features is cross platform portability, which may, or may not be important if you are just starting out with C++.
If you are just creating some projects for your own learning, then I would suggest that you create some GUI using Windows API without any framework. This will help you learn the internals on how things work (messaging, etc).
But to make any real world project you must choose existing framework (MFC, Qt etc) so that you can save a lot of time. You will understand the framework better if you create some GUI projects with plain Windows API SDK.
If you platform is only Windows, then you can in fact develop faster using .Net Framework. Of course there is also Xamarin that will allow you to write in C# for cross platform.
So what you choose depends on your goals.
With WinAPI you can use all Windows GUI features, controls, styles, respond to some rarely used messages etc.
It's easier to achieve native Windows look&feel.
Higher-lever GUI libraries, especially multiplatform ones, are usually "least common denominator", limited in many ways, with some controls (e.g. dialogs) reinvented just for the sake of it. You can patch your code with WinAPI calls, but that quickly turns into spaghetti.
For one, tools like Qt, OGRE, OSG, OpenGL etc are cross-platform. So you won't be stuck with using your program only on Windows.
If by windows API you meant VC++ with WM_PAINT etc, then it's worth learning it only for the sake of knowledge about how Windows works. The parts about dirty rectangles etc will intrigue you.
"I started C++ programming not long before.." - so I would advise to start with well-documented library such as QT. You'll have much to learn in C++ itself and to learn WinAPI at the same time will be twice (or more) difficult.
The answer in general depends on the requirements, and if you want to learn "GUI programming in C++" I'd say it means QT (or some other library/framework). I do not know any rich GUI projects now which are written on pure WinAPI (what for?). (If smb knows, please put a link here.)
But you can ask yourself another question - you want to learn C++ or GUI programming? :)

What is the best way to get started in GUI C++ programming?

So, I learned C++ (fundamentals) and I want to write software, however I have stumbled upon a problem where I don't know where to get started. It seems like learning C++ was the easiest part by far when it comes to understanding the libraries for the GUI construction the concept I yet don't fully comprehend. I searched a lot and couldn't even decide been a new guy on MFC, Win32 or Qt.
Qt C++ GUI seems like a fun and easy to use software with the definitions of classes available right there quickly.
With Visual's MFC I am seeing a lot of code upfront on the pre made project file and a lot of description of classes, however getting definitions is a bit slower as I have to go to the internet.
Win32 is apparently written in C and is not updated much?
A lot of people recommend Java and C# as well, but I am not interested in learning a new language when I don't have C++ set in stone and practiced with enough yet.
Not sure how to go about this.
Go with Qt if you envision porting your program to platforms other than Windows and/or your actual UI needs are relatively straightforward. But Qt, being "fun," abstracts you away from the Windows API, so if you find yourself needing to access features of that API not offered by Qt, then you'll be up the creek. So go with MFC if you're staying on Windows and you're building an application whose complexity or Windows-specific features may require more direct access to the Windows API. MFC provides a thin abstraction layer over that API; its concepts map more or less one-to-one with the API's concepts.
What kind of GUI do you want? Any framework should be able to do any kind of GUI, but some are optimized for certain work:
MFC is optimized for making applications that edit documents, like MS Office programs Word, Excel, Powerpoint.
wxWidgets and Qt (and .NET WinForms and WPF) are optimized for any sort of app that primarily uses widgets (textboxes, buttons, menus).
SDL is optimized if you want to draw stuff, like graphs or vector artwork.
I wouldn't recommend that you use MFC since it isn't a good fit for most applications, and also doesn't use modern C++ design, it's loaded with workarounds needed for stuff that was broken in early versions of Visual C++ and now can't shake those workarounds because of backward compatibility.
The Win32 API is actually really useful to know regardless of what kind of application you want to make, because it defines the rules for how the UI interfaces to the rest of the system. Yes, it's written in C, but this is to make it usable from any programming language, not because it's an obsolete design. Win32 API is highly object-oriented and uses polymorphism extensively.
Few things you need to be aware of:
If one day you want to sell a program written using Qt you might need to purchase a license.
If you feel like GUI applications/ GUI programming is what you want to do in general, for windows platform you better learn WinForms or even better WPF (with C# of course).
If you just want to quickly put up simple GUIs for your C++ programs for learning purposes, and you don't care much about learning the frameworks and licensing issues, just go with Qt or wxWidgets.
MFC is outdated. If sticking with C++ on Windows, I recommend you to lean C++ CLI.
However I suggest you to learn c# directly since c# is the mainstream language in .Net world.
For GUI, the windows world is now dominated by WPF.

Windows GUI applications in VisualStudio

What are the valid ways to write (hopefully native) C++ applications with GUI in VS 2010?
I remember some 10 years ago I was using MFC, any big changes today?
If you want to stay with Native API then MFC is still a good choice or plain Win32 API.
There are new controls like the ribbon control introduced in VS2010. There's a tutorial on native development with VS2010 on MSDN. There are also a lot of C++0x features available to your native program if you're using VS2010.
Qt is another good choice even if you aren't going cross platform but you won't be using VS 2010 most likely in that case. The licensing is now free for commercial use with LGPL.
If you are going to use a newer framework like WPF from Microsoft then you will need to use a managed language (.NET). Another choice is Silverlight for both web and apps. Silverlight apps have the advantage that you can get them to work even on Mac if they have Silverlight installed. Winforms is still easy to code but mostly superseded by WPF.
Unless you have good reason to do so, you can develop much faster with a framework like WPF instead of MFC. Even if you don't know a managed language. (If you don't go straight to C# instead of C++/CLI). WPF also offers GPU acceleration.
You can use Windows Forms, or Windows Presentation Foundation (WPF) - in VS2010 you can use either of these to create apps with a GUI. In terms of which would be the best - I suppose that depends on your specific needs, but I couldn't say as I've only really used WinForms. However, WPF apps seem to have more components for you to use.
Just for completeness - not advocating it, wxWidgets is a cross-platform GUI toolset.
If you really want native, and you really want C++, your best option is WX. MFC has some nice controls and such but still lacks any semblance of a complete UI library. It lacks any layout managers, period and still suffers from being a basic wrapper to the win32 C API. WX has some of this latter issue as well but has been cleaned up considerably from MFC and has layout managers.
A couple other options:
You could break out of C++ and go with one of the .NET languages to use other, better native libraries.
You could use a cross-platform library that'll still have the look and feel of the native toolkits, like Qt or GTKmm.

Which Windows GUI system should I choose with C++? [closed]

Closed. This question is opinion-based. It is not currently accepting answers.
Want to improve this question? Update the question so it can be answered with facts and citations by editing this post.
Closed 7 years ago.
Improve this question
There are now so many ways to write windows apps, win32, MFC, ATL, .NET, WinForms, and probably some others that I don't know of. Which one should I choose? I'd like one that works on a fresh install of Vista, and is modern and easy to use.
I highly recommend Qt. It's cross-platform, very easy to use and LGPL licensed.
If you are amateur with C++ you'll have much easier time learning WinForms than any of the native Visual C++ frameworks (Win32, MVC, etc.). WPF will give you best versatily. It's a bit harder to master than WinForms but managed and so keeps you away from the nasty Win32 stuff.
The native frameworks are good mainly if you want to crunch the last bits of performance or need to keep the footprint small for stuff such as shell extensions.
I'd recommend checking WinForms at least first to get some quick understanding of the principles. If WinForms doesn't suit you, you can then move to either C++ if you feel you need more low level control or WPF if you wish more shiny features like skinning and theming.
Edit:
Though if you have a look at WPF, remember that fresh Vista contains only .Net 3.0 so 3.5 and 3.5 SP1 features require a separate runtime installation.
actuallly it's very easy to start with Qt - you get a complete SDK incl. a very nice IDE as a simple package and a smart integration into VisualStudio.
Plus the LGPL licensing which allows anybody to write opensource and closed source/commercial apps without paying any fees - the commercial support/licenses are optionally!
The biggest advantage of Qt is the very easy to learn and very very clean C++ API, which can do more than just building GUI apps (it supports low leven networking and file io etc.).
Best regards,
Chris
Short answer... It depends.
Whats your skillset/background? Why are you developing a desktop app? Is it for work or as an experiment for you to learn something new? Will there be multiple other developers working on it and whats they're skillset?
My personal preference would be winforms because that's what I spend most time coding in (in C#). They're very quick to put together and the VS IDE is very quick & stable for building the UI elements of your application. And you can publish/deploy them using Click Once which allows easy updating of the clients when you make changes & updates.
Alternatively, you might want to look at WPF which is the new Presentation Foundation in .NET 3.5. This will allow you to leverage a newer "shinier" UI experience for desktop applications.
Straight up Win32 is getting better with the Scenic Ribbon. Will work on Vista and Windows 7.
I'm probably biased (aren't we all?), but since your question states you're interested in Windows development and you want a modern and easy to use GUI framework that's works with Vista out of the box, the obvious answer is .NET WinForms.
I personally prefer gtkmm. Although it doesn't look as good as Qt or the native frameworks on Windows, I think the API is the most transparent among all frameworks I tried. It feels very OOish, and is very easy to learn. You can easily create GUI layouts with Glade, but you can also create decent designs with nothing but code. In this regard, gtkmm is similar to Java GUI programming.
I would recommend WxWidgets. The API is easy to understand; it is very well documented with samples; and it is cross-platform. If you are programming an application that is going to have any a large number of users, you will eventually want to have the option of running it on a different operating system. By choosing a Microsoft only API you will permanently put yourself into the Microsoft corner. Getting out will require a serious refactoring of your software which will require that you learn yet another API. Take my advice and start with a cross-platform API - it will save you a lot of grief in the future.
I would recommend C++Builder 2009, which can create applications that work with Windows 2000, XP and Vista.
If you go the Microsoft route, be sure to check which frameworks they are putting the most muscle behind lately. For instance, MFC is an older framework that should NOT be used for new development because MS isn't putting any time into it, and the marketplace for add-on MFC components has dried up and blown away.
Basically, when choosing MS backed technology, make sure you pick one that isn't already on the outs.
So you're a student with only PHP knowledge? Well before even considering a GUI you'll need to come up to speed in a proper language. I would suggest C# as you are already used to curly braces and you want to program Windows. WinForms is part of .Net, not a separate thing. Just download Visual Studio 2008 Express and you're up and running. By the way, GUI programming can be hard in any language, especially after you move past the stage of toy programs to real apps.
If you knew C++ to a higher degree I would have suggested Qt. Simply because the new LGPL licensing removes the final impediment. It's also cross-platform, high quality, high performance and now has the financial backing of a huge company (Nokia) to ensure further development.