The Old New Thing

Returning values from a dialog procedure

For some reason, the way values are returned from a dialog procedure confuses people, so I'm going to try to explain it a different way. The trick with dialog box procedures is realizing that they actually need to return two pieces of information: ...
Comments are closed.0 0
Code

Just follow the rules and nobody gets hurt

You may have been lazy and not bothered calling VirtualProtect(PAGE_EXECUTE) when you generated some code on the fly. You got away with it because the i386 processor page protections do not have a "read but don't execute" mode, so anything you could read you could also execute. Until...
Comments are closed.0 0
Code

The long and sad story of the Shell Folders key

When you are attempting to architect an operating system, backwards compatibility is one of the ones you just have to accept. But when new programs rely on app hacks designed for old programs, that makes you want to scream. Once upon a time, in what seems like a galaxy far far away (a Windows 95 beta release known as "M3"), we documented a...

Why highlighting by inverting colors is a bad idea

Often people will say, "Oh, we can highlight by inverting the color." This may have worked great on two-color black-and-white displays, but in the world of 32-bit color this no longer is effective. Consider the following picture. See if you can guess which one is inverted...
Comments are closed.0 0
Code

Drawing an active-looking caption even when not active

"Why would somebody ever want to do that?" you might ask. Well, this is a common appearance for floating toolbars. (But aside from that case, I can't think of any other valid reason to draw a window as active even though it isn't.) Fortunately this is easy to do. Just add this line to the WndProc...
Comments are closed.0 0
Code

Getting a custom right-click menu for the caption icon

Explorer does it. Now you can too. It's a simple matter of detecting a context menu on the caption icon and displaying a custom context menu. Here are the simple changes to our scratch program to display a rather pointless one-item menu. When we receive a WM_CONTEXTMENU ...
Comments are closed.0 0
Code

Writing a sort comparison function

When you are writing a sort comparison function (say, to be passed to ListView_SortItems or *gasp* to be used as an IComparer), your comparison function needs to follow these rules: Reflexivity: Compare(a, a) = 0. Anti-Symmetry: Compare(a, b) has the opposite sign of Compare(b, a), where 0 is considered to be its own opposite. Transitivity...
Comments are closed.0 0
Code

Using the TAB key to navigate in non-dialogs

The IsDialogMessage function works even if you aren't a dialog. As long as your child windows have the WS_TABSTOP and/or WS_GROUP styles, they can be navigated as if they were part of a dialog box. One caveat is that IsDialogMessage will send DM_GETDEFID and DM_SETDEFID messages to your window, which are ...
Comments are closed.0 0
Code

Scrollbars redux: Part 12

Reader Jeff Miller added Word-style scroll tips to our sample scrollbar program. Here's how he did it: A tracking tooltip is used to display the scroll tip because we don't want the tooltip to do automatic positioning or automatic show/hide. When a tracking scroll occurs (...
Comments are closed.0 0
Code