The Old New Thing

Using the powers of mathematics to simplify multi-level comparisons

What a boring title. Often you'll find yourself needing to perform a multi-level comparison. The most common example of this is performing a version check when there are major and minor version numbers involved. Bad version number checks are one of the most common sources of errors. If you're comparing version numbers, you can use the ...
Comments are closed.0 0
Code

The dialog manager, part 8: Custom navigation in dialog boxes

Some dialog boxes contain custom navigation that goes beyond what the IsDialogMessage function provides. For example, property sheets use Ctrl+Tab and Ctrl+Shift+Tab to change pages within the property sheet. Remember the core of the dialog loop: while (<dialog still active> && GetMessage(&msg, NULL, 0, 0, 0)) { ...
Comments are closed.0 0
Code

The dialog manager, part 7: More subtleties in message loops

Last time, we solved the problem with the EndManualModalDialog function by posting a harmless message. Today, we're going to solve the problem in an entirely different way. The idea here is to make sure the modal message loop regains control, even if all that happened were incoming sent messages, so that it can detect that the fEnded flag ...
Comments are closed.0 0
Code

The dialog manager, part 6: Subtleties in message loops

Last time, I left you with a homework exercise: Find the subtle bug in the interaction between EndManualModalDialog and the modal message loop. The subtlety is that EndManualModalDialog sets some flags but does nothing to force the message loop to notice that the flag was actually set. Recall that the GetMessage function does not return ...
Comments are closed.0 0
Code

The dialog manager, part 5: Converting a non-modal dialog box to modal

Let's apply what we learned from last time and convert a modeless dialog box into a modal one. As always, start with the scratch program and make the following additions: INT_PTR CALLBACK DlgProc( HWND hdlg, UINT uMsg, WPARAM wParam, LPARAM lParam) { switch (uMsg) { case WM_INITDIALOG: SetWindowLongPtr(hdlg, DWLP_USER, lParam); ...
Comments are closed.0 0
Code

The dialog manager, part 4: The dialog loop

The dialog loop is actually quite simple. At its core, it's just while (<dialog still active> && GetMessage(&msg, NULL, 0, 0, 0)) { if (!IsDialogMessage(hdlg, &msg)) { TranslateMessage(&msg); DispatchMessage(&msg); } } If you want something fancier in your dialog loop, you can take the loop above ...
Comments are closed.0 0
Code

The dialog manager, part 3: Creating the controls

This is actually a lot less work than creating the frame, believe it or not. For each control in the template, the corresponding child window is created. The control's sizes and position is specified in the template in DLUs, so of course they need to be converted to pixels. int x = XDLU2Pix(ItemTemplate.x); int y = YDLU2Pix(...
Comments are closed.0 0
Code

The dialog manager, part 2: Creating the frame window

The dialog template describes what the dialog box should look like, so the dialog manager walks the template and follows the instructions therein. It's pretty straightforward; there isn't much room for decision-making. You just do what the template says. For simplicity, I'm going to assume that the dialog template is an extended dialog ...
Comments are closed.0 0
Code

The dialog manager, part 1: Warm-ups

I think a lot of confusion about the dialog manager stems from not really understanding how it works. It's really not that bad. I'll start by describing how dialog boxes are created over the next few articles, then move on to the dialog message loop, and wrap up with some topics regarding navigation. There will be nine parts in all. The ...
Comments are closed.0 0
Code