The Old New Thing

Make sure the buttons match the question

When your program displays a dialog box with buttons, please make the buttons match the text. Consider this dialog, which appears after you install patches from Windows Update: (image) It asks a yes/no question, but the options are "OK" and "Cancel". Either the buttons...

Preventing edit control text from being autoselected in a dialog box

By default, when the user TABs to an edit control in a dialog box, the entire contents of the edit control are autoselected. This occurs because the edit control responds with the flag in response to the message. To prevent it from happening, remove that flag. All this subclass procedure does is remove the flag from the return value of ...

Another different type of dialog procedure

The other method of using a window-procedure-like dialog box is to change the rules of the game. Normally, the window procedure for a dialog box is the function, which calls the dialog procedure and then takes action if the dialog procedure indicated that it desired the default action to take place. The dialog procedure is subservient to...

Answer to previous exercise about m_fRecursing

Answer to previous exercise: The flag does not need to be per-instance. It only needs to be valid long enough that the recursive call that comes immediately afterwards can be detected. However, a global variable would not work because two threads might be inside the recursive call simultaneously. But a thread-local variable would work. (...

A different type of dialog procedure

In the discussion following my entry about dialog procedure return values, somebody suggested an alternate dialog design where you just call to do default actions (the same way you write window procedures and ) rather than returning TRUE/FALSE. So let's do that. In fact, we're going to do it twice. I'll cover one method today and cover an...

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: ...

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...

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...