The Old New Thing

Locale-sensitive number grouping

Most westerners are familiar with the fact that the way numbers are formatted differ between the United States and much of Europe. What people don't realize is that the grouping is not always in threes. In India, the least significant group consists of three digits, but subsequent groups are in pairs. I've also seen reports that the first ...

Inadvertently passing large objects by value

One mark of punctuation can make all the difference. One program was encountering a stack overflow exception in a function that didn't appear to be doing anything particularly stack-hungry. The following code illustrates the problem: (In reality, the algorithm for comparing two tests results was much more complicated, but that's ...

Why doesn't the window manager just take over behavior that used to be within the application's purview?

A commenter named "Al" wondered why the window manager couldn't just take over behavior that used to be within the application's purview, such as painting the non-client area, in order to avoid problems with applications not responding to messages promptly enough. If the window manager were being rewritten, then perhaps it could. But to do it...

Basic ground rules for programming – function parameters and how they are used

There are some basic ground rules that apply to all system programming, so obvious that most documentation does not bother explaining them because these rules should have been internalized by practitioners of the art to the point where they need not be expressed. In the same way that when plotting driving directions you wouldn't even consider ...

Why does the version 6 animation control not use a background thread?

Many people have noticed that the animation bar control in version 6 of the common controls no longer uses a background thread to draw the animation. Instead, it acts as if the style is always set, even if the caller didn't pass it. Why is that? The first reason is that the background thread didn't actually help any. In order to draw ...

Controlling resource consumption by meting out work items

At the PDC, one person came to talk to me for advice on a resource management problem they were having. To simplify, their system generated dozens of work items, each of which required significant resource consumption. For the sake of illustration, let's say that each of the work items was a single-threaded computationally-intensive operation ...

A thread waiting on a synchronization object could be caught napping

If you have a synchronization object, say a semaphore, and two threads waiting on the semaphore, and you then release two semaphore tokens with a single call to , you would expect that each of the waiting threads would be woken, each obtaining one token. And in fact, that's what happens—most of the time. Recall in our discussion of why...

If you ask for a window caption, you also get a border

Some people may have noticed that the is defined as the combination of and : Since includes , it is impossible to get a caption without a border. Sometimes people don't quite get this and keep asking the question over and over again, and I have to keep trying to explain the laws of logic in different ways until one of them finally ...

Why is there no message for disabling the Cancel button on a wizard?

Some people have noticed that there is no message that lets you disable the Cancel button on a wizard. This is on purpose. Usability studies reveal that users find it extremely frustrating when they get partway through a wizard and then decide they don't want to perform the operation after all, but find that the wizard doesn't give them a way ...

The consequences of invalidating the null window

On occasion, you might notice that every window on the desktop flickers and repaints itself. One of the causes for this is a simple null handle bug. The function is one you're probably well-familiar with. It is used to indicate to the window manager that the pixels of a particular window are no longer current and should be repainted. (You ...