The Old New Thing

Practical development throughout the evolution of Windows.

Latest posts

Dec 6, 2010
Post comments count 0
Post likes count 1

TrackMouseEvent tracks mouse events in your window, but only if the events belong to your window

Raymond Chen

Greg Williams wonders why fails to detect mouse hover events when responding to Do­Drag­Drop callbacks. "My suspicion is that monopolizes the window so that a message is never posted, so it won't end up being useful." That's basically it, for the appropriate sense of the word "monopolize." The monitors mouse events that take place in your window and notifies your window when events of interest occur. But this requires that the events actually take place in your window! The function calls so that it can carry out the task of following the mouse anywhere on the screen. Recall that mouse events nor...

Dec 3, 2010
Post comments count 0
Post likes count 1

ZOMG! This program is using 100% CPU!1! Think of the puppies!!11!!1!1!eleven

Raymond Chen

Calm down.

Dec 2, 2010
Post comments count 0
Post likes count 1

The alignment declaration specifier is in bytes, not bits

Raymond Chen

Explicit object alignment is not something most people worry about when writing code, which means that when you decide to worry about it, you may be a bit rusty on how the declarations work. (After all, if it's something you worried about all the time, then you wouldn't have trouble remembering how to do it!) I was looking at some customer code, and there was a class who had a data member with an explicit alignment declaration. I pointed out that the comment didn't match the code. The comment says that the variable needs to be DWORD-aligned (which in Windows-speak means aligned on a 32-bit boundary), but th...

Dec 1, 2010
Post comments count 0
Post likes count 0

I will be speaking at TechEd China 2010 today

Raymond Chen

As I've mentioned a few times by now, the way to get me to show up at your event is to invite me. The easiest (i.e. cheapest) way is to hold your event in the Seattle area so that my travel expenses are effectively zero; I just use my bus pass. The folks at TechEd China 2010, on the other hand, had to fly me all the way out to Beijing, which is where I've been this week. Preparing these talks is a lot of work, because each one is different. It's not like I have a "stock presentation" that I give over and over. So even if you invite me, I may decline because I simply don't have the time to write up a new present...

Dec 1, 2010
Post comments count 0
Post likes count 1

How do I delete bytes from the beginning of a file?

Raymond Chen

It's easy to append bytes to the end of a file: Just open it for writing, seek to the end, and start writing. It's also easy to delete bytes from the end of a file: Seek to the point where you want the file to be truncated and call . But how do you delete bytes from the beginning of a file? You can't, but you sort of can, even though you can't. The underlying abstract model for storage of file contents is in the form of a chunk of bytes, each indexed by the file offset. The reason appending bytes and truncating bytes is so easy is that doing so doesn't alter the file offsets of any other bytes in the file. I...

Nov 30, 2010
Post comments count 0
Post likes count 1

Microspeak: Take-away

Raymond Chen

At Microsoft, the take-away is the essential message of a presentation or the conclusion that you are expected to draw from a situation. It is something you are expected to remember when the whole thing is over, a piece of information you take away with you as you leave the room. XYZ demo take away (title of a document) The preferred intensifier is key, and you probably see it attached to the phrase take-away more often than not. This example comes from a presentation on the results of a user study: Results: XYZ Tough to Use In fact, every single slide in this presentation had a bullet point at the botto...

Nov 29, 2010
Post comments count 0
Post likes count 1

What were Get/SetMessageExtraInfo ever used for?

Raymond Chen

KJK::Hyperion asks, "Could you shed some light on Get/SetMessageExtraInfo? It's almost like nobody on earth used them, ever, and I can't get some sample code." Yup, that's about right. Nobody on earth (to within experimental error) ever used them. These functions were introduced on July 20, 1990 (I'm looking at the change history right now) at the request of what was then called the Hand-Writing Windows group, which shipped the first version of Windows for Pen Computing in 1992. The idea was that each input event from the custom pen hardware would have this extra information associated with it, and the software...

Nov 26, 2010
Post comments count 0
Post likes count 0

Watching the game of Telephone play out in five seconds

Raymond Chen

Some time ago, I spent the Thanksgiving holiday with my nieces (ages 3 and 5 at the time), and I overheard this conversation between them. "Thanksgiving is over." — Christmas is coming! "It's Christmas time!" — Today is Christmas!

Nov 26, 2010
Post comments count 0
Post likes count 1

The easy way out is to just answer the question: What is the current Explorer window looking at?

Raymond Chen

A customer had the following question: We have an application which copies and pastes files. Our problem is that we want to paste the files into the folder which corresponds to the currently active Windows Explorer window. Right now, we're using , but we find this method unsatisfactory because we want to replace Explorer's default file copy engine with our own custom one. Can you provide assistance? (And commenter wtroost had no clue why somebody would copy a file by sending window messages to Explorer. Well here you have it.) The easy way out is to answer the question: You can enumerate the active Explorer ...