August, 2005

  • The Old New Thing

    Microsoft Company Picnic 2005

    • 14 Comments

    This weekend, it was Microsoft's turn to rent Mountain Meadows Farm for the company picnic. As I noted last year, the picnic is put on by a company that just puts on company picnics all summer. In addition to Microsoft, they also do Alaska Air, Honeywell, T-Mobile, and Amazon.

    I decided to bicycle to the picnic this year. The route was approximately 25 miles from Marymoor Park (6046 W Lake Sammamish Pkwy NW, Redmond WA) to Mountain Meadows Farm (10106 422nd Ln SE, North Bend, WA: three out of four web-based mapping services can find the farm given the address) along State Highway 202. According to the Fat Cyclist, Highway 202 from Redmond to Fall City "is the very definition of 'rolling'." I'd have to agree. I was able to maintain 18–20mph without too much difficulty. (That little statistic lets all you cyclists figure out how much of a patsy I am in the bicycling scheme of things.) But of course it's the part right after Fall City that is the doozy, because that's where you climb from the base of Snoqualmie Falls to the top.

    A digression on Fat Cyclist: His web site is a riot. Read his commuting tips and his description of bicycling etiquette for starters. As a former Fat Cyclist myself, I wish him all the best. You can do it!

    When I started out bicycling, I had a jersey but just wore plain shorts even though I had a pair of those stupid-looking bicycle shorts. I didn't wear them because I didn't want to look like a poser. In my plain shorts, I would wave to other cyclists but they would just ignore me. One day I decided to wear the stupid-looking shorts and the world changed. Other cyclists would wave to me first! I suddenly had street cred. It was all about the shorts.

    Oh, right, biking to the company picnic. At Marymoor Park, I met up with a friend who had already put about fifty miles on his bicycle that morning just getting to the park. (So either he was already tired and I could look like a non-patsy, or he was all warmed up and I was toast. I couldn't tell which way it was going to go...) We headed out together, and about 15 miles into the trip, I blew a tire just before reaching Fall City.

    We pulled over and I pulled out my spare tube. Replaced the tube, put the wheel back on the bicycle, started pumping it up, and oh look the Presta valve snapped off inside the pump. Well that sucks, because I carried only one spare tube.

    Plan B: My friend pulled out his patch repair kit to fix the hole in the original tube, but, alas, the glue had dried up. We had patches but no rubber cement.

    Plan C: We called another friend who lives eight miles away, and he arrived with a patch kit. That patch kit had glue! Unfortunately, the glue didn't take.

    Plan D: Fortunately, he also brought a glueless patch kit. We cleaned the tube of glue and applied the glueless patch. It seemed to hold, though there was a little leakage when the tube was over-inflated. Since we didn't really have any options left regarding patch kits, we decided to go with it and see what happens.

    What happened is that the patch didn't hold and we pulled over in Fall City just a few hundred meters later.

    Plan E: We called my friend's girlfriend who was originally going to meet us at the picnic, telling her where we were and asking her to come pick us up. She ultimately arrived, we loaded the bicycles onto the carrier, and drove the rest of the way to the company picnic.

    Clearly the bicycling gods were trying to tell me something. I apologized to my friend for ruining the ride, but he pointed out that if a spare tube and three patch kits can't fix it, you can't really be blamed for a blown tube.

    At the picnic, we met up with our mutual friend Wendy and hung out, along the way squeezing in a game of what seemed like "multi-ball four-way soccer dodgeball in an inflatable moon walk". It made no sense, but that was probably the point. Wendy didn't join us; she stayed outside and took several "butt pictures", according to her description. I'm not sure I want to see those pictures...

    Curiously, we didn't experience the twenty-minute wait for water that JVert warned about... Probably because we didn't make it to the picnic until 2pm, by which time the lunch crush was over.

  • The Old New Thing

    Rendering standard Windows elements

    • 15 Comments

    The DrawFrameControl function allows you to render standard Windows elements in your custom controls. Let's start by simply rendering a selected radio button. Start with our new scratch program and make this very simple change:

    class RootWindow : public Window
    {
     ...
    protected:
     void PaintContent(PAINTSTRUCT *pps);
     ...
    };
    
    void RootWindow::PaintContent(PAINTSTRUCT *pps)
    {
     RECT rc = { 0, 0, 32, 32 };
     DrawFrameControl(pps->hdc, &rc, DFC_BUTTON,
                      DFCS_BUTTONRADIO | DFCS_CHECKED);
    }
    

    When you run the program, you'll see a little radio button in the corner. Woo-hoo.

    You might also notice that it's an unthemed radio button. To get a themed radio button, you need to use the theme-drawing functions defined in the uxtheme.h header file. Let's make the following further changes:

    class RootWindow : public Window
    {
     ...
    protected:
     void OpenTheme() { m_htheme = OpenThemeData(m_hwnd, L"Button"); }
     void CloseTheme()
     {
      if (m_htheme) { CloseThemeData(m_htheme); m_htheme = NULL; }
     }
     RootWindow() : m_htheme(NULL) { }
     ~RootWindow() { CloseTheme(); }
     ...
    };
    
    LRESULT RootWindow::OnCreate()
    {
     OpenTheme();
     return 0;
    }
    
    void RootWindow::PaintContent(PAINTSTRUCT *pps)
    {
     RECT rc = { 0, 0, 32, 32 };
     if (m_htheme) {
      DrawThemeBackground(m_htheme, pps->hdc,
                          BP_RADIOBUTTON, RBS_CHECKEDNORMAL,
                          &rc, NULL);
     } else {
      DrawFrameControl(pps->hdc, &rc, DFC_BUTTON,
                       DFCS_BUTTONRADIO | DFCS_CHECKED);
     }
    }
    
    LRESULT RootWindow::HandleMessage(...)
    {
     ...
      case WM_THEMECHANGED:
       CloseTheme();
       OpenTheme();
       break;
     ...
    }
    

    This new version attempts to open the "Button" theme for the window when the window is created. If themes are not enabled, then this call will fail. When it comes time to draw, we see whether we have a theme available. If so, then we use the DrawThemeBackground function to draw it; otherwise, we draw it the unthemed way. Of course, we close the theme handle at destruction, and we also refresh the theme handle if the user changes the theme.

    If you run this new program with themes enabled, then you will get the pretty themed radio button instead of the old-fashioned unthemed radio button.

    Next time, we'll look at the trickier menu bitmaps.

Page 5 of 5 (42 items) 12345