The Old New Thing
Practical development throughout the evolution of Windows.
Latest posts
 
    How do I find the most recently created file in a directory from a batch file?
 
        We've reached Hump Day of Batch File Week. Remember, nobody actually likes batch programming. You merely tolerate it. Today, we'll find the most recently-created item in a directory. (For example, we have a server that holds our daily builds, and you might want to write a batch file that automatically installs the latest build.) There may be better ways, but what I do is ask for a list sorted oldest-to-newest, and then choose the last one. This trick works by asking the command to list just the names () of just the files , sorted by date (), based on the creation time (). Each time a new file is report...
 
    Reading the output of a command into a batch file variable
 
        It's Day Two of Batch File Week. Don't worry, it'll be over in a few days. There is no obvious way to read the output of a command into a batch file variable. In unix-style shells, this is done via backquoting. The Windows command processor does not have direct backquoting, but you can fake it by abusing the command. Here's the evolution: The flag to the command says that it should open the file you pass in parentheses and set the loop variable to the contents of each line. The loop variable in the command takes one percent sign if you are executing it directly from the command prompt, but two perc...
 
    Raymond's subjective, unfair, and completely wrong impressions of the opening ceremonies of a major athletic event which took place recently
 
        Like many other people, I watched the opening ceremonies of a major athletic event which took place a few days ago. (The organization responsible for the event has taken the step of blocking the mention of the name of the city hosting the event and the year the event takes place, or the name of the event itself except in editorial news pieces or journalistic statements of fact, of which this is neither, so I will endeavour to steer clear of the protected marks.) I wish somebody had let me know in advance that the opening ceremonies came with a reading list. I hope that at least the British history majors enjoy...
 
    Why don't any commands work after I run my batch file? I'm told that they are not recognized as an internal or external command, operable program, or batch file.
 
        I sort of forgot to celebrate CLR Week last year, so let's say that CLR week is "on hiatus" until next year. To fill the summertime time slot, I'm going to burn off a busted pilot: This week is Batch File Week 2012. Remember, nobody actually enjoys batch programming. It's just something you have to put up with in order to get something done. Batch programming is the COBOL of Windows. (Who knows, if people actually like Batch File Week [fat chance], maybe it'll come back as a regular series.) We'll open Batch File Week with a simple puzzle. A customer reported that after running their batch file, almost no co...
 
    Psychic debugging: Why your IContextMenu::InvokeCommand never gets called
 
        A customer reported a problem with their shell context menu extension. I have implemented the shell extension, but when the user selects my custom menu item, my is never called. Can anyone please let me know what the problem could be and how to fix it? Since there really isn't much information provided in this request, I was forced to invoke my psychic powers. Actually, given what you know about shell context menu hosting, you probably know the answer too. My psychic powers tell me that you gave your menu item the wrong ID, or you returned the wrong value from . If the menu IDs do not lie in the range yo...
 
    A brief and also incomplete history of Windows localization
 
        The process by which Windows has been localized has changed over the years. Back in the days of 16-bit Windows, Windows was developed with a single target language: English. Just English. After Windows was complete and masters were sent off to the factory for duplication, the development team handed the source code over to the localization teams. "Hey, by the way, we shipped a new version of Windows. Go localize it, will ya?" While the code that was written for the English version was careful to put localizable content in resources, there were often English-specific assumptions hard-coded into the source code...
 
    One way to make sure you pass an array of the correct size
 
        Another entry in the very sporadic series of "very strange code I've seen." The code has been changed to protect the guilty, but the essence has been preserved.
 
    Taking flexitarianism to another, perhaps unintended, level
 
        Our cafeteria has been trying to encourage flexitarianism, which it defines as eating one meat-free meal per week. But in their effort to make the concept more appealing, they may have lost sight of the goal. (The "Vegetarian Option" magnet was probably intended for the Asparagus, Mushroom and Spinach Pizette just above it.) One of my colleagues suggested that the sign was applying the transitive property of vegeterianism: "If you eat that which eats plants, you too eat the plants." Fool me twice: The following day, the "Vegetarian Option" magnet was placed on the sign for the meatball pizza. Maybe they're tr...
 
    What's the story behind the WM_SYNCPAINT message?
 
        Danail wants to know the story behind the message. The documentation pretty much tells the story. When a window has been hidden, shown, moved or sized, the system may determine that it needs to send a message to the windows of other threads. This message must be passed to , which will send the and messages to the window as necessary. When you call the function, the window manager updates the window size, position, whatever, and then it goes around repainting the windows that were affected by the operation. By default, the function does a quick-repaint of the windows before returning. After the function ...
