+
+LRESULT CALLBACK
+DownloadProgressProc(HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam, UINT_PTR uIdSubclass, DWORD_PTR dwRefData)
+{
+ static WCHAR szProgressText[MAX_STR_LEN] = {0};
+
+ switch (uMsg)
+ {
+ case WM_SETTEXT:
+ {
+ if (lParam)
+ wcscpy(szProgressText, (WCHAR *)lParam);
+ }
+
+ case WM_ERASEBKGND:
+ case WM_PAINT:
+ {
+ PAINTSTRUCT ps;
+ HDC hDC = BeginPaint(hWnd, &ps), hdcMem;
+ HBITMAP hbmMem;
+ HANDLE hOld;
+ RECT myRect;
+ UINT win_width, win_height;
+
+ GetClientRect(hWnd, &myRect);
+
+ /* grab the progress bar rect size */
+ win_width = myRect.right - myRect.left;
+ win_height = myRect.bottom - myRect.top;
+
+ /* create an off-screen DC for double-buffering */
+ hdcMem = CreateCompatibleDC(hDC);
+ hbmMem = CreateCompatibleBitmap(hDC, win_width, win_height);
+
+ hOld = SelectObject(hdcMem, hbmMem);
+
+ /* call the original draw code and redirect it to our memory buffer */
+ DefSubclassProc(hWnd, uMsg, (WPARAM)hdcMem, lParam);
+
+ /* draw our nifty progress text over it */
+ SelectFont(hdcMem, GetStockFont(DEFAULT_GUI_FONT));
+ DrawShadowText(hdcMem, szProgressText, wcslen(szProgressText),
+ &myRect,
+ DT_CENTER | DT_VCENTER | DT_NOPREFIX | DT_SINGLELINE,
+ GetSysColor(COLOR_CAPTIONTEXT),
+ GetSysColor(COLOR_3DSHADOW),
+ 1, 1);
+
+ /* transfer the off-screen DC to the screen */
+ BitBlt(hDC, 0, 0, win_width, win_height, hdcMem, 0, 0, SRCCOPY);
+
+ /* free the off-screen DC */
+ SelectObject(hdcMem, hOld);
+ DeleteObject(hbmMem);
+ DeleteDC(hdcMem);
+
+ EndPaint(hWnd, &ps);
+ return 0;
+ }
+
+ /* Raymond Chen says that we should safely unsubclass all the things!
+ (http://blogs.msdn.com/b/oldnewthing/archive/2003/11/11/55653.aspx) */
+ case WM_NCDESTROY:
+ {
+ ZeroMemory(szProgressText, MAX_STR_LEN);
+ RemoveWindowSubclass(hWnd, DownloadProgressProc, uIdSubclass);
+ }
+
+ default:
+ return DefSubclassProc(hWnd, uMsg, wParam, lParam);
+ }
+}
+