The Old New Thing
Practical development throughout the evolution of Windows.
Latest posts
How do I extract an icon at a nonstandard size if IExtractIcon::Extract tells me to go jump in a lake?
Commenter Ivo notes that if you ask to extract an icon at a particular size, the function can return which means "Go jump in a lake do it yourself." But how can you do it yourself? The and functions don't let you specify a custom size, and doesn't work with icon indices (only resource IDs). The function comes to the rescue. This takes all the parameters of (plus a bonus flags parameter), and it will actually do an extraction. Let's extract an icon from Explorer at 48×48, just for illustration. As usual, start with our scratch program, then make these changes: Run the program, and observe th...
The StartRunNoHOMEPATH policy affects whether the user's HOME path is the current directory when you use Start.Run, but make sure you read that carefully
A customer (via the customer liaison) discovered that even though they had set the policy, they found "if the user creates a Notepad file, the file is searched in the user's HOME directory, in contradiction of policy," I asked the liaison to confirm: "The steps you describe are rather vague. Are you saying that the problem occurs when the user opens the Run dialog and types ?" The customer liaison replied, "I believe the scenario is close to what you describe. The user opens the Run dialog, types , then types some text into Notepad and then does a Save As. I will confirm with the customer." A few days later...
Why does the common file save dialog create a temporary file and then delete it?
When you call , the common file save dialog will ask the user to choose a file name, and just before it returns it does a little create/delete dance where it creates the file the user entered, and then deletes it. What's up with that? This is a leftover from the ancient days of 16-bit Windows 3.1, back when file systems were real file systems and didn't have this namby-pamby "long file name" or "security" nonsense. (Insert sound effect of muscle flexing and gutteral grunting.) Back in those days, the file system interface was MS-DOS, and MS-DOS didn't have a way to query security attributes because, well, ...
Showing a balloon tip at a specific position, then removing it
Today's Little Program shows a balloon tip at a specific position, then manually removes it. Start with our scratch program and make these changes: When our main window is created, we also create a balloon-style tooltip and add a tracking tool. Normally, the tooltip control appears and disappears automatically, at a position of the tooltip's choosing. Tracking tooltips are managed manually, so you can specify exactly when and where they appear, and you also manually remove them from the screen. At startup, we add the tool but do not show the balloon tooltip yet. When the user presses the space bar, we get...
A discovered quirk is just few steps away from becoming a feature
Commenter Cherry wonders who invented all those strange syntaxes, like to show all environment variables, including the hidden ones. An interesting historical note is the origin of the convention in unix that files whose names begin with a dot are hidden by default (here's the relevant portion). That article highlights how a discovered quirk is just a few steps away from becoming a feature. As Master Yoda might put it: Discovery leads to dissemination. Dissemination leads to adoption. Adoption leads to entrenchment. Entrenchment creates a compatibility constraint. As I've noted many times, the batch la...
I thought you could use SWP_FRAMECHANGED to force a control to recalculate its properties after a change in styles
Simon Cooke dug back into his memory and asked, "Doesn't calling with cause a recreate and re-apply of the styles?" The flag does not recreate anything, but it does reapply the styles, as far as it knows. Recall that the bits in the window style break into two parts. There are the styles managed by the window manager, which are in the upper 16 bits, and there are the styles that are specific to each control, which are in the lower 16 bits. The window manager knows about the styles that it manages, but it has no clue about the styles that are specific to each control. It has no idea that the style control...
How do I programmatically create folders like My Pictures if they were manually deleted?
A corporate customer had a problem with their employees accidentally deleting folders like Videos and Pictures and are looking for a way to restore them, short of blowing away the entire user profile and starting over. They found some techniques on the Internet but they don't always work consistently or completely. What is the recommended way of recreating these missing folders? It turns out that the customer was asking a question that I answered many years ago, but looking at it from the other side. To recreate a folder, call with the flag , or call and pass . If you are targeting Windows Vista or higher,...
Le Chatelier's Principle in action: Administrative overrides
Today we have another example of Le Chatelier's Principle as interpreted by John Gall: Every system resists its proper functioning. There was a video card manufacturer which was using the key so that they could inject their DLL into every process. I have no idea why. Perhaps to get a nice bonus. In Windows Vista, the registry key was deactivated for both engineering and security reasons. Oh no! Undeterred, the video card manufacturer issued an update to their driver so that in addition to adding themselves to , they also set the administrative override switch that re-enabled the feature. Boom, they probab...
How can I get information about the items in the Recycle Bin from script?
Today we'll do a scripting version of an old C++ program: Printing information about the items in the Recycle Bin. (How you wish to act on the information is up to you.) This is a pattern we've seen a lot. Bind to a folder, enumerate its contents, extract properties. Wow, that was way easier than doing it in C++! Just for fun, I'll do it in C#, first as a straight port: We have to cast to because the default interface for the method is , but is a method on . We didn't have to do this explicit cast in JavaScript because JavaScript is a dynamically-typed language. So let's use the keyword to mimi...