The Old New Thing

What’s the point of DeferWindowPos?

The purpose of the DeferWindowPos function is to move multiple child windows at one go. This reduces somewhat the amount of repainting that goes on when windows move around. Take that DC brush sample from a few months ago and make the following changes: HWND g_hwndChildren[2]; BOOL OnCreate(HWND hwnd, LPCREATESTRUCT lpcs) { const ...

Using script to query information from Internet Explorer windows

Some time ago, we used C++ to query information from the ShellWindows object and found it straightforward but cumbersome. This is rather clumsy from C++ because the ShellWindows object was designed for use by a scripting language like JScript or Visual Basic. Let's use one of the languages the ShellWindows object was designed for to ...

What’s the difference between My Documents and Application Data?

The most important difference between My Documents and Application Data is that My Documents is where users store their files, whereas Application Data is where programs store their files. In other words, if you put something in CSIDL_MYDOCUMENTS (My Documents), you should expect the user to be renaming it, moving it, deleting it, emailing ...

Beware of roaming user profiles

One of the less-known features of Windows is the roaming user profile. I know that this is not well-known because I often see suggestions that fail to take the roaming user profile scenario into account. Indeed, if your program behaves badly enough, you can cause data loss. (More on this later.) What is a roaming user profile? Well, your ...

Why can't I get the pixels of a window that isn't visible on screen?

If the window isn't visible on the screen, then the pixels simply don't exist. The Windows painting model follows the principle of "Don't save anything you can recalculate". Consider: You have a 640x480 display in 16-color mode. That's 150KB of video memory. Take four copies of Notepad and maximize each one. If each of those copies of ...

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

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...

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

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...

Displaying the dictionary, part 2: Using text callbacks

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 ...

Displaying the dictionary, part 1: Naive version

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.) ...