Today's "Little Program" displays a button on the taskbar preview window. For now, the button increments a number, because incrementing numbers is so retro.

Welcome, visitor number  0 0 3 1 4

Start with the program from last week and make these changes:

int g_iCounter;

PaintContent(HWND hwnd, PAINTSTRUCT *pps)
  RECT rc;
  GetClientRect(hwnd, &rc);
  LOGFONTW lf = { 0 };
  lf.lfHeight = rc.bottom -;
  wcscpy_s(lf.lfFaceName, L"Verdana");
  HFONT hf = CreateFontIndirectW(&lf);
  HFONT hfPrev = SelectFont(pps->hdc, hf);
  wchar_t wszCount[80];
  swprintf_s(wszCount, L"%d", g_iCounter);
  DrawTextW(pps->hdc, wszCount, -1, &rc,
  SelectFont(pps->hdc, hfPrev);

That's an awful lot of typing just to print a big number on the screen.

#define IDC_INCREMENT 100

void CreateThumbBarButtons(HWND hwnd)
  THUMBBUTTON rgtb[1];
  rgtb[0].iId = IDC_INCREMENT;
  rgtb[0].hIcon = g_hicoAlert;
  rgtb[0].dwFlags = THBF_ENABLED;
  rgtb[0].dwMask = THB_ICON | THB_TOOLTIP | THB_FLAGS;
  wcscpy_s(rgtb[0].szTip, L"Increment the value");
  ITaskbarList3Ptr sptb3;
  sptb3->ThumbBarAddButtons(hwnd, 1, rgtb);

We define only one thumbbar button, and out of laziness, I just reuse that alert icon.

void OnCommand(HWND hwnd, int id, HWND hwndCtl, UINT codeNotify)
  switch (id) {
    InvalidateRect(hwnd, nullptr, TRUE);

When the button is pressed, we increment the counter and invalidate our window so we redraw with the new counter.

    // HANDLE_MSG(hwnd, WM_CHAR, OnChar);
    HANDLE_MSG(hwnd, WM_COMMAND, OnCommand);

      if (uiMsg != 0 && uiMsg == g_wmTaskbarButtonCreated) {

Okay, run the program, and then hover over the taskbar button so that the preview window appears. Hey, look, there's an alert icon button under the thumbnail.

Click it.

Boom, the number increments.

That's why I chose a huge font to draw the number: So it's big enough that you can see the number in the thumbnail.