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

Belated happy first birthday, Windows 7

On Friday, the marketing folks informed me that they decided to put me on the Microsoft Careers United States home page in recognition of Windows 7's first birthday. It's an honor and to be honest a bit scary to be chosen to be the face of Windows on a day of such significance. (They told me that had narrowed it down to me and "some Director of Test". Sorry, Director of Test; maybe they'll pick you for Windows 7's second birthday.) I think my picture is still there (they didn't tell me how long it was going to be up), but here's a screen capture just to prove it to my relatives: ...

When you call a function, your code doesn't resume execution until that function returns

Consider this code fragment: When calls , and has not yet returned, does continue executing? Does get called before returns? No, it does not. The basic structure of the C/C++ language imposes sequential execution. Control does not return to the function until returns control, either by reaching the end of the function or by an explicit . Commenter Norman Diamond asks a bunch of questions, but they're all mooted by the first: I can't find any of the answers in MSDN, and even an answer to one doesn't make answers to others obvious. Unless failures occur, the DialogBox function doesn't return u...

The evolution of the ICO file format, part 4: PNG images

We finish our tour of the evolution of the ICO file format with the introduction of PNG-compressed images in Windows Vista. The natural way of introducing PNG support for icon images would be to allow the field of the to take the value , in which case the image would be represented not by a DIB but by a PNG. After all, that's why we have a field: For forward compatibility with future encoding systems. Wipe the dust off your hands and declare victory. Unfortunately, it wasn't that simple. If you actually try using ICO files in this format, you'll find that a number of popular icon-authoring tools crash w...

The evolution of the ICO file format, part 3: Alpha-blended images

Windows XP introduced the ability to provide icon images which contain an 8-bit alpha channel. Up until this point, you had only a 1-bit alpha channel, represented by a mask. The representation of an alpha-blended image in your ICO file is pretty straightforward. Recall that the old ICO format supports 0RGB 32bpp bitmaps. To use an alpha-blended image, just drop in a ARGB 32bpp bitmap instead. When the window manager sees a 32bpp bitmap, it looks at the alpha channel. If it's all zeroes, then it assumes that the image is in 0RGB format; otherwise it assumes it is in ARGB format. Everything else remains the ...

How do I get the dimensions of a cursor or icon?

Given a or a , how do you get the dimensions of the icon or cursor? The function gets you most of the way there, returning you an structure which gives you the mask and color bitmaps (and the hotspot, if a cursor). You can then use the function to get the attributes of the bitmap. And then here's the tricky part: You have to massage the data a bit. As we've learned over the past few days, an icon consists of two bitmaps, a mask and an image. A cursor is the same as an icon, but with a hotspot. To get the dimensions of the icon or cursor, just take the dimensions of the color bitmap. If you have one. ...

The evolution of the ICO file format, part 2: Now in color!

Last time, we looked at the format of classic monochrome icons. But if you want to include color images, too? (Note that it is legal—and for a time it was common—for a single ICO file to offer both monochrome and color icons. After all, a single ICO file can offer both 16-color and high-color images; why not also 2-color images?) The representation of color images in an ICO file is almost the same as the representation of monochrome images: All that changes is that the image bitmap is now in color. (The mask remains monochrome.) In other words, the image format consists of a where the is the width of the ima...

The evolution of the ICO file format, part 1: Monochrome beginnings

This week is devoted to the evolution of the ICO file format. Note that the icon resource format is different from the ICO file format; I'll save that topic for another day. The ICO file begins with a fixed header: must be zero, and must be 1. The describes how many images are included in this ICO file. An ICO file is really a collection of images; the theory is that each image is an alternate representation of the same underlying concept, but at different sizes and color depths. There is nothing to prevent you, in principle, from creating an ICO file where the 16×16 image looks nothing like the 32...

What does the FOF_NOCOPYSECURITYATTRIBS flag really do (or not do)?

In the old days, the shell copy engine didn't pay attention to ACLs. It just let the file system do whatever the default file system behavior was. The result was something like this: Perfectly logical, right? If a new file is created, then the security attributes are inherited from the container. If an existing file is moved, then its security attributes move with it. And since moving a file across drives was handled as a copy/delete, moving a file across drives behaved like a copy. Users, however, found this behavior confusing. For example, they would take a file from a private folder like their My Document...

The memcmp function reports the result of the comparison at the point of the first difference, but it can still read past that point

This story originally involved a more complex data structure, but that would have required too much explaining (with relatively little benefit since the data structure was not related to the moral of the story), so I'm going to retell it with double null-terminated strings as the data structure instead. Consider the following code to compare two double-null-terminated strings for equality: "Aha, this code is inefficient. Since the function stops comparing as soon as it finds a difference, I can skip the call to and simply write because we can never read past the end of : If the strings are equal, then...