Windows Programming

Started by
13 comments, last by Glass_Knife 9 years, 7 months ago

Hi Guys,

Just wondering if I am looking to make some tools for WIndows (3d editor, particle editor) is the Charles Petzold book still the best thing to go by?

Not interest in Windows 8 programming, just xp 7.

Thanks

Advertisement

For the types of tools you mention, as they appear to have little to do with the Windows API, Petzold's likely to be as good as any for bitmaps, etc.

You don't mention what sort of 3D objects you may want to code an editor for, but there are probably better options than the Windows API for that purpose - e.g., an existing 3D editor such as Blender, etc. Unless your intent is for intellectual exercise and you really want to code your own "tool," something like OpenGL or Direct3D may be a better choice.

Please don't PM me with questions. Post them in the forums for everyone's benefit, and I can embarrass myself publicly.

You don't forget how to play when you grow old; you grow old when you forget how to play.

If you are asking about how to make GUIs for desktop applications, I really like Qt.

Here's a screenshot of a 2D tile-based editor I'm working on using Qt. The center of the editor uses a different API for drawing (SFML and OpenGL); you can make widgets be OpenGL-drawn as well as have Qt-drawn widgets.

Qt is also cross-platform for Windows, OSX, and Linux. Supposedly it's also recently gained cross-platformness for iOS and Android, but I'm not sure how well it works.

Petzold's Programming Windows, 5th Edition is still kind of the de-facto standard for basic C Win32 coding, though he's not going to cover anything added to Windows since XP or so due to the age of the book. Note that the sixth edition of the same book is Windows 8 Modern UI only which, IMHO, is a mistake where he should have just called it a new book rather then a new edition cause of all the confusion it will cause.

Outside of that, MSDN is a good Win32 reference, though it won't usually help you with the big picture it can help you do certain things once you have a basic idea of what you want. Though a lot of more modern features require a basic knowledge of how to use COM.

You can, of course, skip all that using UI frameworks like MFC (yes, it's still relevant and up-to-date for C++ coders), Windows Forms or WPF (for .NET languages), or third party libraries like the aforementioned Qt.

If you are going to do 3d stuff you're probably also going to have to integrate DirectX or OpenGL, as none of these frameworks support accelerated 3d rendering (Qt might, I'm not familiar with it). WPF can handle some 2d stuff rather competently, but it's more geared for vector work over bitmap.
Pure Win32 or pure X11/POSIX are not good choices for building UIs, especially for tools. Seriously consider using a higher-level tool like Qt. Having built-in events, MVC, and so on will make a huge difference in the quality of your tools

Sean Middleditch – Game Systems Engineer – Join my team!

Thanks for the information guys. I had worked on some tools back in the day but it was a combination of win32 and directx. I will look into some of the things you suggest like QT.

It is mainly as a hobbyist thing on the side. The one thing that I've always disliked is having to rely on learning someone else's tool, someone else's file format, and just when I get stuck on something having to wait for response or not getting a response.

Also when I say 3d editor it would be the standard 3 2d windows with one 3d window. There are other options, but I've always wanted to make my own as mentioned above :).

Thanks Guys :)

If your tool is Windows only, you might consider using C# and winforms (or possibly even WPF). It's a much nicer language than C++ to build UIs in and you can still interface with your C++ engine code easily enough using C++/CLI.

if you think programming is like sex, you probably haven't done much of either.-------------- - capn_midnight

If you are asking about how to make GUIs for desktop applications, I really like Qt.

Here's a screenshot of a 2D tile-based editor I'm working on using Qt. The center of the editor uses a different API for drawing (SFML and OpenGL); you can make widgets be OpenGL-drawn as well as have Qt-drawn widgets.

Qt is also cross-platform for Windows, OSX, and Linux. Supposedly it's also recently gained cross-platformness for iOS and Android, but I'm not sure how well it works.

If you don't stop talking about how awesome Qt is, I may have to start using it. I didn't realize it had a built-in GUI API. Is that something like Swing for C++? And how does it do on the cross-platform issues like Look-and-Feel and input handling?

This is me getting Qt and QtCreator confused. But I wasn't thinking about the Qt GUI stuff being enabled with QtCreator. Looks like some powerful stuff.

I think, therefore I am. I think? - "George Carlin"
My Website: Indie Game Programming

My Twitter: https://twitter.com/indieprogram

My Book: http://amzn.com/1305076532

If you are asking about how to make GUIs for desktop applications, I really like Qt.

Here's a screenshot of a 2D tile-based editor I'm working on using Qt. The center of the editor uses a different API for drawing (SFML and OpenGL); you can make widgets be OpenGL-drawn as well as have Qt-drawn widgets.

Qt is also cross-platform for Windows, OSX, and Linux. Supposedly it's also recently gained cross-platformness for iOS and Android, but I'm not sure how well it works.


If you don't stop talking about how awesome Qt is, I may have to start using it. I didn't realize it had a built-in GUI API. Is that something like Swing for C++? And how does it do on the cross-platform issues like Look-and-Feel and input handling?

This is me getting Qt and QtCreator confused. But I wasn't thinking about the Qt GUI stuff being enabled with QtCreator. Looks like some powerful stuff.


No GUI API is going to actually get you a true "native" UI feel without you doing some work to design your menus, layouts, etc to match the desired platform. The most they can do is abstract away the particulars of how common controls work and possibly shore up holes in particular platforms with custom controls.

For example, on a OSX your menu bar is at the top of the screen and child windows float freely, whereas in Windows the menu bar is at the top of the main window with child windows constrained to the parent window's bounds (for an MDI program). Another example is that OSX uses a "Quit" menu option to leave a program, whereas Windows will use "Exit".

As far as I understand it, Qt will implement the UI using native controls, which helps match the look-and-feel of the host OS, whereas something like Swing doesn't even try and will use custom controls for everything with an intent of keeping the program's look consistent, even if it drastically mismatches the host.

If you don't stop talking about how awesome Qt is, I may have to start using it. I didn't realize it had a built-in GUI API. Is that something like Swing for C++? And how does it do on the cross-platform issues like Look-and-Feel and input handling?

There's the Qt libraries, and then later on they made QtCreator, which is an IDE (a really good one, as far as non-Visual Studio IDEs go), that includes things like a great GUI wizard builder. Qt can supposedly be used with other IDEs like Visual Studio, but it may require jumping through some hoops to get it working (they run a preprocessor on parts of the .cpp files to enable some features).

Qt (the API, which pre-dates the IDE) includes a huge number of cross-platform libraries using a consistent interface, kinda like Boost, but is most famous for it's GUI stuff. Apart from using the wizard, you can also easily create the GUIs programmatically, either manually positioning widgets, or (a better idea) using nested 'layouts', to automatically organize widgets horizontally, vertically, in grids, or so on.

Qt Layout Management


QWidget *window = new QWidget;
QPushButton *button1 = new QPushButton("One");
QPushButton *button2 = new QPushButton("Two");
QPushButton *button3 = new QPushButton("Three");
QPushButton *button4 = new QPushButton("Four");
QPushButton *button5 = new QPushButton("Five");

QHBoxLayout *layout = new QHBoxLayout;
layout->addWidget(button1);
layout->addWidget(button2);
layout->addWidget(button3);
layout->addWidget(button4);
layout->addWidget(button5);

window->setLayout(layout);
window->show();

(Note: Qt uses alot of calls to 'new', but manages the pointers to free them, so you use few, if any, calls to 'delete'.

In this example, 'window' will end up owning the pointers to the QPushButtons, because 'window' becomes their parent)

Cross-platform look-and-feel is handled by "styles". The widgets are often native widgets (so you can do things like get the HWND on Windows, if needed), and look native on whatever platform you are on, by Qt choosing, at runtime, the proper style without you doing anything. However, you can also tell Qt to use a specific style if you want.
qstyle-comboboxes.png

Some of the layouts and widgets also rearrange things automaticly (which you can override) for different platforms - like placing OSX 'Ok' and 'Cancel' buttons in the proper location compared to Window's 'OK' and 'Cancel' buttons.

In addition to overall application 'styles', which can be difficult to customize, each individual widget can be styled using a domain-specific language called 'style sheets', inspired by CSS (but nowhere near as unwieldy and butchered as CSS) to theme things exactly as you want. I'm not a fan of CSS, but I like Qt's stylesheets.

In the screenshot I previously posted, the top tabbar/filemenu and the toolbar at the bottom are examples of where I used stylesheets to make them look 20% cooler. Also note that the "Notes" button in the lower-right is different (in appearance only) from the native Windows-themed buttons half an inch above it. Both are QPushButtons. Same as the icon-only and icon-and-text buttons on the bottom bar - all are QPushButtons by styled different and optionally assigned icons.

Here's a screenshot I manually touched up a month or so ago, showing how I use different drawing techniques for different parts of the editor.

And, ofcourse, you can have custom QWidget-derived widgets that uses Qt's QPainter class to draw it manually, or you can use OpenGL or DirectX to draw one or more widgets.

The only downside is, Qt works well for desktop applications like game editors, but isn't fast enough for things like 3D or 2D games that require smooth motions and high framerates. Qt is fast and responsive, but most of the frametime is stolen by Qt itself, so my 2D RPG won't be compiled with Qt, just SFML (OpenGL under the hood), but my editor is made in Qt, using SFML (and OpenGL) to draw the game view.

Qt uses signals-and-slots for sending messages between widgets (which works very well, but took me some time to get used to), and widgets also have virtual event functions that can be overridden for things like mouse movement, drag-and-drop, or repainting events.

Qt has a bit of a learning curve, since there are so many features and the libraries are so huge, but you can knock up GUI interfaces very quickly, either for mock-ups or for actual applications, so you can focus on coding the actual features behind the UI (or you can waste hours nitpicking your interface to make it look "cooler" like I do, instead of getting actual work done. laugh.png).

This topic is closed to new replies.

Advertisement