• The Old New Thing

    Please disconnect all cell phones, signal watches, and pagers

    • 4 Comments

    Last Saturday night, a group of us (including butt photographer Wendy) attended a performance of the Seattle Symphony consisting of the world premiere of the orchestral arrangement of Shafer Mahoney's Sparkle, Richard Strauss' Don Quixote (with guest soloist Lynn Harrell) and concluding with Brahms' Fourth Symphony. I was pleasantly surprised by the Mahoney. World premieres are a hit or miss affair (mostly miss), but Sparkle had wit and direction. It had the feel of an overture, because when it was over, I was expecting Act One to start. And even today, I can remember bits and pieces of it. If only all world premieres had such stickiness.

    I didn't have high hopes for Don Quixote either, but for the opposite reason from Sparkle: Instead of being apprehensive for the unknown, I was dreading the known. In my opinion, the piece merely rambles on and on, and last night's performance... rambled on and on. About a quarter of the way through, the muffled electronic tones of a cell phone could be heard. Imagine our surprise when the guest soloist himself reached into his jacket pocket, pulled out his mobile telephone, and disengaged the ringer! My seats were in the center of the third row, so I had an excellent view of this surreal scene. (The first-desk second violins, who were counting rests at the time, found this rather amusing.)

    The final piece was reassuringly Brahms. I wallowed in the melancholy of the falling thirds and the lyricism of the Andante, and smiled to myself whenever I caught the opening theme returning in a different guise. The performance seemed to rush in places, during which the orchestra had some difficulty keeping together, but I was satisfied overall. (Of the four symphonies, this one has the weakest ending, in my opinion. It feels like he went, "Oh, right this is the last variation, I should put a big chord here.")

    It so happens that my seat was positioned such that I was in the line of sight of the second first violin as well as the second second violin. When they were looking at their music, they were looking pretty much directly at me; it was kind of creepy. I could see their eyes dart from the music to their stand partner to the conductor. Both of them are long-time symphony members so I recognized them quickly enough, but my previous seats were much further away, so I only knew them from afar. Up close, I could read the expressions on their faces. The second first is really their acting concertmaster who sits second because the Seattle Symphony is auditioning for a permanent concertmaster after a messy break-up with the previous concertmaster. She was all business, hardly cracking a smile the entire time; this is something that is completely lost on me when I'm in the upper orchestra much less the third balcony. (I had to scour the program to figure out who the guest concertmaster was this evening. Elisabeth Adkins' name was dropped into the program incidentally in a paragraph attributed to Gerard Schwarz. She wasn't listed as a guest artist or in the orchestra roster. It appears that Ms. Adkins is a finalist in the concertmaster search. She did a fine job on stage, but the real work of the concertmaster is behind the scenes, so I don't know how well she fared there.)

    Here's what Wendy had to say about the concert.

  • The Old New Thing

    Things to do at Microsoft when the power goes out

    • 46 Comments

    When the power goes out, the first thing you notice is how quiet everything becomes. The hum of the computers in the building stops. You hear... nothing.

    Bask in its peaceful silence.

    The next thing you do is turn off all the machines in your office, because you don't want to stress the power grid and network when the power eventually returns by having a hundred thousand computers all firing themselves up and joining the network at the same time.

    Of course, another thing you need to do is find your way around. This can be quite a challenge if you're in a lab with no windows and no emergency lighting: It suddenly becomes pitch black! Laptop computers prove useful at this point. Fire up notepad and maximize it, resulting in an all-white screen. Use that screen as a flashlight to navigate through the lab turning off computers and eventually leading yourself out of the lab to daylight.

    Next time, a story of an employee-induced power outage.

  • The Old New Thing

    Corrections to the answers I gave at the end of my PDC talk

    • 16 Comments

    I guess one advantage of having a web site is that I can publish errata. I haven't watched the Channel9 video (and probably never will; it's hard to watch yourself), but I do remember some of the questions at the end that I wasn't able to answer off the top of my head, but after a few days' research I think I can do it now.

    The person who asked "When I call MessageBox from my MFC application and shut down the system, why does my application crash?" stopped by the Fundamentals Lounge later that day, and we went into more detail about his problem. It turns out that he was a victim of one of the bullet points I called out in the section on parents and owners: He was passing NULL as the owner window to MessageBox, which created two top-level unowned windows on the same thread, something I also explained earlier this year when discussing the importance of setting the correct owner for modal UI. As a result, the handling of the shutdown message resulted in the support for the message box being torn down while it was still live on the stack. (I didn't cover this in my talk because I didn't want to bore people with information they could already have gotten by reading my earlier articles. After all, the talk wasn't titled "Raymond's Greatest Hits".)

    I made a mistake in my answer to the question about transferring input due to a mistaken input queue assignment due to a hole in a regional window. In fact, the message does not move between input queues; the window manager does a full hit-test against the region before deciding which input queue gets the message. The point of queue transfer is not to transfer the message, as I mistakenly described, but rather is to transfer the wake flag. If there are two input messages in an input queue, one for thread A and the second for thread B, then it is thread A that is woken first to process the input. When thread A processes the first message and then goes back to ask for the second message, the queue manager sees that the next message in the input queue is for thread B. At this point, it wakes up thread B and tells it that it is being woken due to an input transfer: "It's your turn now."

    It so happens that as you all came to my talk to check me out, I had spies in the crowd checking you out. Sara Ford, a Microsoft celebrity in her own right, told me that the buzz in the crowd was that I'm so short. Well, in my defense, I would like to point out that being on a raised platform makes me look shorter since the front of the table takes about six inches off my height due to the angle.

    But yeah, I'm short.

    And I'll take it as a compliment that you don't consider me to be old or fat.

    For those who were wondering: What was I doing when I was fiddling with the second computer on the table? That computer was running a giant clock program so I could see how I was doing on time. For some strange reason, the standard PDC equipment for a talk doesn't include a clock! I was fiddling with it because I forgot to disable the screen saver, so I had to wake up the computer periodically in order to keep the clock visible.

    Note that I never said that I never wanted to be on video. What I said was that I don't do interviews.

    Assuming the PDC organizers ask me back for the next PDC (big assumption) what do you think the title of my next talk should be?

  • The Old New Thing

    Why doesn't Microsoft give every employee a UPS?

    • 30 Comments

    One reaction to my story about the oldest computer at Microsoft still doing useful work was shock (shock!) that Microsoft suffers from power outages.

    In the Pacific Northwest, winter windstorms are quite common, and it is not unexpected that a windstorm blow down tall trees (which are also quite common) which in turn take out power lines. And if those power lines supply Microsoft main campus, then main campus loses power.

    All the critical computers have UPSs so that they can make a soft landing when the power goes out, but it's hardly the case that every single computer in every office and lab gets a UPS. That would be prohibitively expensive and wouldn't accomplish much anyway. Sure, each of the five computers in your office might stay alive for another fifteen minutes, but this assumes that you're actually in your office to shut them down cleanly when the power goes out. If your machine is frozen into the debugger, no amount of software-automated shutdown will help. (A frozen machine cannot shut itself down.)

    In other words, the cost-benefit of giving every employee a UPS for each machine in their office simply doesn't pan out.

    In the last few days of 1999, the main Windows development building was prepared for a wholesale catastrophe. Generator trucks were brought in so that the entire building could be kept up and running should the power fail as part of a worldwide Year 2000 meltdown. Those trucks were huge and no doubt extremely expensive.

    And thankfully were never needed.

    Those who were in Los Angeles last week for the PDC might be amused to learn that the PDC technical staff, fearing a repeat of Monday's blackout, rented a generator truck to provide emergency backup power for all the machines on stage for Bill Gates' and Jim Allchin's keynote addresses. The power may go out in Los Angeles, but the PDC keynote must go on!

    More musings about power outages next time.

  • The Old New Thing

    Fiddling with the fonts, part 2: Keeping the English font small

    • 14 Comments

    We concluded last time that we wanted the custom large font to apply only to the columns containing Chinese characters and leave the original font in place for the English columns. We do this by carrying two fonts around, choosing the appropriate one for each column.

    class RootWindow : public Window
    {
     ...
    private:
     HWND m_hwndLV;
     HWND m_hwndEdit;
     HWND m_hwndLastFocus;
     HFONT m_hfChinese;
     HFONT m_hfNormal;
     int  m_cyEdit;
     ...
    }
    
    RootWindow::RootWindow()
     : m_hfChinese(NULL)
     , m_hfNormal(NULL)
    {
    }
    
    RootWindow::~RootWindow()
    {
     if (m_hfChinese) DeleteObject(m_hfChinese);
     if (m_hfNormal) DeleteObject(m_hfNormal);
    }
    
    LRESULT RootWindow::OnCreate()
    {
     ...
     ListView_SetExtendedListViewStyleEx(m_hwndLV,
                                         LVS_EX_FULLROWSELECT,
                                         LVS_EX_FULLROWSELECT);
    
     LOGFONT lf;
     if (!GetObject(GetWindowFont(m_hwndLV), sizeof(lf), &lf)) {
      return -1;
     }
     m_hfNormal = CreateFontIndirect(&lf);
     if (!m_hfNormal) return -1;
     lf.lfHeight += lf.lfHeight / 2; // 50% bigger
     m_hfChinese = CreateFontIndirect(&lf);
     if (!m_hfChinese) return -1;
     SetWindowFont(m_hwndLV, m_hfChinese, FALSE);
     ...
    }
    

    Before we change the default font for the list view to the Chinese font, we create a copy of the original font (which we rather presumptuously call "normal") for safekeeping. Next, when the list view asks us to customize a column, we select the appropriate font and return the "I also changed the font" code.

    LRESULT RootWindow::OnLVCustomDraw(NMLVCUSTOMDRAW* pcd)
    {
     ...
     case CDDS_ITEMPREPAINT | CDDS_SUBITEM:
      pcd->clrText = m_clrTextNormal;
      if (pcd->iSubItem == COL_SIMP &&
        pcd->nmcd.dwItemSpec < (DWORD)Length()) {
        const DictionaryEntry& de = Item(pcd->nmcd.dwItemSpec);
        if (de.m_pszSimp) {
          pcd->clrText = RGB(0x80, 0x00, 0x00);
        }
      }
      // break;
      if (pcd->iSubItem == COL_TRAD || pcd->iSubItem == COL_SIMP) {
        SelectFont(pcd->nmcd.hdc, m_hfChinese);
      } else {
        SelectFont(pcd->nmcd.hdc, m_hfNormal);
      }
      return CDRF_NEWFONT;
     ...
    }
    

    There are several important details here.

    First, we set the Chinese font as the "overall" font for the list view. It would have been easier for us not to do this; after all, since we explicitly set the font for each column, why does it matter what the default font is? It also would have removed the need to create a copy of the original font. But if you delete the SetWindowFont(m_hwndLV, m_hfChinese); line, the bottoms of the Chinese characters get cut off. The reason is that the list view uses the default font to decide what the line spacing should be. Therefore, the default font for the list view needs to be the largest font we intend to use for any column.

    Why does the list view use the default font to decide on the line spacing? Because it's not clairevoyant. That's the only font it has, after all. It doesn't know what font you're going to select in your CDDS_ITEMPREPAINT | CDDS_SUBITEM notification handler. All it has is the font you set with SetWindowFont.

    Another important detail is that once we have decided to use different fonts for different columns, we are committed to selecting a font for all columns. The reason for this was discussed when we discussed how to colorize the columns.

    Finally, there is the important detail of returning the CDRF_NEWFONT value when we change the font. For performance reasons, the list view assumes you aren't changing the font on a subitem-by-subitem basis (since very few list views do) and it caches many font properties to avoid having to recalculate them all the time. Returning CDRF_NEWFONT indicates that the list view should look at the font you selected and base its computations on that font instead.

    Since boldface, italics and underline are font attributes, you can use this "select a custom font" technique to make selected items display as boldface, italics, or underline, in addition to using it to change the font size as we did here.

    That's all for this month. Next month will be a rather boring one, adding a status bar to make the Chinese characters even more readable. After that, we'll enhance the dictionary lookup algorithm, which is itself groundwork for dynamic translation, as I may have alluded to in a previous entry.

    [Raymond is currently away; this message was pre-recorded.]

  • The Old New Thing

    Fiddling with the fonts, part 1: Making the Chinese characters larger

    • 16 Comments

    Let's pay a quick visit to our continuing dictionary project. One of the things you may have noticed is that the Chinese characters are unreadably small. Let's fix that by making them larger.

    class RootWindow : public Window
    {
    public:
     virtual LPCTSTR ClassName() { return TEXT("Scratch"); }
     static RootWindow *Create();
     RootWindow();
     ~RootWindow();
     ...
    private:
     HWND m_hwndLV;
     HWND m_hwndEdit;
     HWND m_hwndLastFocus;
     HFONT m_hfChinese;
     int  m_cyEdit;
     ...
    }
    
    RootWindow::RootWindow()
     : m_hfChinese(NULL)
    {
    }
    
    RootWindow::~RootWindow()
    {
     if (m_hfChinese) DeleteObject(m_hfChinese);
    }
    
    LRESULT RootWindow::OnCreate()
    {
     ...
     ListView_SetExtendedListViewStyleEx(m_hwndLV,
                                         LVS_EX_FULLROWSELECT,
                                         LVS_EX_FULLROWSELECT);
    
     LOGFONT lf;
     if (!GetObject(GetWindowFont(m_hwndLV), sizeof(lf), &lf)) {
      return -1;
     }
     lf.lfHeight += lf.lfHeight / 2; // 50% bigger
     m_hfChinese = CreateFontIndirect(&lf);
     if (!m_hfChinese) return -1;
     SetWindowFont(m_hwndLV, m_hfChinese, FALSE);
    
     LVCOLUMN lvc;
     ...
    }
    

    This magnifies the font in the list view by 50% by taking the current font, increasing the height, and creating a new font, which we select into the list view.

    This works in that the font is indeed bigger, but it's bigger even for the English part, and that larger-than-normal English font looks kind of out of place. The English was perfectly fine at its original size, after all. It was only the Chinese we wanted to enlarge. (This will become more important later on when we turn the program into a dynamic translator.)

    We'll look at this problem next time.

    [Raymond is currently away; this message was pre-recorded.]

  • The Old New Thing

    Typo patrol at the PDC

    • 10 Comments

    You can find the following typographical errors in the Big Room at the PDC:

    • Intergrated
    • Precison
    • Personel

    If you can locate all three of them and catch me at the PDC (say at the Fundamentals Lounge or at the Ask the Experts table), I'll award you a prize of um (rummaging through my bag) how about a retractable network cable? (Or an autographed business card? But then again, anybody can get one of those just by asking for one.)

  • The Old New Thing

    Like an invention out of Harry Potter, except that Harry's would use a quill

    • 4 Comments

    When I heard this story from Swedish Radio, it struck me as the sort of object that would exist in the imaginary world of Harry Potter. Raymond's bad translation follows:

    Pen can help dyslexics

    With today's cheaper and cheaper microelectronics, it becomes possible for young inventors to produce new products without a lot of resources. A new idea for a smart-pen for speech synthesis and voice recognition is an example of this.

    The pen intended primarily for dyslexics has been produced by Johan Strömbom, a student at the Chalmers University of Technology. It is a pen which produces speech from writing, and which converts your speech into text, explains Johan Strömbom.

    "One can read in text from a piece of paper, which is then heard in a headset, also one can speak text into the headset and have it written out," says Johan Strömbom.

    He was inspired to invent the pen by his mother who teaches dyslexics. The pen has been nominated for an inventor's prize at the Technical Fair in October.

    Of course, the Harry Potter version would be a quill instead of a pen, and it wouldn't need a headset. Or batteries.

    Voice recognition also has a lot of promise for people other than dyslexics. Imagine if you could take a voice recording and send it through a recognizer to produce a transcript. I can read Swedish and German much better than I can listen to it, and having a transcript of a news report as it happens would improve my understanding tremendously.

    [Raymond is currently away; this message was pre-recorded.]

  • The Old New Thing

    The double-Ctrl+Alt+Del feature is really a kludge

    • 39 Comments

    Most people who care about such things know that you can press Ctrl+Alt+Del twice from the Welcome screen and sometimes you will get a classic logon dialog. (Note: "Sometimes". It works only if the last operation was a restart or log-off, for complicated reasons that are irrelevant to this discussion.)

    The ability to do the double-Ctrl+Alt+Del was added as a fallback just in case there turned out to be some important logon scenario that the new Welcome screen failed to cover, but which the designers had failed to take into account by simple oversight. Scenarios such as smartcard or fingerprint logon.

    In other words, it's a kludge.

    In the time since Windows XP came out, the logon folks have kept an eye out to see if there indeed were any scenarios that weren't covered by the Welcome screen. I think the only one that came up was Kerberos authentication.

    Now that (once they fix the Kerberos problem) they have covered all the bases, the designers are probably going to feel more confident about the new logon design, and the double-Ctrl+Alt+Del panic button will likely be removed.

    So don't get too attached to it.

    This is why the Welcome screen shows that Administrator account if there are no other members of the Administrators group on the system: If it didn't show the Administrator account, you would be locked out of your own computer.

    "No I'm not. I can use the double-Ctrl+Alt+Del trick to log on as the Administrator."

    Well, okay, that works today, but you're relying on a panic button that might not be there tomorrow.

    [Raymond is currently away; this message was pre-recorded.]

  • The Old New Thing

    Sorry I missed you all this morning

    • 4 Comments

    Sorry to all you PDCers who stopped by the Fundamentals Lounge to see me. The scheduling software that the PDC organizers cooked up is, um, "suboptimal" and listed me for Tuesday 11.30a–2.30p instead of 2.30p–5.30p. During the early afternoon shift, I was actually in the Hands-On Lab. But I'll be in the Lounge on Thursday after my talk all afternoon, really.

    I will try to be in the Lounge on Wednesday, but I may have to take refuge in the Speaker Prep Room to deal with a major last-minute change to my talk.

    Whoa a huge stream of people just flooded in. I'll catch up with you folks later.

Page 366 of 455 (4,542 items) «364365366367368»