How to get started with Winforms style applications on Win32?

A bit of background: I'm mostly a C ++ programmer, but the only GUI I've ever made was on top of the .NET WinForms platform. I'm completely new to Windows GUI programming, and despite Petzold's excellent book, I'm very confused.

Namely, it seems that most of the links to getting started with Win32 - this is drawing lines and curves and things - a topic that (at least for the time being) I don't care about.

I need a window with a verified list, a splitter and a text box - something that would take Winforms on Earth for less than 10 minutes. I was encouraged to use the WTL library, which provides the implementation of all three of these controls, but I keep focusing on simple things, such as getting controls to use the correct font , and getting the right DPI . I spent two days on this, and I cannot help but think that there should be a better reference to such things that I could find. Petzold's book is good, but it has not been updated since Windows 95 days, and LOT has been changed by wrt as applications should be properly developed from the moment of its publication.

I guess I'm looking for a modern Petzold book. Where can I find such a resource, if any?

+6
c ++ user-interface windows
source share
3 answers

First, there is virtually no documentation (which I will ever find) explaining how to use WTL. It seems to be a library of experts, for experts.

Now your options: use the MFC application wizard to create an application or navigate the Win32 API path. The Win32 API itself is the C API, MFC is the C ++ wrapper around the C Win32 API with the addition of an application model for viewing documents.

However, instead of creating your controls from code: the closest analogue of the native Windows API to "WinForm" is a dialog box. Dialogs are placed in resource files that are embedded during binding in the EXE or DLL that you are developing. The dialog resource accepts a font parameter, which is automatically applied to all controls in the dialog box, and dialogs are laid out in terms of dialog blocks, not pixels, which allows them to automatically scale relative to the font face and dpi settings in the user system.

If you create a dialog resource and add it to a simple application, it does not need to get complicated to get the dialogue on the screen and close it in response to the click of the OK button.

#include <windows.h> #include "resource.h" BOOL CALLBACK MyDialogProc(HWND hwnd,UINT uMsg,WPARAM wParam,LPARAM lParam) { switch(uMsg){ case WM_INITDIALOG: return TRUE; case WM_COMMAND: switch(LOWORD(wParam){ case IDOK: EndDialog(hwnd,wParam); } return TRUE; } return FALSE; } int CALLBACK WinMain(HINSTANCE hInstance, HINSTANCE hNull,LPCTSTR strCmdLine,int nCmdShow) { return DialogBoxParam(hInstance,MAKEINTRESOURCE(IDD_DIALOG1),NULL,&DialogProc,0l); } 
+4
source share

There are definitely better ways. Firstly, it’s expected that some sophisticated and interesting features will appear on today's Windows applications. If you plan to implement all this from scratch, you will spend a lot of time on your project.

Personally, I use MFC. Other options are valid, but I would really doubt that I use anything at all in the library. Especially when you use types of problems.

Can you place them in a dialog box, or are you doing something unusual in a regular window? Typically, most controls are created by overlaying them on the dialog box constructor. No need to mess around with the right font.

Can you go through what you are trying to do and the problems you see?

+2
source share

The Win32 API exacerbates the difficulty of using directly, so no. Most people use some graphical interfaces. I am trying to give my personal opinion on more popular options:

  • WTL . This is too thin a layer on the Win32 API and has not been updated for many decades. You will soon come across the Win32 API if you try to do something over simple stock examples with it. The bonus is that it is extremely fast compared to the competition.
  • MFC Since VS 2008 SP1 MFC allows you to make a relatively modern look GUI. If you can live with your strange coding agreement and heavy macro then it is liveable. It is supported by the VS IDE, but much weaker than WinForms.
  • WxWidgets . Initially, it was a bit like the MFC, which is additionally portable. It got a lot better after people started using it in Python.
  • QT . These are most flexible and powerful ones. Unfortunately, it began a long time ago so it has some legacy of strangeness in it. It is slow in places and creates large executables. It is best to use it as a well-insulated GUI layer and not mix the intensive use of STL and increase the level of this layer.
+2
source share

All Articles