Examples of win32 Gui code?

Started by
11 comments, last by RobTheBloke 8 years, 7 months ago

I'll second Qt here. Its excellent if you want to build GUI programs. Win32 API can be used to achieve the same results, but it is painful, error-prone and takes an enormous amount of effort. The only real gain is that you don't end up with a large set of dependencies, so I use it for games to make a window and respond to basic window messages, but I'd never want to use it to write a GUI-based program again.

The problem with Win32 is it has to be backwards compatible and is essentially a C-based library. Most of the interactions you have with controls are via sending messages using SendMessage, which then require casting of all the various parameters to the WPARAM and LPARAM types so you essentially throw away the type-safety we are all used to these days and have to be incredibly careful that you know what you are doing.

But, yes, it is possible, of course.

Qt sort of extends C++ with its meta-object compiler system (the main reason I suspect Servant said it was easier to work with QtCreator although you can work around this) and adds a generic SIGNALS/SLOTS system that is then used to communicate between controls, which is a real boon. This is improved further in Qt 5 I believe to start using more native C++ to achieve this, although they still have the MOC.

Oh, and your last question, it is indeed possible to write any type of program with Qt. Qt is divided into modules, so you can write a command-line program just using QtCore, a GUI application using QtCore and QtGui, and there are a bunch of other modules you can mix and match as you see fit (QtXml, QtWebKit etc).

Can seem a bit daunting setting it all up for the first time, but once you are up, running and comfortable, if you are anything like me you'll never look back. I learned to use it for work, but within months I'd scrapped and rewritten my 3D modelling software (previously in Win32) in Qt from the ground up.

My Qt-based application: http://www.gamedev.net/gallery/image/6633-charm/

I'm using Direct3D 9.0c to do the actual rendering in there because I'm a bit of a dinosaur but it was fairly easy to host a D3D window inside a Qt Widget (obviously I don't have any cross-platform ability now on this project as a result).

And if you use Qt throughout without falling back on any Windows-only libraries, you essentially have cross-platform for as close to free as you are ever going to get, since Qt will work on Linux, Mac etc.

Advertisement

^-- what Aardvark said. smile.png

So you made that whole program using Qt?

Yes. The main window in the middle is OpenGL (exposed by Qt), but the rest is Qt.

Is all of the logic behind the scenes c++?

Yes.

So with QT it doesn't have to look like a typical windows program (for which I think of something like winRAR looks like...). Can the same effect be achieved with just the Win 32 API?

Win32 and Qt both allow the use of "normal" Windows programs, and also allow great customization to make programs look however you want.

Qt just makes it easier to do, while also being cross-platform.

Qt is the way to go in the long run. If it's a quick and dirty gui you want (over a simple tool), a windows forms GUI that calls a C++ command line app is hard to beat. (Effectively the gui just builds up the command line args)

This topic is closed to new replies.

Advertisement