The Old New Thing
Practical development throughout the evolution of Windows.
Latest posts
Keyboard layouts aren't like Beetlejuice – they won't appear just because you say their name
A customer reported a bug in Windows Vista Home Editions: We are handling a Ctrl+V keyboard event and want to interpret it in the context of a US-English keyboard. On Windows XP and versions of Windows Vista other than Home editions, the three calls all succeed, whereas on Windows Vista Home Editions, the calls fail. On the other hand, if instead of using the US-English keyboard, we use the current keyboard layout: then Windows Vista Home Editions behave the same as Windows XP and non-Home editions of Vista. This suggests that the Home Editions of Vista supports keyboard queries only for the...
You can't use the WM_USER message in a dialog box
Today, I'm not actually going to say anything new. I'm just going to collate information I've already written under a better title to improve search engine optimization. A customer reported that they did the following but found that it didn't work: "I send the message to my dialog, but the value doesn't stick. At random times, the value resets back to zero." As we saw some time ago, window messages in the range belong to the window class. In the case of a dialog box, the window class is the dialog class, and the owner of the class is the window manager itself. An application which tries to use the mes...
Diversion: Generating a random color from JavaScript
A colleague posed a little puzzle for a fun little app he was writing in HTML: He wanted to generate a random color. If you search around the intertubes, you can find several possible attempts at a solution, like this collection, and an interesting example that has trouble with the pigeonhole principle. The original function to generate a random color went like this: Can you do better? (My solution after the jump.) That was a short jump. My first simplification was recognizing that three random 8-bit values is the same as one random 24-bit value. Next, I got rid of the function by simply settin...
How do you come up with new shortcut keys?
Anon asks, "How do you come up with new shortcut keys and how do you deal with different keyboard layouts? What is the process; is there a company-wide procedure to keep things consistent?" This is several questions (none of them really a suggestion, but I've given up on making the Suggestion Box about suggestions; now it's just the "Ask Raymond a question" page), so let's take them one at a time. (Note that if you ask multiple questions, you reduce the likelihood that I'll answer them, because I feel obligated either to answer all of them or none of them.) First question: How do you come up with new shortcut k...
Using WM_COPYDATA to marshal message parameters since the window manager otherwise doesn’t know how
Miral asks for the recommended way of passing messages across processes if they require custom marshaling. There is no one recommended way of doing the custom marshaling, although some are hackier than others. Probably the most architecturally beautiful way of doing it is to use a mechanism that does perform automatic marshaling, like COM and MIDL. Okay, it's not actually automatic, but it does allow you just give MIDL your structures and some information about how they should be interpreted, and the MIDL compiler autogenerates the marshaler. You can then pass the data back and forth by simply invoking COM me...
Why does ShellExecute return SE_ERR_ACCESSDENIED for nearly everything?
We saw a while ago that the function returns at the slightest provocation. Why can't it return something more meaningful? The short-term answer is that the return value from is both a success code and an error code, and you check whether the value is greater than 32 to see which half you're in. In particular, the error code case is if the value you got is less than or equal to 32. This already demonstrates that the error codes are limited to values less than or equal to 32. And all those error codes are already accounted for, so there's nowhere to stick "an error not on the original list of 32 possible err...
If there's a problem with a wiki, then you can fix it; that's why it's a wiki
On an internal mailing list, somebody asked a question about how to do X with Y, and I replied with a link to an internal wiki that described how to do X with Y (answer: use the Z tool). Somebody else replied, "Time to update that article because the link to the Z tool is broken." Apparently, this person forgot that one of the defining characteristics of a wiki is that it's easy to edit. (Another characteristic is that it is collaboratively-edited; there is no central authority.) In other words, if you see something wrong, fix it yourself. Don't just stand around saying somebody should do something. Be someon...
Irony patrol: Recycling bins
Microsoft has a large corporate recycling effort. Every office, every mail room, every kitchenette, every conference room has a recycling bin. The dining facilities earned Green Restaurant Certification, and there is a goal of making the cafeterias a zero-landfill facility by 2012. (Hey, that's this year!) A few years ago, I found one room in my building that didn't have a recycling bin, and you'd think it'd be one of the rooms near the top of the list for needing one. The room without a recycling bin was the copy machine room. As a result, people were throwing their unwanted cover sheets and other paper wa...
The cries of "Oh no!" emerge from each office as the realization slowly dawns
Today is the (approximate) 15th anniversary of the Bedlam Incident. To commemorate that event, here's a story of another email incident gone horribly awry. Some time ago, an email message was sent to a large mailing list. It came from somebody in the IT department and said roughly, "This is a mail sent on behalf of Person X to check if your XYZ server has migrated to the new datacenter. Please visit http://blahblah and confirm that your server name is of the form XXYYNNZZ. If not, please Reply to All." Uh-oh. The seasoned Microsoft employees (and the new employees who paid attention during new employee o...