Showing results for Code - The Old New Thing

May 28, 2010
Post comments count0
Post likes count0

How do I accept files to be opened via IDropTarget instead of on the command line? – bonus content

Raymond Chen
Raymond Chen

One of my colleagues tipped me off to some additional resources on the subject of using the DropTarget technique for accepting files for execution. First, it turns out that there is an SDK sample that demonstrates the DropTarget technique after all. This sample is fifteen years late according to one commenter who apparently thinks that the Plat...

Code
May 28, 2010
Post comments count0
Post likes count0

Every window with the WS_SYSMENU style has a system menu, but it's not there until it needs to be

Raymond Chen
Raymond Chen

I mentioned last time that there's an optimization in the treatment of the system menu which significantly reduces the number of menus in the system. When a window has the window style, it has a system menu, but until somebody calls on that window, nobody knows what its menu handle is. Until that point, the window manager doesn't actually have ...

Code
May 27, 2010
Post comments count0
Post likes count0

When will the window manager destroy a menu automatically, and when do I need to do it manually?

Raymond Chen
Raymond Chen

Our old friend Norman Diamond wonders when you are supposed to destroy a menu and when you are supposed to let Windows destroy it. The rules for when the window manager implicitly destroys menus are actually not that complicated. Outside of the above situations, you are on your own. Of course, when I write that "you are on your own" I do ...

Code
May 26, 2010
Post comments count0
Post likes count0

How do I find the bounding box for a character in a font?

Raymond Chen
Raymond Chen

A customer had the following question: I'm looking for a way to get the height of text which consists entirely of digits, for example , as these characters do not have any descent or internal leading. I expected functions like to return the character's ascent minus the internal leading, but in fact it returns the ascent plus the descent plus t...

Code
May 21, 2010
Post comments count0
Post likes count0

SHAutoComplete giveth, and SHAutoComplete taketh away

Raymond Chen
Raymond Chen

The function lets you attach autocomplete functionality to an edit control, and there are flags that describe what sources you want the autocomplete to draw from. If you call a second time, the second set of flags replace the original flags. The flags do not accumulate. For example, if you first call , and then you later call , the result is tha...

Code
May 20, 2010
Post comments count0
Post likes count0

We've traced the call and it's coming from inside the house: Operating system names

Raymond Chen
Raymond Chen

As the Windows Server 2003 project wound down, somebody reported a serious bug that went something like this: Subject: Windows Server 2003 still refers to itself as Windows .NET Server Previous versions of Windows report the product name correctly, but Windows Server 2003 still calls itself "Windows .NET Server" instead of Windows Server 2003...

Code
May 3, 2010
Post comments count0
Post likes count0

How do I accept files to be opened via IDropTarget instead of on the command line?

Raymond Chen
Raymond Chen

Commenter Yaron wants to know how to use the new IDropTarget mechanism for receiving a list of files to open. (Also asked by Anthony Wieser as a comment to an article.) The MSDN documentation on Verbs and File Assocations mentions that DDE has been deprecated as a way of launching documents and that you should use the DropTarget method instead....

Code
Apr 30, 2010
Post comments count0
Post likes count0

If it's not yours, then don't mess with it without permission from the owner

Raymond Chen
Raymond Chen

It's surprising how many principles of real life also apply to computer programming. For example, one of the rules of thumb for real life is that is that if something doesn't belong to you, then you shouldn't mess with it unless you have permission from the owner. If you want to ride Jimmy's bike, then you need to have Jimmy's permission. Even if J...

Code
Apr 29, 2010
Post comments count0
Post likes count0

A short puzzle about heap expansion

Raymond Chen
Raymond Chen

At the 2008 PDC, somebody stopped by the Ask the Experts table with a question about the heap manager. I don't understand why the heap manager is allocating a new segment. I allocated a bunch of small blocks, then freed nearly all of them. And then when my program makes a large allocation, it allocates a new segment instead of reusing the mem...

Code
Apr 23, 2010
Post comments count0
Post likes count0

Why can't I get my regular expression pattern to match words that begin with %?

Raymond Chen
Raymond Chen

A customer asked for help writing a regular expression that, in the customer's words, matched the string when it appeared as a standalone word. One of the things that people often forget to do when asking a question is to describe the things that they tried and what the results were. This is important information to include, because it saves th...

Code