• The Old New Thing

    Contradictory feedback from my 2005 PDC talk

    • 10 Comments

    I was looking through the feedback from my 2005 PDC talk, and I noticed an interesting contradiction. The written feedback indicated that the first half of my talk (wherein I talked about memory management and "paying your taxes") was more favorably-received than the second half (on user interface issues). On the other hand, nearly all of the questions people asked afterwards were about the user interface issues. "Wow, that thing about parent and owner windows, I think that's why my program is crashing," or "Gosh, synchronized input explains this problem we've been having."

    I've been told that "the quality of the questions you get after a talk is the best indicator of a talk's success", so I'm inclined to go with the people who were more interested in the second half than the first half. (Of course, the increased interest in the second half might just mean that I did a worse job in that part and people needed to come up to me to clarify the things I did poorly!)

    Maybe my next title should be "Story Time with Raymond". It could be the only 100-level talk at the PDC.

  • The Old New Thing

    Coming to the completely opposite conclusion on Windows versions

    • 22 Comments

    When I discussed why there is no all-encompassing superset version of Windows, people somehow interpreted this as an explanation of why there are so many versions of Windows Vista. I guess these people never even made it past the title of the article, which argues for fewer Windows versions, not more! Besides, the article talked about the server side of Windows, not the workstation side. The target audiences for servers are very different from the target audiences for workstations. (At least some people were able to follow my point.)

    The list of Windows Vista versions was news to me as much as it was news to you. It's not like everybody tells me what's going on at this company, or that I'd have the time to keep up on it if they did! (There's so much going on here, I can't even keep track of what my colleagues on the shell team are doing, and they work on my hallway! When I want Windows news, I turn to Paul Thurrott just like everybody else.) At least it appears that the people who want the all-encompassing superset version of Windows Vista Workstation will have their wish with the "Ultimate" plan.

  • The Old New Thing

    Black(out) humor at the 2005 PDC

    • 7 Comments

    Trying to make light (get it? light?) of the situation, there were quite a few jokes about the power outage at the PDC. The Hands-On Lab was being set up at the time the building went dark. A bunch of us speculated what the technicians must have been thinking when the power went out just as they plugged in a rack of computers... Perhaps in reaction to this, the "Frequently-Used Tasks" section of the Hands-On Labs software included a new task: Cause Power Outage. I of course couldn't resist and clicked on it. "Shame on you!" it roared back at me.

  • The Old New Thing

    Giving fair warning before plugging in your computer

    • 17 Comments

    That colleague who gave me the AOL CD that came with a big-iron server later received a prototype Itanium computer for testing purposes. The early Itaniums were behemoths. They weighed a ton, sounded like a weed whacker, and put out enough heat to keep you comfortably warm through the winter. (If you opened them up, you would likely see several carefully-shaped Styrofoam blocks with the label "Do not remove! Engineering styrofoam!" I never thought I would ever see the phrase "engineering styrofoam" used seriously. Note: Styrofoam® is a registered trademark of the Dow Chemical Company; consequently, it should be capitalized. The generic term is "foamed polystyrene". Mind you, the Dow Chemical Company also claims to have trademarked the color Blue [see **].)

    Never one to read all the safety labels before playing with a new toy, my colleague took the heavy-duty double-capacity power cables and ran them to the normal wall socket. Then he threw the power switch.

    And the power went out in the entire building wing.

    The power surge from the Itanium overloaded the poor wall socket and tripped the wing's circuit breaker. Everybody went through the standard power outage drill, while speculating amongst themselves what the cause for this one might be.

    It didn't take long for word to get out. "Fred plugged in his Itanium." (Not his real name.)

    After the electricians came by to check that everything was okay, they reset the circuit breaker and everybody got back to work.

    My colleague re-cabled the machine to be more friendly to the building's power circuitry. Then he sent out email to the entire team.

    "I'm turning it on!"

    Everbody laughed.

    And then hit Ctrl+S just in case.

  • 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.]

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