The Old New Thing
Practical development throughout the evolution of Windows.
Latest posts

Psychic debugging: Understanding DDE initiation

You too can use your psychic powers to debug the following problem: We have a problem with opening documents with our application by double-clicking them in Explorer. What's really strange is that if we connect a debugger to Explorer and set a breakpoint on , then wait a moment after returns, then hit '', then the document opens fine. But if we don't wait, then the application launches but the document does not open. Instead, you get the error message "Windows cannot find 'abc.lit'. Make sure you typed the name correctly, and then try again." Here is the command we are executing when we run into this problem...

Three-Minute Masterpieces (2006)

The Seattle Times invited its readers to make three-minute movies, and the best were screened at the Seattle International Film Festival. Or you can watch them online.

A single-instance program is its own denial of service

There are many ways a program can establish itself as a single-instance program; I won't go into them here. But once people head down the path of a single-instance program, they bump into another issue in their security review: Denial of service. We are using a named mutex with a fixed name in order to detect whether another copy of the program is running. But that also means an attacker can create the mutex first, thereby preventing our program from running at all! How can I prevent this type of denial of service attack? If the attacker is running in the same security context as your program is (or would be) ...

Announcements on the ferry, one self-explanatory, one not

While I was riding the ferry last Saturday, there were two announcements made over the public address system. "All crew please report to the Second Mate's office." What were they all doing in the Second Mate's office? Would the whole crew fit into the office? And while all the crew are in the Second Mate's office, who's steering the ferry? The second announcement was self-explanatory: "Will the owner of a XYZ please report to the Car Deck to shut off your car alarm? The passenger in the car is becoming increasingly frantic." What was I doing on the ferry anyway? I was returning to Seattle from a bike ride w...

Why can't you programmatically reorder the items on the Start menu?

The classic Start menu and the "All Programs" portion of the Windows XP Start menu permit you to customize the order of the shortcuts that appear there. You can use drag/drop to rearrange them, or force them to be sorted by name. But why is there no programmatic interface to these actions? Because the power would be used for evil far more than it would be used for good. As noted before, the Start menu is highly contentious screen real estate. If a programmatic interface were given to the order of the items on the Start menu, programs would just use it to force their shortcut to the top (and possibly demot...

Understanding what significant digits really mean

A double-precision floating point number carries fifteen significant digits. What does this really mean? I multiplied 0.619207 by 10,000,000 and got 6192069.999999991 instead of 6192070. That's only six significant digits; where's my fifteen? Talking about significant digits is really just a shorthand for talking about relative precision. "Fifteen significant digits" means that the representational resolution is one part in 1015. It doesn't mean that the first fifteen digits are correct. (If you spend more time with numerical analysis, you can even see people talking about things like "five and a half signific...

It's a good idea to get somebody who knows the language to be your proofreader

If you're going to use text from another language, it behooves you to get somebody who knows the language to be your proofreader. Those who fail to heed this advice with respect to Chinese characters may end up featured on Hanzi Smatter 一知半解, which starts with a book titled A Dictionary of Chinese Symbols whose cover depicts the character "book" (書) upside-down. (Psst, they're called "characters", not "symbols".) David Beckham could have done with a good proofreader when he got his wife's name tattooed onto his arm in Hindi, but misspelled it. I get a real chuckle out of the...

Window class properties apply to all windows that belong to the class

Window class properties apply to all windows that belong to the class. That's why they're called class properties. This seems like an obvious thing to say when put in so many words, but I see many "solutions" that lose sight of this simple fact. All the properties that you set in the (or ) are window class properties, as are the properties that you can access via . This means that when you change those properties, they affect the entire class. For example, if you write then you aren't just changing the cursor for the window specified by . You're changing the cursor for all windows of the same class as . F...

Pitfalls of transparent rendering of anti-aliased fonts

Windows provides a variety of technologies for rendering monochrome text on color displays, taking advantage of display characteristics to provide smoother results. These include grayscale anti-aliasing as well as the more advanced ClearType technique. Both of these methods read from the background pixels to decide what pixels to draw in the foreground. This means that rendering text requires extra attention. If you draw text with an opaque background, there is no problem because you are explicitly drawing the background pixels as part of the text-drawing call, so the results are consistent regardless of what...