Showing results for Code - The Old New Thing

Jun 22, 2005
Post comments count0
Post likes count0

Why does the Run dialog autocorrect but not the Run key?

Raymond Chen
Raymond Chen

In an earlier comment, Aswin Gunawan asked why the Run dialog does autocorrection but not the Run key? One is a programmatic interface and the other is an end-user control. End users are not expected to be understand how computers do things. They want, and even expect, the computer to help them out with what they're typing. This means spell-chec...

Code
Jun 15, 2005
Post comments count0
Post likes count0

Displaying the dictionary, part 3: Using an owner-data listview

Raymond Chen
Raymond Chen

Owner-data listviews let you take over data management from the listview. This is useful in our case since we have over twenty thousand dictionary entries, and creating even that many blank listview items takes an unacceptably long amount of time. Let's convert our listview to an owner-data listview. Believe it or not, this is quite easy to do o...

Code
Jun 14, 2005
Post comments count0
Post likes count0

Displaying the dictionary, part 2: Using text callbacks

Raymond Chen
Raymond Chen

As we noted last time, adding items to the listview takes an absurd amount of time. Today, we'll make a failed attempt at improving this because it lets me illustrate a listview technique and it lays the groundwork for the real fix next time. Instead of creating the items in their entirety, let's set their text to . This is a placeholder value ...

Code
Jun 13, 2005
Post comments count0
Post likes count0

Displaying the dictionary, part 1: Naive version

Raymond Chen
Raymond Chen

We return briefly to the ongoing Chinese/English dictionary series and write some code to display all the definitions we had worked so hard to collect. (I figure you're anxious to see something on the screen, so I am going to handle the Traditional Chinese/Simplified Chinese issue later. For now, the "Simplified" column will be blank.) Take th...

Code
Jun 7, 2005
Post comments count0
Post likes count0

Answer to quick puzzle about security and synchronization

Raymond Chen
Raymond Chen

As many people quickly figured out, the reason why the the returns immediately is that the call is failing. The reason is that the second process opened the handle with access, which grants permission to call the function, the function, and the fatally flawed function, but it doesn't include access, which is necessary if you intend to ...

Code
Jun 6, 2005
Post comments count0
Post likes count0

A quick puzzle about security and synchronization

Raymond Chen
Raymond Chen

This quick puzzle floated past one of our internal discussion groups. In Process B, the succeeds, but the returns immediately instead of waiting. Explain. [Correction: I confused the matter by passing as the third parameter, thereby creating an event that is initially signalled. Change it to so that the event is created non-signall...

Code
May 31, 2005
Post comments count0
Post likes count0

Using modular arithmetic to avoid timing overflow problems

Raymond Chen
Raymond Chen

In an earlier article, I presented a simple way of avoiding timing overflows which seemed to create a bit of confusion. The short version: Given a starting time start, an ending time end and an interval interval, the way to check whether the interval has elapsed is to use the expression . The naive expression suffers from integer overflow probl...

Code
May 30, 2005
Post comments count0
Post likes count0

You can't simulate keyboard input with PostMessage

Raymond Chen
Raymond Chen

Some people attempt to simulate keyboard input to an application by posting keyboard input messages, but this is not reliable for many reasons. First of all, keyboard input is a more complicated matter than those who imprinted on the English keyboard realize. Languages with accent marks have dead keys, Far East languages have a variety of Input Me...

Code
May 27, 2005
Post comments count0
Post likes count1

When is x/2 different from x>>1?

Raymond Chen
Raymond Chen

Everyone "knows" that the following pairs of expressions are equivalent: Too bad they aren't. In the C language standard, there is no requirement that the internal representation of signed integers be two's complement. All the permissible representations agree for positive numbers, but negative numbers can have different representations. If is ...

Code
May 25, 2005
Post comments count0
Post likes count0

The effect of SetCursor lasts only until the next SetCursor

Raymond Chen
Raymond Chen

Of course the effect of the function for a thread lasts only until that thread changes the cursor to something else. Any moron knows that, right? The tricky part is that the may come from an unexpected place. THe most common place people run into this is when they do something like this: This puts up the hourglass during the processing. ...

Code