• The Old New Thing

    I'm doing this instead of writing a book


    Some commenters mentioned that I should write a book. It turns out that writing a book is hard.

    A few years ago, MS Press actually approached me about writing a book for them. But I declined because the fashion for technical books is to take maybe fifty pages of information and pad it to a 700-page book, and I can't write that way. None of my topics would ever make it to a 100-page chapter. They're just little page-and-a-half vignettes. And it's not like the world needs yet another book on Win32 programming.

    So I'll just continue to babble here. It's easier.

  • The Old New Thing

    Low-tech usability testing

    My pal Jason Moore discusses using paper prototypes as a fast way to get usability feedback. I found it interesting that by going low-tech, you actually get better feedback, because people are more willing to criticize a paper model than running code. (And another advantage of the paper model is that you can make changes on the fly. If during the session you get the idea, "Maybe if I did it this way," you can grab a piece of paper, write on it, and insert it into the session instantly. Try doing that with running code.)
  • The Old New Thing

    Stupid memory-mapping tricks


    Shared memory is not just for sharing memory with other processes. It also lets you share memory with yourself in sneaky ways.

    For example, this sample program (all error checking and cleanup deleted for expository purposes) shows how you can map the same shared memory into two locations simultaneously. Since they are the same memory, modifications to one address are reflected at the other.

    #include <windows.h>
    #include <stdio.h>
    void __cdecl main(int argc, char **argv)
        HANDLE hfm = CreateFileMapping(INVALID_HANDLE_VALUE, NULL,
                        PAGE_READWRITE, 0, sizeof(DWORD), NULL);
        LPDWORD pdw1 = (LPDWORD)MapViewOfFile(hfm, FILE_MAP_WRITE,
                                              0, 0, sizeof(DWORD));
        LPDWORD pdw2 = (LPDWORD)MapViewOfFile(hfm, FILE_MAP_WRITE,
                                              0, 0, sizeof(DWORD));
        printf("Mapped to %x and %x\n", pdw1, pdw2);
        printf("*pdw1 = %d, *pdw2 = %d\n", *pdw1, *pdw2);
        /* Now watch this */
        *pdw1 = 42;
        printf("*pdw1 = %d, *pdw2 = %d\n", *pdw1, *pdw2);

    This program prints

    Mapped to 280000 and 290000
    *pdw1 = 0, *pdw2 = 0
    *pdw1 = 42, *pdw2 = 42

    (Missing asterisks added, 8am - thanks to commenter Tom for pointing this out.)

    The addresses may vary from run to run, but observe that the memory did get mapped to two different addresses, and changing one value to 42 magically changed the other.

    This is a nifty consequence of the way shared memory mapping works. I stumbled across it while investigating how I could copy large amounts of memory without actually copying it. The solution: Create a shared memory block, map it at one location, write to it, then unmap it from the old location and map it into the new location. Presto: The memory instantly "moved" to the new location. This a major win if the memory block is large, since you didn't have to allocate a second block, copy it, then free the old block - the memory block doesn't even get paged in.

    It turns out I never actually got around to using this trick, but it was a fun thing to discover anyway.
  • The Old New Thing

    Researchers discover link between music and drinking

    A British scientific study shows that a bit of classical music can persuade diners to buy more fancy coffees, pricey wines and luxurious desserts. "North has shown that playing German or French music can persuade diners to buy wine from those countries." I found this to be true in my experience. If you get two thousand people in a tent and play live oom-pah music, they end up drinking lots of German beer.
  • The Old New Thing

    Why does the System Properties page round the memory size?


    During Windows 95 beta testing, people ran the System Properties page and complained about "missing memory".

    The Windows 95 System Properties page reports the amount of memory available to Windows as system memory, which is not necessarily the same as the amount of memory installed in your computer.

    For example, you may have an old DOS device driver that allocates a large amount of memory for itself, which prevents Windows 95 from using it. Or you may have a dreaded UMA machine, where your so-called 8MB of memory is actually being divided between main system memory and video memory. So if you have an 8MB UMA machine and you're running at 800x600 8bpp, you actually have only 7.5MB of memory, since the other half-meg got eaten by the video card.

    When we displayed the actual amount of memory available to Windows, we got lots of bug reports from people asking, "I paid for 8MB of memory, where is it?"

    So Windows 95 takes the actual amount of memory and rounds it up to the nearest multiple of four megabytes and displays that.
  • The Old New Thing

    Why can't I use &-accelerators on the Start menu?


    The first letter of the program is the accelerator and there's nothing you can do about it. So if you have ten programs by Microsoft, they all use the accelerator "M". (Yes I hate this too. The first thing I do after installing a Microsoft program is go into the Start menu and delete the word "Microsoft" from the front.)

    For Win32 menus, the ampersand character acts as the marker for the menu accelerator. For example, you would set your menu text to "Save &As" to set Alt+A as the accelerator for the menu item.

    This isn't done for the Start menu and for the Favorites menu because the ampersand appears in program names occasionally. Otherwise, "AT&T Internet" would end up displaying as "ATT Internet". (This was a real problem in Windows 95, where the Start menu was constructed from your old Program Manager groups, and occasionally we'd run across one that had an ampersand in its name.)
  • The Old New Thing

    What do the text label colors mean for files?


    Blue means compressed; green means encrypted.

    This is an example of one of those "come on, it's a tiny, simple feature" requests. Yes, the code to do this isn't particularly complicated, but it adds another element of "Ha ha, I'm going to do something in a way that you will never be able to figure out unless somebody tells you."

    We get a lot of these little requests. If we accepted them all, you'd have icons with so many incomprehensible decorations you'd never be able to figure out what all the colors and markers mean.

    So the next time you say to yourself, "Windows should change the appearance of X if simple condition Y," imagine what it would be like if we actually did even twenty of those simple things.

    As my last example: What does it mean if an item on your Start menu is grey?
  • The Old New Thing

    Why does my Advanced Options dialog say ON and OFF after every option?


    Because Windows thinks a screenreader is running.

    If a screenreader is running, then the Advanced Options dialog will add "ON" and "OFF" to the end of each checkbox item so the screenreader program can read the state to a blind user.

  • The Old New Thing

    Jag skrivar svenska inte so bra.


    The nice thing about the schwa sound is that you don't have to spell it.

    Many thanks to C-J Berg for fixing my Swedish spelling errors. I probably introduced some new ones here, though.

    But why Swedish?

    Well, it wasn't Swedish initially. Many years ago, I saw an ad in the local newspaper that read, "Free Norwegian lessons, Tuesday nights at Xyz Church, Ballard." (Ballard is the Scandinavian neighborhood in Seattle.) I read it and though Norwegian lessons would be a fun, borderline goofy, thing to do. Especially since I figured most of the other people in the class were there because their parents forced them. When the Olympics were held a few years later in Lillehammer I was again inspired to learn Norwegian, because the sound of the language appealed to me.

    But it never really got past the "Gosh that would be fun" phase, until this year.

    A friend of mine moved to Sweden, so I figured, "Well, if I'm going to learn a Scandinavian language, Swedish seems the better choice now. And besides, it means I get to talk to the people who work at IKEA in their native language!" (Nevermind that the people who work at the Seattle IKEA probably don't speak Swedish anyway.)

    The hard part is trying to prevent Swedes from switching to English when they hear that your Swedish isn't native-fluent.
  • The Old New Thing

    Jag taler lita svenska.


    Attended my first formal Swedish lesson last night. It's great to recapture the simultaneous thrill and frustration of trying to have a conversation in a language you don't really know.

    It's a small class - Swedish isn't exactly one of the "big-name" languages out there. I always feel sorry for the student who can't seem to shake the bad American accent. I remember in high school, we had a student who spoke German with a thick Midwestern accent. It was painful to listen to.

    I thought it was just me, but it seems to be a common trait: When people are learning their third language and they get stuck, they instinctively fall back, not on their first language, but on their second. For me, it means that when I can't find the Swedish word for something, I substitute the German word. One of my classmates falls back on Spanish. (Technically, German isn't my second language, but I never got very good at the other language before German, so German acts as the de-facto second language.)

    I'm pretty sure nobody finds this fascinating aside from me...
Page 419 of 427 (4,268 items) «417418419420421»