April, 2008

  • The Old New Thing

    Why doesn't Explorer let you create a file whose name begins with a dot?

    • 111 Comments

    Rolf Viehmann asks why Explorer doesn't let you create a file whose name begins with a dot.

    Such files are considered to have an extension but no name. If the extension is known and the user has chosen to hide known extensions, the resulting file would have no name at all!

    If you really want to create a file with a leading dot in its name, you are free to do so. You can do it from the command line or use your favorite file management tool. And then you can watch the file show up with no name and then observe the confusion that ensues. Maybe you're lucky and don't run any programs that freak out when a file has no name. If so, then more power to you.

    If it really bugs you that you can't do it from Explorer, you are free to write your own shell extension to do "Rename this file, and if I'm going to shoot myself in the foot, then let me."

  • The Old New Thing

    One-line batch script to delete empty directories

    • 49 Comments

    You don't need a whole 260KB program to do it. This batch file does the trick just fine:

    for /f "usebackq" %%d in (`"dir /ad/b/s | sort /R"`) do rd "%%d"
    

    I call it rdempty.cmd.

    This is the long-forgotten follow-up to Performing an operation in each subdirectory of a directory tree from batch. We're using the same technique as in that article, but pumping the result through "| sort /R" to reverse the order of the enumeration so we enumerate the directories bottom-up rather than top-down. This is important for deleting empty directories because you have to remove the subdirectories before you remove the parent.

    Disclaimer: I doubt anybody actually enjoys working with batch files, but that doesn't mean that tips on using it more effectively aren't valid. If you would rather gouge your eyes out than use the confusing command prompt batch language, then you are more than welcome to use the scripting language of your choice instead. At no point in this article am I saying that this is the only way or the best way to do it. But it's definitely smaller than a 260KB program.

  • The Old New Thing

    Windows doesn't close windows when a user logs off; that's your call

    • 48 Comments

    Commenter Peter Kankowski asks why Windows doesn't send WM_CLOSE and WM_DESTROY messages when the user logs off.

    That's what WM_ENDSESSION is for. To tell the program that the Windows session is ending, and that you should get done whatever last things you want to get done before the world comes to an end.

    Windows doesn't send the WM_CLOSE message because sending WM_CLOSE becomes complicated once there is more than one window. What is the correct order for sending WM_CLOSE when there are multiple windows? Besides, many programs don't respond to WM_CLOSE by closing. Instant messenger programs typically treat WM_CLOSE to mean "hide" rather than "close". Notepad displays an unsaved data warning when you close the window. And of course, you can't close a disabled window.

    As we saw with Notepad, sending a WM_CLOSE would just repeat actions that were taken during WM_ENDSESSION, which is particularly bad because the time for user interaction is over. WM_QUERYENDSESSION is the time to say your last good-byes. If Windows sent the WM_CLOSE message during logoff, Notepad would display a "You have unsaved changes. Do you want to save this file?" message after the user already said, "Go ahead and exit without saving," when Notepad handled the WM_QUERYENDSESSION message. "Stupid computer. Why is it asking me this question again?" Even worse, what if the user says "Cancel"? It's too late; shutdown has begun. Your chance to cancel it was back when you got the WM_QUERYENDSESSION message.

    Asking for the WM_DESTROY message is even weirder, since that message is not sent explicitly but is rather generated when DestroyWindow is called. You can't just send it outside of a destroy sequence.

    Besides, why spend your time closing windows when the session is about to go away anyway? Ooh, let me clean up this and destroy that, I know you asked to shut down, but this'll just take a few seconds. It's like taking the time to steam-clean the rugs before you demolish the building. Wasted effort.

    Now, you might respond, "Yeah, sure, these are problems, but we should just require programs to address them, such as not putting up additional UI if they get a WM_CLOSE after a WM_ENDSESSION." Of course, this argument contradicts the rationale for the original question, since the question was inspired by programs that didn't handle the WM_ENDSESSION correctly in the first place! "We have a problem with programs that don't handle the WM_ENDSESSION message correctly. Solution: Make WM_ENDSESSION more complicated."

  • The Old New Thing

    The dead desktop computer: The good, the bad, and the ugly, but not in that order

    • 48 Comments

    When last we left my dead desktop computer, it had fried its second video card, and I was considering whether I should get a third.

    I did indeed get a third video card, a cheap one since I knew that if the computer really did eat video cards, I'd have to feed it on a budget. I plugged it in, and...

    Computer still dead. Bad.

    Remove the video card, and the computer boots up.

    Okay, so the computer doesn't actually eat video cards. The problem is that the PCI Express slot is dead, for whatever reason, be it a fried component, a failing power supply, who knows.

    While I was back behind the computer, I noticed an unused plug: Yup, it was for VGA video output. I plugged in a VGA video cable, and, leaving the PCI Express video card unplugged, turned on the computer. Lo and behold, the computer started up and sent images out the VGA cable. Good.

    I didn't realize that the motherboard has an onboard video card. In the absence of a plug-in video card, the onboard video card takes over and pumps out video just fine. I don't use the computer for anything video-intensive, so a lame, underpowered video card is just fine by me.

    The problem is that the onboard video card has only VGA out, so I'm running an analog signal to my LCD monitor. Ugly.

    But at least it's a situation I can live with for now.

  • The Old New Thing

    Use the #error directive to check whether the compiler even sees you

    • 47 Comments

    You may find yourself in a twisty maze of #ifdefs. Or you may be wondering why your macros aren't working.

    I have these lines in my header file:

    #define MM_BUSY     0x0001
    #define MM_IDLE     0x0002
    

    but when I try to use them, I get errors.

    sample.cpp(23): error C2065: 'MM_BUSY': undeclared identifier
    sample.cpp(40): error C2065: 'MM_IDLE': undeclared identifier
    

    Any idea why this is happening?

    First, make sure the compiler even sees you. Notice that for macros, generating a preprocessed file doesn't accomplish anything since #defines don't show up in the preprocessor output. (They are preprocessor input.) What I do is use the #error directive. Add it to the header file and recompile.

    #define MM_BUSY     0x0001
    #define MM_IDLE     0x0002
    #error Did we get here?
    

    If you get

    sample.h(80) : error C1189: #error :  Did we get here?
    

    then you know that the line is indeed being compiled and that somebody after you is doing an #undef MM_BUSY. If not, then you get to investigate why the lines in the header file are being ignored. For example, they might be hidden by an #ifdef, or (if you're using Visual Studio with precompiled headers), your #include directive might be ignored due to an overriding precompiled header directive. You can scatter #error directives into other parts of the header file (or other header files) to narrow down why your lines are being skipped.

  • The Old New Thing

    We can't cut that; it's our last feature

    • 38 Comments

    Many years ago, I was asked to help a customer with a problem they were having. I don't remember the details, and they aren't important to the story anyway, but as I was investigating one of their crashes, I started to wonder why they were even doing it.

    I expressed my concerns to the customer liaison. "Why are they writing this code in the first place? The performance will be terrible, and it'll never work exactly the way they want it to."

    The customer liaison confided, "Yeah, I thought the same thing. But this is a feature they're adding to the next version of their product. The product is so far behind schedule, they've been cutting features like mad to get back on track. But they can't cut this feature. It's the last one left!"

  • The Old New Thing

    21: like 24 but three hours shorter

    • 38 Comments

    When I first heard that a new project titled 21 was coming out, I simply assumed it was the same as 24, except that Jack Bauer gets some sleep.

    Pre-emptive snarky comment: "Somebody was clearly sleeping when they designed Vista."

  • The Old New Thing

    The contradictory dialog: Click Finish to begin

    • 38 Comments

    I was installing a program and its setup wizard said, and I am not making this up,

    Click Finish to begin installation.

    But wait, the weirdness doesn't end there. After you click Finish, the program installation completes, and then you get another page that tells you to click Close.

    This is misuse of the Finish button. Finish does not mean Almost finished. If the user clicks the Finish button, that's it. No more wizard pages. It's finished.

    The last two wizard pages should have read

    Click Next to begin installation.
    You have successfully installed LitWare 2.0. To close this wizard, click Finish.
  • The Old New Thing

    The double-click time tells the window manager how good your reflexes are

    • 37 Comments

    The double-click time is sort of the dialog unit of time. It's used as the basis for many user interface time values that don't have their own custom setting. Here are just a few examples, along with the values you get if you leave the double-click time at its default of 500ms:

    • The default tooltip timeouts are based on the double-click time. (Initial: 0.5s, autopop: 5s, reshow: 0.1s.)
    • Incremental searching in list boxes resets after 4 times the double click time (2s).
    • When you click and hold over a scroll bar arrow, autorepeat begins after 4/5 of the double-click time has elapsed (.4s), and autorepeat occurs at one tenth of the double-click time (0.05s = 20 repeats per second).
    • The menu speed used to be 4/5 of the double click speed (0.4s), but now it has its own setting (SPI_SETMENUSHOWDELAY).

    If you go into the mouse control panel and speed up your double-click speed, then you'll find that other user interface operations tend to speed up as well. The double-click time is a sort of barometer for how good the user's reaction time is. If you set it too low, you may find that things just happen too fast.

  • The Old New Thing

    The concrete pedestrian bridge in the Washington Park Arboretum claims another victim

    • 35 Comments

    Spanning the main road through the Washington Park Arboretum is a pedestrian bridge, formally known as the Arboretum Sewer Trestle (you don't need me to explain why). The bridge is marked Clearance: 9'0". There are warnings posted far in advance. There is even a laser sensor above the road which triggers flashing yellow warning lights if an over-height vehicle approaches.

    Despite all these precautions and warnings, people still crash into the bridge with alarming frequency, at least according to one of my colleagues who drives under that bridge every day. (If you ask the Department of Transportation—as my colleague did—how often vehicles strike the bridge, you'll get a number far, far below the actual number. Probably because most of the incidents go unreported.) The evidence by the side of the road suggests that the accidents are usually caused by somebody who forgot that he's pulling a U-Haul behind him.

    Or maybe it was a bus carrying a high school softball team.

    The driver of the bus was blindly following the instructions of his GPS navigation system and never saw the flashing lights or the clearance sign. He figured the route must have been good, because he set the GPS to bus mode. You can read the article to find out why that didn't work.

    Remember folks, it's great that you have a computer to give you directions, but it's still your responsibility to drive the vehicle.

    Bonus chatter: My bridge-obsessed colleague also introduced me to the Om Nom Nom Nom meme by forwarding a picture of the crash site with a pair of googly eyes drawn on the bridge overpass. Here's an interview with the source of the phrase om nom nom nom.

    Oh, and my bridge-obsessed colleague also wishes somebody would install a web-cam pointed at the bridge: When the laser detects an imminent collision, it starts recording!

Page 1 of 5 (41 items) 12345