The Old New Thing

Why does the debugger show me the wrong function?

Often you'll be minding your own business debugging some code, and you decide to step into one function and the debugger shows that you're in some other function. How did that happen? You then step through code that does something like this: And when you step into the call to you find yourself in . What happened? What happened is ...

Your exception handler can encounter an exception

Consider the following code, written in C# just for kicks; the problem is generic to any environment that supports exception handling. Some time later, you find yourself facing an assertion failure from claiming that you are destroying the document while there are still active plugins. But there is your call to , and it's in a block, and...

Why does SystemParametersInfo hang when I pass the SPIF_SENDCHANGE flag?

If you pass the flag to the function, it will broadcast the message with the wParam equal to the system parameter code you passed. For example, if you call then the system will broadcast the message If there is a window that isn't responding to messages, then this broadcast will hang until that unresponsive window finally resumes ...

Using SystemParametersInfo to access user interface settings

The function gives you access to a whole slew of user interface settings, and it is the only supported method for changing those settings. I'm not going to list every single setting; go read the list yourself. Here are some highlights: Here are some control panel settings. Notice that when using the SPI_SET* commands, you also have to...

A timed context menu

This is sort of in the same spirit as our previous exercise in writing a timed message box, but this is much easier. Here, we use the handy-dandy message to get us out of menu mode. Before displaying the menu, we set a timer. (And we use a thread timer because we don't own the window and therefore don't know what timer IDs are safe to ...

Modality, part 8: A timed MessageBox, the better version

A few days ago, we saw a simple version of a timed message box which had a limitation that it could be used from only one thread at a time. Today we'll work to remove that limitation. As you may recall, the reason why it could be used from only one thread at a time was that we kept the "Did the message box time out?" flag in a global. To ...

The bonus window bytes at GWLP_USERDATA

The window manager provides a pointer-sized chunk of storage you can access via the constant. You pass it to the function and the function to read and write that value. Most of the time, all you need to attach to a window is a single pointer value anyway, so the free memory in is all you need. Note that this value, like the other ...

The scratch window

Sometimes you need a quick and dirty window and you don't want to go through all the hassle of registering a class for it. For example, you might need a window to do a brief snippet of DDE, or you just need a window to own a message box. To save yourself the trouble of registering a class for every single weenie thing you might need a ...

Modality, part 7: A timed MessageBox, the cheap version

As we noted at the end of part 3, now that you know the conventions surrounding the message you can put them to your advantage. The more robust you want the function to be, the more work you need to do. Here's the cheap version, based on the sample in the Knowledge Base, but with some additional bug fixes. This function acts ...

Modality, part 6: Interacting with a program that has gone modal

Earlier we saw the importance of setting the right owner window for modal UI. It is also important, when manipulating a window, to respect its modality. For example, consider the program we ended up with last time, the one which calls the function to display a modal dialog. If we wanted to get that program to exit and sent a message to ...