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

How does Explorer determine the delay between clicking on an item and initiating an edit?

Ian Boyd wants to know why the specific value of 500ms was chosen as the edit delay in Windows Explorer. Because it's your double-click time. Since the double-click action (execute) is not an extension of the single-click action (edit), Explorer (and more generally, list view) waits for the double-click timeout before entering edit mode so it can tell whether that first click was really a single-click on its own or a single-click on the way to a double-click. If the timeout were shorter than the double-click time, then double-clicking an item would end up having the first click trigger edit mode and the seco...

How did real-mode Windows fix up jumps to functions that got discarded?

In a discussion of how real-mode Windows walked stacks, commenter Matt wonders about fixing jumps in the rest of the code to the discarded functions. I noted in the original article that "there are multiple parts to the solution" and that stack-walking was just one piece. Today, we'll look at another piece: Inter-segment fixups. Recall that real-mode Windows ran on an 8086 processor, a simple processor with no memory manager, no CPU privilege levels, and no concept of task switching. Memory management in real-mode Windows was handled manually by the real-mode kernel, and the way it managed memory was by lo...

When the default pushbutton is invoked, the invoke goes to the top-level dialog

One quirk of nested dialogs lies in what happens when the user presses Enter to invoke the default pushbutton: The resulting message goes to the top-level dialog, even if the default pushbutton belongs to a sub-dialog. Why doesn't it send the to the parent of the default pushbutton? I mean, the dialog manager knows the handle of the button, so it can send the message to the button's parent, right? Well, the dialog manager knows the handle of a button. But not necessarily the button. Recall that if focus is not on a pushbutton, then the dialog manager sets the default pushbutton based on the control ID ret...

Counting down to the last day of school, as students do it

Today is the last day of school in Seattle public school. My friend the seventh-grade teacher told me that students count down to the last day of school in a rather unusual way. Some people might count the number of calendar days until the end of school. For example, if there are 35 days between today and the last day of school, we say that it's 35 days until the end of school. Others might count only the number of school days before school is out. If today is Monday, and the last day of school is Friday, then there are five days of school remaining. But students, or at least seventh-grade students, count the ...

When embedding a dialog inside another, make sure you don't accidentally create duplicate control IDs

The extended style (known in dialog templates as ) instructs the dialog manager that the dialog's children should be promoted into the dialog's parent. This is easier to explain in pictures than in text. Given the following window hierarchy: The result of the extended style being set is that the children of B are treated as if they were direct children of the main dialog, and the window B itself logically vanishes. The extended style means "Hello, I am not really a dialog control. I am a control parent. In other words, I have children, and those children are controls." (Some people erroneously pu...

It's not a good idea to give multiple controls on a dialog box the same ID

When you build a dialog, either from a template or by explicitly calling , one of the pieces of information about each control is a child window identifier. And it's probably in your best interest to make sure two controls on the dialog don't have the same ID number. Of course, one consequence of giving two control the same ID number is that the function won't know which one to return when you say, "Please give me control number 100." This naturally has a cascade effect on all the other functions which are built atop the function, such as . Another reason to avoid duplication is that many notification messag...

What is the history of the GetRandomRgn function?

An anonymous commenter was curious about how the function arrived at its strange name, what the purpose of the third parameter is, and why it is inconsistent between Windows 95 and Windows NT. The sense of word "random" here is hacker slang rather than its formal probabilistic definition, specifically sense 2: "Assorted, undistinguished", perhaps with a bit of sense 4 sprinkled in: "Not well organized." (Commenter Gabe suggested that a better name would have been .) Once upon a time, when men were men and Windows was 16-bit, there was an internal function used to communicate between the ...

Globalization quiz: In honor of, well, that's part of the quiz

The Corporate Citizenship Tools; Microsoft Local Language Program Web site contains a map of the world, coded by region. There was a bug on the map. See if you can spot it: After I pointed out the error, they fixed the map on their Web page, so no fair clicking through to the Local Language Program Web page and comparing the pictures! Non-useful hint: I chose the publication date of this quiz in honor of the answer. Bonus chatter: Inside the answer. Iceland is drawn in the color of North America rather than Europe. Here's the corrected map: The non-useful hint is that I posted this quiz on the Fri...

Now that Windows makes it harder for your program to block shutdown, how do you block shutdown?

Up until Windows XP, applications could intercept the message and tell Windows, "No, don't shut down." If they were polite about it, they would also inform the user which application blocked system shutdown and why. And if they were really polite about it, they would even provide a way for the user to say, "I don't care; shut down anyway." As I noted some time ago, Windows Vista made it harder for applications to block shutdown. Applications are given two seconds to clean up, and then it's game over. Okay, now the game of walls and ladders continues. The power management folks created an escape hatch fo...