The Old New Thing

Practical development throughout the evolution of Windows.

Latest posts

If my WM_TIMER handler takes longer than the timer period, will my queue fill up with WM_TIMER messages?
Dec 4, 2014
Post comments count 0
Post likes count 0

If my WM_TIMER handler takes longer than the timer period, will my queue fill up with WM_TIMER messages?

Raymond Chen
Raymond Chen

A customer was worried that they may have a problem with their message queue filling with messages. "If my handler takes longer than the timer period, will my queue fill up with messages?" As we should know by now, timer messages are generated on demand: The WM_TIMER message is a low-priority message. The Get­Message and Peek­Message functions post this message only when no other higher-priority messages are in the thread's message queue. Here's the basic algorithm. (I'm ignoring filtering and I'm assuming that messages are removed.) Notice that the generated messages are generated on demand ...

What happens if I don't paint when I get a WM_PAINT message?
Dec 3, 2014
Post comments count 0
Post likes count 0

What happens if I don't paint when I get a WM_PAINT message?

Raymond Chen
Raymond Chen

Suppose your window procedure doesn't paint when it gets a message. What happens? It depends on how you don't paint. If you have an explicit handler for the message that does nothing but return without painting, then the window manager will turn around and put a new message in your queue. "And try harder this time." Remember that the rules for the message are that the window manager will generate a message for any window that has a dirty region. If you fail to remove the dirty region in your message handler, well, then the rules state that you get another message. (The most common way of clearing the ...

Microspeak: Redlines
Dec 2, 2014
Post comments count 0
Post likes count 0

Microspeak: Redlines

Raymond Chen
Raymond Chen

To the outside world, redline can mean to mark something for removal, or it could mean the maximum safe speed of an engine. But in the world of Microsoft design, the term redlines (pronounced as if it were written as the two words red lines, but the accent is on the red) refers to a diagram showing the exact position of visual elements. They typically take the form of a proposed screen shot, with arrows and lines superimposed to indicate the distances between items, which items align with each other, and so on. They also contain indications as to the exact colors to use for different elements. Originally the li...

Counting array elements which are below a particular limit value using SSE
Dec 1, 2014
Post comments count 0
Post likes count 1

Counting array elements which are below a particular limit value using SSE

Raymond Chen
Raymond Chen

Some time ago, we looked at how doing something can be faster than not doing it. That is, we observed the non-classical effect of the branch predictor. I took the branch out of the inner loop, but let's see how much further I can push it. The trick I'll employ today is using SIMD in order to operate on multiple pieces of data simultaneously. Take the original program and replace the function with this one: Now, this program doesn't actually use any parallel operations, but it's our starting point. For each 32-bit value, we load it, compare it agains the boundary value, and accumulate the result. The func...

A user's SID can change, so make sure to check the SID history
Nov 28, 2014
Post comments count 0
Post likes count 1

A user's SID can change, so make sure to check the SID history

Raymond Chen
Raymond Chen

It doesn't happen often, but a user's SID can change. For example, when I started at Microsoft, my account was in the SYS-WIN4 domain, which is where all the people on the Windows 95 team were placed. At some point, that domain was retired, and my account moved to the REDMOND domain. We saw some time ago that the format of a user SID is The issuing entity for a local account on a machine is the machine to which the account belongs. The issuing entity for a domain account is the domain. If an account moves between domains, the issuing entity changes, which means that the old SID is not valid. A new SID...

Some light reading on lock-free programming
Nov 27, 2014
Post comments count 0
Post likes count 0

Some light reading on lock-free programming

Raymond Chen
Raymond Chen

Today is a holiday in the United States, so I'm going to celebrate by referring you to other things to read. I'm going to start with a presentation by Bruce Dawson at GDC 2009, which is basically multiple instances of the question "Is this code correct?", and the answer is always "No!" Although the title of the talk is Lockless Programming in Games, the information is relevant to pretty much everybody. I can't find a recording of the presentation, but you can download the PowerPoint slides or view them in your browser. But I recommend downloading the PowerPoint slides and reading the notes, because the notes e...

If 16-bit Windows had a single input queue, how did you debug applications on it?
Nov 26, 2014
Post comments count 0
Post likes count 0

If 16-bit Windows had a single input queue, how did you debug applications on it?

Raymond Chen
Raymond Chen

After learning about the bad things that happened if you synchronized your application's input queue with its debugger, commenter kme wonders how debugging worked in 16-bit Windows, since 16-bit Windows didn't have asynchronous input? In 16-bit Windows, all applications shared the same input queue, which means you were permanently in the situation described in the original article, where the application and its debugger (and everything else) shared an input queue and therefore would constantly deadlock. The solution to UI deadlocks is to make sure the debugger doesn't have any UI. At the most basic level, the ...

What is the difference between Full Windows Touch Support and Limited Touch Support?
Nov 25, 2014
Post comments count 0
Post likes count 0

What is the difference between Full Windows Touch Support and Limited Touch Support?

Raymond Chen
Raymond Chen

In the System control panel and in the PC Info section of the PC & Devices section of PC Settings, your device's pen and touch support can be reported in a variety of ways. Here is the matrix: The meaning of No touch and Single touch are clear, but if a device supports multiple touch points, what makes the system report it as having Limited versus Full touch support? A device with Full touch support is one that has passed Touch Hardware Quality Assurance (THQA). You can read about the Windows Touch Test Lab (WTTL) to see some of the requirements for full touch support. If you have a touch device without ...

The crazy world of stripping diacritics
Nov 24, 2014
Post comments count 0
Post likes count 0

The crazy world of stripping diacritics

Raymond Chen
Raymond Chen

Today's Little Program strips diacritics from a Unicode string. Why? Hey, I said that Little Programs require little to no motivation. It might come in handy in a spam filter, since it was popular, at least for a time, to put random accent marks on spam subject lines in order to sneak past keyword filters. (It doesn't seem to be popular any more.) This is basically a C-ization of the C# code originally written by Michael Kaplan. Don't forget to read the follow-up discussion that notes that this can result in strange results. First, let's create our dialog box. Note that I intentionally give it a huge font ...