Showing results for Code - The Old New Thing

Sep 20, 2013
Post comments count0
Post likes count0

How can I tell that I have a shell folder that represents My Computer?

Raymond Chen
Raymond Chen

You have in your hands an , and you want to know whether this is an that represents My Computer. There are a few ideas that may occur to you. One is to ask the folder for its current location and compare it to . Okay, we have a lot of moving parts here. Let's look at them one at a time. The function takes an object and asks what folder it r...

Code
Sep 19, 2013
Post comments count0
Post likes count0

When a program is launched via DDE, and there are multiple servers, which one is used?

Raymond Chen
Raymond Chen

Although you are more than welcome to stop using DDE (please oh please stop using it), there are still many applications which still use it (cough), and as a result, customers still have questions about it. One customer wanted to know why, if multiple copies of a DDE-based application are running, Windows 7 will send the command to the earli...

Code
Sep 18, 2013
Post comments count0
Post likes count0

SubtractRect doesn't always give you the exact difference

Raymond Chen
Raymond Chen

The function takes a source rectangle and subtracts out the portion which intersects a second rectangle, returning the result in a third rectangle. But wait a second, the result of subtracting one rectangle from another need not be another rectangle. It might be an L-shape, or it might be a rectangle with a rectangular hole. How does this map bac...

Code
Sep 16, 2013
Post comments count0
Post likes count0

Forcing a file handle closed when it has been opened remotely

Raymond Chen
Raymond Chen

Today's Little Program closes a file handle that was opened remotely. It builds on previous discussion on how to use the functions. Forcing a network file handle closed does not actually close the handle. This makes it very different from the various "force handle closed" utilities out there. Rather, forcing a network file handle closed is a...

Code
Sep 5, 2013
Post comments count0
Post likes count0

Why are my posted messages getting lost when the user drags my window around?

Raymond Chen
Raymond Chen

This question was inspired by an actual customer question, but I changed a lot of it around to make for a more interesting story. (Trust me, the original story was even more boring.) A customer's background thread posted a message to the main UI thread to signal something (details not important). They found that the posted message was never rece...

Code
Aug 30, 2013
Post comments count0
Post likes count0

Can an x64 function repurpose parameter home space as general scratch space?

Raymond Chen
Raymond Chen

We saw some time ago that the x64 calling convention in Windows reserves space for the register parameters on the stack, in case the called function wants to spill them. But can the called function use the memory for other purposes, too? You sort of already know the answer to this question. Consider this function: How would a naïve comp...

Code
Aug 29, 2013
Post comments count0
Post likes count0

How can I write to a file only as long as nobody's looking?

Raymond Chen
Raymond Chen

A customer wanted to know how to detect that the user has opened Notepad to view a particular file. They had come up with method based on polling and sniffing the Notepad title bar, but they found that it consumed a lot of CPU. (They hadn't noticed yet that it doesn't localize, and that it can trigger false positives since Notepad shows only the fi...

Code
Aug 28, 2013
Post comments count0
Post likes count0

The format of data and custom resources

Raymond Chen
Raymond Chen

Continuing the highly-sporadic series of Win32 resource formats, today we'll look at the format of resources, which are declared in resource files as . Also the format of custom resources, which are declared in resource files by just giving the custom resource name or ordinal as the second word on the declaration. The format is very simple: It's ...

Code
Aug 26, 2013
Post comments count0
Post likes count0

Why doesn't the "Automatically move pointer to the default button in a dialog box" work for nonstandard dialog boxes, and how do I add it to my own nonstandard dialog boxes?

Raymond Chen
Raymond Chen

The Mouse control panel has a setting called Automatically move pointer to the default button in a dialog box, known informally as Snap to default button or simply Snap To. You may have discovered that it doesn't work for all dialog boxes. Why not? The Snap To feature is implemented by the dialog manager. When the window is shown and the setting...

CodeTips/Support
Aug 23, 2013
Post comments count0
Post likes count0

If I attach a file to an existing completion port, do I have to close the completion port handle a second time?

Raymond Chen
Raymond Chen

There are two ways of calling the function. You can pass a null pointer as the parameter, indicating that you would like to create a brand new completion port, associated with the file handle you passed (if you passed one). Or you can pass the handle of an existing completion port, and the file handle you passed will be associated with that por...

Code