Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse code

added code from 'The Old New Thing'

Signed-off-by: Stefan Naewe <stefan.naewe@atlas-elektronik.com>
  • Loading branch information...
commit 3921afbe58cea8526893eb28059c6e33e891a503 1 parent 31a4f55
authored January 19, 2009

Showing 49 changed files with 6,429 additions and 0 deletions. Show diff stats Hide diff stats

  1. 125  oldnewthing/079_scratch.cpp
  2. 145  oldnewthing/085_captionmenu.cpp
  3. 146  oldnewthing/087_usepopupmenu.cpp
  4. 157  oldnewthing/088_loadpopupmenu.cpp
  5. 146  oldnewthing/089_paint.cpp
  6. 156  oldnewthing/091_paint2.cpp
  7. 161  oldnewthing/092_covered.cpp
  8. 139  oldnewthing/095_tiling.cpp
  9. 150  oldnewthing/097_ellipse.cpp
  10. 138  oldnewthing/098_dcbrush.cpp
  11. 49  oldnewthing/100_exttextout.cpp
  12. 152  oldnewthing/102_stretchblt.cpp
  13. 197  oldnewthing/103_textoutfl.cpp
  14. 142  oldnewthing/109_uniscribe.cpp
  15. 170  oldnewthing/123_nonmodalfind.cpp
  16. 174  oldnewthing/125_modalfind.cpp
  17. 137  oldnewthing/129_wrongowner.cpp
  18. 137  oldnewthing/131_rightowner.cpp
  19. 49  oldnewthing/133_cheaptimedmbox.cpp
  20. 220  oldnewthing/136_timedmbox.cpp
  21. 17  oldnewthing/138_timedcontextmenu.cpp
  22. 101  oldnewthing/154_wldialog.cpp
  23. 117  oldnewthing/159_wldialog2.cpp
  24. 172  oldnewthing/207_nonmodal.cpp
  25. 211  oldnewthing/209_modal.cpp
  26. 212  oldnewthing/211_subtlety.cpp
  27. 219  oldnewthing/212_moresubtlety.cpp
  28. 87  oldnewthing/218_nestedinner.cpp
  29. 117  oldnewthing/222_resizeinner.cpp
  30. 4  oldnewthing/227_setdlgfocus.cpp
  31. 7  oldnewthing/228_dlgdisablewindow.cpp
  32. 214  oldnewthing/230_tab.cpp
  33. 174  oldnewthing/245_cpl.cpp
  34. 75  oldnewthing/259_cache.cpp
  35. 85  oldnewthing/262_cache2.cpp
  36. 29  oldnewthing/398_shared.cpp
  37. 137  oldnewthing/440_flickerdraw.cpp
  38. 158  oldnewthing/441_bufferdraw.cpp
  39. 160  oldnewthing/442_remotedraw.cpp
  40. 143  oldnewthing/443_fus.cpp
  41. 171  oldnewthing/455_power.cpp
  42. 163  oldnewthing/457_ipaddr.cpp
  43. 157  oldnewthing/459_cleartype.cpp
  44. 20  oldnewthing/462_dpi.cpp
  45. 7  oldnewthing/467_dpi.xml
  46. 24  oldnewthing/467_multimon.cpp
  47. 13  oldnewthing/470_workarea.cpp
  48. 372  oldnewthing/472_accessibility.cpp
  49. 173  oldnewthing/readme.txt
125  oldnewthing/079_scratch.cpp
... ...
@@ -0,0 +1,125 @@
  1
+#define STRICT
  2
+#include <windows.h>
  3
+#include <windowsx.h>
  4
+#include <ole2.h>
  5
+#include <commctrl.h>
  6
+#include <shlwapi.h>
  7
+
  8
+HINSTANCE g_hinst;                          /* This application's HINSTANCE */
  9
+HWND g_hwndChild;                           /* Optional child window */
  10
+
  11
+void
  12
+OnSize(HWND hwnd, UINT state, int cx, int cy)
  13
+{
  14
+    if (g_hwndChild) {
  15
+        MoveWindow(g_hwndChild, 0, 0, cx, cy, TRUE);
  16
+    }
  17
+}
  18
+
  19
+BOOL
  20
+OnCreate(HWND hwnd, LPCREATESTRUCT lpcs)
  21
+{
  22
+    return TRUE;
  23
+}
  24
+
  25
+void
  26
+OnDestroy(HWND hwnd)
  27
+{
  28
+    PostQuitMessage(0);
  29
+}
  30
+
  31
+void
  32
+PaintContent(HWND hwnd, PAINTSTRUCT *pps)
  33
+{
  34
+}
  35
+
  36
+void
  37
+OnPaint(HWND hwnd)
  38
+{
  39
+    PAINTSTRUCT ps;
  40
+    BeginPaint(hwnd, &ps);
  41
+    PaintContent(hwnd, &ps);
  42
+    EndPaint(hwnd, &ps);
  43
+}
  44
+
  45
+void
  46
+OnPrintClient(HWND hwnd, HDC hdc)
  47
+{
  48
+    PAINTSTRUCT ps;
  49
+    ps.hdc = hdc;
  50
+    GetClientRect(hwnd, &ps.rcPaint);
  51
+    ps.fErase = FALSE;
  52
+    PaintContent(hwnd, &ps);
  53
+}
  54
+
  55
+LRESULT CALLBACK
  56
+WndProc(HWND hwnd, UINT uiMsg, WPARAM wParam, LPARAM lParam)
  57
+{
  58
+    switch (uiMsg) {
  59
+    HANDLE_MSG(hwnd, WM_CREATE, OnCreate);
  60
+    HANDLE_MSG(hwnd, WM_SIZE, OnSize);
  61
+    HANDLE_MSG(hwnd, WM_DESTROY, OnDestroy);
  62
+    HANDLE_MSG(hwnd, WM_PAINT, OnPaint);
  63
+    case WM_PRINTCLIENT: OnPrintClient(hwnd, (HDC)wParam); return 0;
  64
+    }
  65
+
  66
+    return DefWindowProc(hwnd, uiMsg, wParam, lParam);
  67
+}
  68
+
  69
+BOOL
  70
+InitApp(void)
  71
+{
  72
+    WNDCLASS wc;
  73
+
  74
+    wc.style = 0;
  75
+    wc.lpfnWndProc = WndProc;
  76
+    wc.cbClsExtra = 0;
  77
+    wc.cbWndExtra = 0;
  78
+    wc.hInstance = g_hinst;
  79
+    wc.hIcon = NULL;
  80
+    wc.hCursor = LoadCursor(NULL, IDC_ARROW);
  81
+    wc.hbrBackground = (HBRUSH)(COLOR_WINDOW + 1);
  82
+    wc.lpszMenuName = NULL;
  83
+    wc.lpszClassName = TEXT("Scratch");
  84
+
  85
+    if (!RegisterClass(&wc)) return FALSE;
  86
+
  87
+    InitCommonControls();               /* In case we use a common control */
  88
+
  89
+    return TRUE;
  90
+}
  91
+
  92
+int WINAPI WinMain(HINSTANCE hinst, HINSTANCE hinstPrev,
  93
+                   LPSTR lpCmdLine, int nShowCmd)
  94
+{
  95
+    MSG msg;
  96
+    HWND hwnd;
  97
+
  98
+    g_hinst = hinst;
  99
+
  100
+    if (!InitApp()) return 0;
  101
+
  102
+    if (SUCCEEDED(CoInitialize(NULL))) {/* In case we use COM */
  103
+
  104
+        hwnd = CreateWindow(
  105
+            TEXT("Scratch"),                /* Class Name */
  106
+            TEXT("Scratch"),                /* Title */
  107
+            WS_OVERLAPPEDWINDOW,            /* Style */
  108
+            CW_USEDEFAULT, CW_USEDEFAULT,   /* Position */
  109
+            CW_USEDEFAULT, CW_USEDEFAULT,   /* Size */
  110
+            NULL,                           /* Parent */
  111
+            NULL,                           /* No menu */
  112
+            hinst,                          /* Instance */
  113
+            0);                             /* No special parameters */
  114
+
  115
+        ShowWindow(hwnd, nShowCmd);
  116
+
  117
+        while (GetMessage(&msg, NULL, 0, 0)) {
  118
+            TranslateMessage(&msg);
  119
+            DispatchMessage(&msg);
  120
+        }
  121
+        CoUninitialize();
  122
+    }
  123
+
  124
+    return 0;
  125
+}
145  oldnewthing/085_captionmenu.cpp
... ...
@@ -0,0 +1,145 @@
  1
+#define STRICT
  2
+#include <windows.h>
  3
+#include <windowsx.h>
  4
+#include <ole2.h>
  5
+#include <commctrl.h>
  6
+#include <shlwapi.h>
  7
+
  8
+HINSTANCE g_hinst;                          /* This application's HINSTANCE */
  9
+HWND g_hwndChild;                           /* Optional child window */
  10
+
  11
+void
  12
+OnSize(HWND hwnd, UINT state, int cx, int cy)
  13
+{
  14
+    if (g_hwndChild) {
  15
+        MoveWindow(g_hwndChild, 0, 0, cx, cy, TRUE);
  16
+    }
  17
+}
  18
+
  19
+BOOL
  20
+OnCreate(HWND hwnd, LPCREATESTRUCT lpcs)
  21
+{
  22
+    return TRUE;
  23
+}
  24
+
  25
+void
  26
+OnDestroy(HWND hwnd)
  27
+{
  28
+    PostQuitMessage(0);
  29
+}
  30
+
  31
+void
  32
+PaintContent(HWND hwnd, PAINTSTRUCT *pps)
  33
+{
  34
+}
  35
+
  36
+void
  37
+OnPaint(HWND hwnd)
  38
+{
  39
+    PAINTSTRUCT ps;
  40
+    BeginPaint(hwnd, &ps);
  41
+    PaintContent(hwnd, &ps);
  42
+    EndPaint(hwnd, &ps);
  43
+}
  44
+
  45
+void
  46
+OnPrintClient(HWND hwnd, HDC hdc)
  47
+{
  48
+    PAINTSTRUCT ps;
  49
+    ps.hdc = hdc;
  50
+    GetClientRect(hwnd, &ps.rcPaint);
  51
+    ps.fErase = FALSE;
  52
+    PaintContent(hwnd, &ps);
  53
+}
  54
+
  55
+LRESULT CALLBACK
  56
+WndProc(HWND hwnd, UINT uiMsg, WPARAM wParam, LPARAM lParam)
  57
+{
  58
+    switch (uiMsg) {
  59
+    HANDLE_MSG(hwnd, WM_CREATE, OnCreate);
  60
+    HANDLE_MSG(hwnd, WM_SIZE, OnSize);
  61
+    HANDLE_MSG(hwnd, WM_DESTROY, OnDestroy);
  62
+    HANDLE_MSG(hwnd, WM_PAINT, OnPaint);
  63
+    case WM_PRINTCLIENT: OnPrintClient(hwnd, (HDC)wParam); return 0;
  64
+
  65
+    case WM_CONTEXTMENU:
  66
+        if (lParam != -1 &&
  67
+            SendMessage(hwnd, WM_NCHITTEST,
  68
+                        0, lParam) == HTSYSMENU) {
  69
+            HMENU hmenu = CreatePopupMenu();
  70
+            if (hmenu) {
  71
+                AppendMenu(hmenu, MF_STRING, 1,
  72
+                           TEXT("Custom menu"));
  73
+                TrackPopupMenu(hmenu, TPM_LEFTALIGN |
  74
+                               TPM_TOPALIGN |
  75
+                               TPM_RIGHTBUTTON,
  76
+                               GET_X_LPARAM(lParam),
  77
+                               GET_Y_LPARAM(lParam), 0, hwnd,
  78
+                               NULL);
  79
+                DestroyMenu(hmenu);
  80
+            }
  81
+            return 0;
  82
+        }
  83
+        break;
  84
+    }
  85
+
  86
+    return DefWindowProc(hwnd, uiMsg, wParam, lParam);
  87
+}
  88
+
  89
+BOOL
  90
+InitApp(void)
  91
+{
  92
+    WNDCLASS wc;
  93
+
  94
+    wc.style = 0;
  95
+    wc.lpfnWndProc = WndProc;
  96
+    wc.cbClsExtra = 0;
  97
+    wc.cbWndExtra = 0;
  98
+    wc.hInstance = g_hinst;
  99
+    wc.hIcon = NULL;
  100
+    wc.hCursor = LoadCursor(NULL, IDC_ARROW);
  101
+    wc.hbrBackground = (HBRUSH)(COLOR_WINDOW + 1);
  102
+    wc.lpszMenuName = NULL;
  103
+    wc.lpszClassName = TEXT("Scratch");
  104
+
  105
+    if (!RegisterClass(&wc)) return FALSE;
  106
+
  107
+    InitCommonControls();               /* In case we use a common control */
  108
+
  109
+    return TRUE;
  110
+}
  111
+
  112
+int WINAPI WinMain(HINSTANCE hinst, HINSTANCE hinstPrev,
  113
+                   LPSTR lpCmdLine, int nShowCmd)
  114
+{
  115
+    MSG msg;
  116
+    HWND hwnd;
  117
+
  118
+    g_hinst = hinst;
  119
+
  120
+    if (!InitApp()) return 0;
  121
+
  122
+    if (SUCCEEDED(CoInitialize(NULL))) {/* In case we use COM */
  123
+
  124
+        hwnd = CreateWindow(
  125
+            TEXT("Scratch"),                /* Class Name */
  126
+            TEXT("Scratch"),                /* Title */
  127
+            WS_OVERLAPPEDWINDOW,            /* Style */
  128
+            CW_USEDEFAULT, CW_USEDEFAULT,   /* Position */
  129
+            CW_USEDEFAULT, CW_USEDEFAULT,   /* Size */
  130
+            NULL,                           /* Parent */
  131
+            NULL,                           /* No menu */
  132
+            hinst,                          /* Instance */
  133
+            0);                             /* No special parameters */
  134
+
  135
+        ShowWindow(hwnd, nShowCmd);
  136
+
  137
+        while (GetMessage(&msg, NULL, 0, 0)) {
  138
+            TranslateMessage(&msg);
  139
+            DispatchMessage(&msg);
  140
+        }
  141
+        CoUninitialize();
  142
+    }
  143
+
  144
+    return 0;
  145
+}
146  oldnewthing/087_usepopupmenu.cpp
... ...
@@ -0,0 +1,146 @@
  1
+#define STRICT
  2
+#include <windows.h>
  3
+#include <windowsx.h>
  4
+#include <ole2.h>
  5
+#include <commctrl.h>
  6
+#include <shlwapi.h>
  7
+
  8
+HINSTANCE g_hinst;                          /* This application's HINSTANCE */
  9
+HWND g_hwndChild;                           /* Optional child window */
  10
+
  11
+// Sample usage: UsePopupMenu(hwnd, g_hinst, MAKEINTRESOURCE(1), lParam);
  12
+void UsePopupMenu(HWND hwnd, HINSTANCE hinst, LPCTSTR pszMenu, LPARAM lParam)
  13
+{
  14
+    HMENU hmenu = LoadMenu(hinst, pszMenu);
  15
+    if (hmenu) {
  16
+        HMENU hmenuPopup = GetSubMenu(hmenu, 0);
  17
+        TrackPopupMenu(hmenuPopup,
  18
+                       TPM_LEFTALIGN | TPM_TOPALIGN | TPM_RIGHTBUTTON,
  19
+                       GET_X_LPARAM(lParam),
  20
+                       GET_Y_LPARAM(lParam), 0, hwnd, NULL);
  21
+        DestroyMenu(hmenu);
  22
+    }
  23
+}
  24
+
  25
+void
  26
+OnSize(HWND hwnd, UINT state, int cx, int cy)
  27
+{
  28
+    if (g_hwndChild) {
  29
+        MoveWindow(g_hwndChild, 0, 0, cx, cy, TRUE);
  30
+    }
  31
+}
  32
+
  33
+BOOL
  34
+OnCreate(HWND hwnd, LPCREATESTRUCT lpcs)
  35
+{
  36
+    return TRUE;
  37
+}
  38
+
  39
+void
  40
+OnDestroy(HWND hwnd)
  41
+{
  42
+    PostQuitMessage(0);
  43
+}
  44
+
  45
+void
  46
+PaintContent(HWND hwnd, PAINTSTRUCT *pps)
  47
+{
  48
+}
  49
+
  50
+void
  51
+OnPaint(HWND hwnd)
  52
+{
  53
+    PAINTSTRUCT ps;
  54
+    BeginPaint(hwnd, &ps);
  55
+    PaintContent(hwnd, &ps);
  56
+    EndPaint(hwnd, &ps);
  57
+}
  58
+
  59
+void
  60
+OnPrintClient(HWND hwnd, HDC hdc)
  61
+{
  62
+    PAINTSTRUCT ps;
  63
+    ps.hdc = hdc;
  64
+    GetClientRect(hwnd, &ps.rcPaint);
  65
+    ps.fErase = FALSE;
  66
+    PaintContent(hwnd, &ps);
  67
+}
  68
+
  69
+LRESULT CALLBACK
  70
+WndProc(HWND hwnd, UINT uiMsg, WPARAM wParam, LPARAM lParam)
  71
+{
  72
+    switch (uiMsg) {
  73
+    HANDLE_MSG(hwnd, WM_CREATE, OnCreate);
  74
+    HANDLE_MSG(hwnd, WM_SIZE, OnSize);
  75
+    HANDLE_MSG(hwnd, WM_DESTROY, OnDestroy);
  76
+    HANDLE_MSG(hwnd, WM_PAINT, OnPaint);
  77
+    case WM_PRINTCLIENT: OnPrintClient(hwnd, (HDC)wParam); return 0;
  78
+
  79
+    case WM_CONTEXTMENU:
  80
+        if (lParam != -1) {
  81
+            UsePopupMenu(hwnd, g_hinst, MAKEINTRESOURCE(1), lParam);
  82
+            return 0;
  83
+        }
  84
+        break;
  85
+    }
  86
+
  87
+    return DefWindowProc(hwnd, uiMsg, wParam, lParam);
  88
+}
  89
+
  90
+BOOL
  91
+InitApp(void)
  92
+{
  93
+    WNDCLASS wc;
  94
+
  95
+    wc.style = 0;
  96
+    wc.lpfnWndProc = WndProc;
  97
+    wc.cbClsExtra = 0;
  98
+    wc.cbWndExtra = 0;
  99
+    wc.hInstance = g_hinst;
  100
+    wc.hIcon = NULL;
  101
+    wc.hCursor = LoadCursor(NULL, IDC_ARROW);
  102
+    wc.hbrBackground = (HBRUSH)(COLOR_WINDOW + 1);
  103
+    wc.lpszMenuName = NULL;
  104
+    wc.lpszClassName = TEXT("Scratch");
  105
+
  106
+    if (!RegisterClass(&wc)) return FALSE;
  107
+
  108
+    InitCommonControls();               /* In case we use a common control */
  109
+
  110
+    return TRUE;
  111
+}
  112
+
  113
+int WINAPI WinMain(HINSTANCE hinst, HINSTANCE hinstPrev,
  114
+                   LPSTR lpCmdLine, int nShowCmd)
  115
+{
  116
+    MSG msg;
  117
+    HWND hwnd;
  118
+
  119
+    g_hinst = hinst;
  120
+
  121
+    if (!InitApp()) return 0;
  122
+
  123
+    if (SUCCEEDED(CoInitialize(NULL))) {/* In case we use COM */
  124
+
  125
+        hwnd = CreateWindow(
  126
+            TEXT("Scratch"),                /* Class Name */
  127
+            TEXT("Scratch"),                /* Title */
  128
+            WS_OVERLAPPEDWINDOW,            /* Style */
  129
+            CW_USEDEFAULT, CW_USEDEFAULT,   /* Position */
  130
+            CW_USEDEFAULT, CW_USEDEFAULT,   /* Size */
  131
+            NULL,                           /* Parent */
  132
+            NULL,                           /* No menu */
  133
+            hinst,                          /* Instance */
  134
+            0);                             /* No special parameters */
  135
+
  136
+        ShowWindow(hwnd, nShowCmd);
  137
+
  138
+        while (GetMessage(&msg, NULL, 0, 0)) {
  139
+            TranslateMessage(&msg);
  140
+            DispatchMessage(&msg);
  141
+        }
  142
+        CoUninitialize();
  143
+    }
  144
+
  145
+    return 0;
  146
+}
157  oldnewthing/088_loadpopupmenu.cpp
... ...
@@ -0,0 +1,157 @@
  1
+#define STRICT
  2
+#include <windows.h>
  3
+#include <windowsx.h>
  4
+#include <ole2.h>
  5
+#include <commctrl.h>
  6
+#include <shlwapi.h>
  7
+
  8
+HINSTANCE g_hinst;                          /* This application's HINSTANCE */
  9
+HWND g_hwndChild;                           /* Optional child window */
  10
+
  11
+HMENU LoadPopupMenu(HINSTANCE hinst, LPCTSTR pszMenu)
  12
+{
  13
+  HMENU hmenuPopup = NULL;
  14
+  HMENU hmenu = LoadMenu(hinst, pszMenu);
  15
+  if (hmenu) {
  16
+    hmenuPopup = GetSubMenu(hmenu, 0);
  17
+    RemoveMenu(hmenu, 0, MF_BYPOSITION);
  18
+    DestroyMenu(hmenu);
  19
+  }
  20
+  return hmenuPopup;
  21
+}
  22
+
  23
+// sample usage
  24
+void Sample(HWND hwnd, LPARAM lParam)
  25
+{
  26
+  HMENU hmenuPopup = LoadPopupMenu(g_hinst, MAKEINTRESOURCE(1));
  27
+  if (hmenuPopup) {
  28
+    TrackPopupMenu(hmenuPopup,
  29
+                   TPM_LEFTALIGN | TPM_TOPALIGN | TPM_RIGHTBUTTON,
  30
+                   GET_X_LPARAM(lParam),
  31
+                   GET_Y_LPARAM(lParam), 0, hwnd, NULL);
  32
+    DestroyMenu(hmenuPopup);
  33
+  }
  34
+}
  35
+
  36
+void
  37
+OnSize(HWND hwnd, UINT state, int cx, int cy)
  38
+{
  39
+    if (g_hwndChild) {
  40
+        MoveWindow(g_hwndChild, 0, 0, cx, cy, TRUE);
  41
+    }
  42
+}
  43
+
  44
+BOOL
  45
+OnCreate(HWND hwnd, LPCREATESTRUCT lpcs)
  46
+{
  47
+    return TRUE;
  48
+}
  49
+
  50
+void
  51
+OnDestroy(HWND hwnd)
  52
+{
  53
+    PostQuitMessage(0);
  54
+}
  55
+
  56
+void
  57
+PaintContent(HWND hwnd, PAINTSTRUCT *pps)
  58
+{
  59
+}
  60
+
  61
+void
  62
+OnPaint(HWND hwnd)
  63
+{
  64
+    PAINTSTRUCT ps;
  65
+    BeginPaint(hwnd, &ps);
  66
+    PaintContent(hwnd, &ps);
  67
+    EndPaint(hwnd, &ps);
  68
+}
  69
+
  70
+void
  71
+OnPrintClient(HWND hwnd, HDC hdc)
  72
+{
  73
+    PAINTSTRUCT ps;
  74
+    ps.hdc = hdc;
  75
+    GetClientRect(hwnd, &ps.rcPaint);
  76
+    ps.fErase = FALSE;
  77
+    PaintContent(hwnd, &ps);
  78
+}
  79
+
  80
+LRESULT CALLBACK
  81
+WndProc(HWND hwnd, UINT uiMsg, WPARAM wParam, LPARAM lParam)
  82
+{
  83
+    switch (uiMsg) {
  84
+    HANDLE_MSG(hwnd, WM_CREATE, OnCreate);
  85
+    HANDLE_MSG(hwnd, WM_SIZE, OnSize);
  86
+    HANDLE_MSG(hwnd, WM_DESTROY, OnDestroy);
  87
+    HANDLE_MSG(hwnd, WM_PAINT, OnPaint);
  88
+    case WM_PRINTCLIENT: OnPrintClient(hwnd, (HDC)wParam); return 0;
  89
+
  90
+    case WM_CONTEXTMENU:
  91
+        if (lParam != -1) {
  92
+            Sample(hwnd, lParam);
  93
+            return 0;
  94
+        }
  95
+        break;
  96
+    }
  97
+
  98
+    return DefWindowProc(hwnd, uiMsg, wParam, lParam);
  99
+}
  100
+
  101
+BOOL
  102
+InitApp(void)
  103
+{
  104
+    WNDCLASS wc;
  105
+
  106
+    wc.style = 0;
  107
+    wc.lpfnWndProc = WndProc;
  108
+    wc.cbClsExtra = 0;
  109
+    wc.cbWndExtra = 0;
  110
+    wc.hInstance = g_hinst;
  111
+    wc.hIcon = NULL;
  112
+    wc.hCursor = LoadCursor(NULL, IDC_ARROW);
  113
+    wc.hbrBackground = (HBRUSH)(COLOR_WINDOW + 1);
  114
+    wc.lpszMenuName = NULL;
  115
+    wc.lpszClassName = TEXT("Scratch");
  116
+
  117
+    if (!RegisterClass(&wc)) return FALSE;
  118
+
  119
+    InitCommonControls();               /* In case we use a common control */
  120
+
  121
+    return TRUE;
  122
+}
  123
+
  124
+int WINAPI WinMain(HINSTANCE hinst, HINSTANCE hinstPrev,
  125
+                   LPSTR lpCmdLine, int nShowCmd)
  126
+{
  127
+    MSG msg;
  128
+    HWND hwnd;
  129
+
  130
+    g_hinst = hinst;
  131
+
  132
+    if (!InitApp()) return 0;
  133
+
  134
+    if (SUCCEEDED(CoInitialize(NULL))) {/* In case we use COM */
  135
+
  136
+        hwnd = CreateWindow(
  137
+            TEXT("Scratch"),                /* Class Name */
  138
+            TEXT("Scratch"),                /* Title */
  139
+            WS_OVERLAPPEDWINDOW,            /* Style */
  140
+            CW_USEDEFAULT, CW_USEDEFAULT,   /* Position */
  141
+            CW_USEDEFAULT, CW_USEDEFAULT,   /* Size */
  142
+            NULL,                           /* Parent */
  143
+            NULL,                           /* No menu */
  144
+            hinst,                          /* Instance */
  145
+            0);                             /* No special parameters */
  146
+
  147
+        ShowWindow(hwnd, nShowCmd);
  148
+
  149
+        while (GetMessage(&msg, NULL, 0, 0)) {
  150
+            TranslateMessage(&msg);
  151
+            DispatchMessage(&msg);
  152
+        }
  153
+        CoUninitialize();
  154
+    }
  155
+
  156
+    return 0;
  157
+}
146  oldnewthing/089_paint.cpp
... ...
@@ -0,0 +1,146 @@
  1
+#define STRICT
  2
+#include <windows.h>
  3
+#include <windowsx.h>
  4
+#include <ole2.h>
  5
+#include <commctrl.h>
  6
+#include <shlwapi.h>
  7
+
  8
+HINSTANCE g_hinst;                          /* This application's HINSTANCE */
  9
+HWND g_hwndChild;                           /* Optional child window */
  10
+
  11
+void
  12
+OnSize(HWND hwnd, UINT state, int cx, int cy)
  13
+{
  14
+    if (g_hwndChild) {
  15
+        MoveWindow(g_hwndChild, 0, 0, cx, cy, TRUE);
  16
+    }
  17
+}
  18
+
  19
+BOOL
  20
+OnCreate(HWND hwnd, LPCREATESTRUCT lpcs)
  21
+{
  22
+    return TRUE;
  23
+}
  24
+
  25
+void
  26
+OnDestroy(HWND hwnd)
  27
+{
  28
+    PostQuitMessage(0);
  29
+}
  30
+
  31
+void
  32
+PaintContent(HWND hwnd, PAINTSTRUCT *pps)
  33
+{
  34
+    TCHAR szTime[100]; 
  35
+    if (GetTimeFormat(LOCALE_USER_DEFAULT, 0, NULL, NULL,
  36
+                      szTime, 100)) {
  37
+        SetWindowText(hwnd, szTime);
  38
+        TextOut(pps->hdc, 0, 0, szTime, lstrlen(szTime));
  39
+    }
  40
+}
  41
+
  42
+void CALLBACK
  43
+InvalidateAndKillTimer(HWND hwnd, UINT uMsg,
  44
+                       UINT_PTR idTimer, DWORD dwTime)
  45
+{
  46
+    KillTimer(hwnd, idTimer);
  47
+    InvalidateRect(hwnd, NULL, TRUE);
  48
+}
  49
+
  50
+void
  51
+OnPaint(HWND hwnd)
  52
+{
  53
+    PAINTSTRUCT ps;
  54
+    BeginPaint(hwnd, &ps);
  55
+    if (!IsRectEmpty(&ps.rcPaint)) {
  56
+        // compute time to next update - we update once a second
  57
+        SYSTEMTIME st;
  58
+        GetSystemTime(&st);
  59
+        DWORD dwTimeToNextTick = 1000 - st.wMilliseconds;
  60
+        SetTimer(hwnd, 1, dwTimeToNextTick, InvalidateAndKillTimer);
  61
+    }
  62
+    PaintContent(hwnd,&ps);
  63
+    EndPaint(hwnd, &ps);
  64
+} 
  65
+
  66
+void
  67
+OnPrintClient(HWND hwnd, HDC hdc)
  68
+{
  69
+    PAINTSTRUCT ps;
  70
+    ps.hdc = hdc;
  71
+    GetClientRect(hwnd, &ps.rcPaint);
  72
+    ps.fErase = FALSE;
  73
+    PaintContent(hwnd, &ps);
  74
+}
  75
+
  76
+LRESULT CALLBACK
  77
+WndProc(HWND hwnd, UINT uiMsg, WPARAM wParam, LPARAM lParam)
  78
+{
  79
+    switch (uiMsg) {
  80
+    HANDLE_MSG(hwnd, WM_CREATE, OnCreate);
  81
+    HANDLE_MSG(hwnd, WM_SIZE, OnSize);
  82
+    HANDLE_MSG(hwnd, WM_DESTROY, OnDestroy);
  83
+    HANDLE_MSG(hwnd, WM_PAINT, OnPaint);
  84
+    case WM_PRINTCLIENT: OnPrintClient(hwnd, (HDC)wParam); return 0;
  85
+    }
  86
+
  87
+    return DefWindowProc(hwnd, uiMsg, wParam, lParam);
  88
+}
  89
+
  90
+BOOL
  91
+InitApp(void)
  92
+{
  93
+    WNDCLASS wc;
  94
+
  95
+    wc.style = 0;
  96
+    wc.lpfnWndProc = WndProc;
  97
+    wc.cbClsExtra = 0;
  98
+    wc.cbWndExtra = 0;
  99
+    wc.hInstance = g_hinst;
  100
+    wc.hIcon = NULL;
  101
+    wc.hCursor = LoadCursor(NULL, IDC_ARROW);
  102
+    wc.hbrBackground = (HBRUSH)(COLOR_WINDOW + 1);
  103
+    wc.lpszMenuName = NULL;
  104
+    wc.lpszClassName = TEXT("Scratch");
  105
+
  106
+    if (!RegisterClass(&wc)) return FALSE;
  107
+
  108
+    InitCommonControls();               /* In case we use a common control */
  109
+
  110
+    return TRUE;
  111
+}
  112
+
  113
+int WINAPI WinMain(HINSTANCE hinst, HINSTANCE hinstPrev,
  114
+                   LPSTR lpCmdLine, int nShowCmd)
  115
+{
  116
+    MSG msg;
  117
+    HWND hwnd;
  118
+
  119
+    g_hinst = hinst;
  120
+
  121
+    if (!InitApp()) return 0;
  122
+
  123
+    if (SUCCEEDED(CoInitialize(NULL))) {/* In case we use COM */
  124
+
  125
+        hwnd = CreateWindow(
  126
+            TEXT("Scratch"),                /* Class Name */
  127
+            TEXT("Scratch"),                /* Title */
  128
+            WS_OVERLAPPEDWINDOW,            /* Style */
  129
+            CW_USEDEFAULT, CW_USEDEFAULT,   /* Position */
  130
+            CW_USEDEFAULT, CW_USEDEFAULT,   /* Size */
  131
+            NULL,                           /* Parent */
  132
+            NULL,                           /* No menu */
  133
+            hinst,                          /* Instance */
  134
+            0);                             /* No special parameters */
  135
+
  136
+        ShowWindow(hwnd, nShowCmd);
  137
+
  138
+        while (GetMessage(&msg, NULL, 0, 0)) {
  139
+            TranslateMessage(&msg);
  140
+            DispatchMessage(&msg);
  141
+        }
  142
+        CoUninitialize();
  143
+    }
  144
+
  145
+    return 0;
  146
+}
156  oldnewthing/091_paint2.cpp
... ...
@@ -0,0 +1,156 @@
  1
+#define STRICT
  2
+#include <windows.h>
  3
+#include <windowsx.h>
  4
+#include <ole2.h>
  5
+#include <commctrl.h>
  6
+#include <shlwapi.h>
  7
+
  8
+HINSTANCE g_hinst;                          /* This application's HINSTANCE */
  9
+HWND g_hwndChild;                           /* Optional child window */
  10
+
  11
+// We'll put our clock here
  12
+RECT g_rcClock = { 50, 50, 200, 100 };
  13
+
  14
+void
  15
+OnSize(HWND hwnd, UINT state, int cx, int cy)
  16
+{
  17
+    if (g_hwndChild) {
  18
+        MoveWindow(g_hwndChild, 0, 0, cx, cy, TRUE);
  19
+    }
  20
+}
  21
+
  22
+BOOL
  23
+OnCreate(HWND hwnd, LPCREATESTRUCT lpcs)
  24
+{
  25
+    return TRUE;
  26
+}
  27
+
  28
+void
  29
+OnDestroy(HWND hwnd)
  30
+{
  31
+    PostQuitMessage(0);
  32
+}
  33
+
  34
+void
  35
+PaintContent(HWND hwnd, PAINTSTRUCT *pps)
  36
+{
  37
+    TCHAR szTime[100];
  38
+    if (GetTimeFormat(LOCALE_USER_DEFAULT, 0, NULL, NULL, szTime,
  39
+                      100)) {
  40
+        SetWindowText(hwnd, szTime);
  41
+        COLORREF clrTextPrev = SetTextColor(pps->hdc,
  42
+                               GetSysColor(COLOR_HIGHLIGHTTEXT));
  43
+        COLORREF clrBkPrev = SetBkColor(pps->hdc,
  44
+                             GetSysColor(COLOR_HIGHLIGHT));
  45
+        ExtTextOut(pps->hdc, g_rcClock.left, g_rcClock.top,
  46
+                   ETO_CLIPPED | ETO_OPAQUE, &g_rcClock,
  47
+                   szTime, lstrlen(szTime), NULL);
  48
+        SetBkColor(pps->hdc, clrBkPrev);
  49
+        SetTextColor(pps->hdc, clrTextPrev);
  50
+    }
  51
+}
  52
+
  53
+void CALLBACK
  54
+InvalidateAndKillTimer(HWND hwnd, UINT uMsg,
  55
+                       UINT_PTR idTimer, DWORD dwTime) {
  56
+    KillTimer(hwnd, idTimer);
  57
+    InvalidateRect(hwnd, &g_rcClock, FALSE);
  58
+} 
  59
+
  60
+void
  61
+OnPaint(HWND hwnd)
  62
+{
  63
+    PAINTSTRUCT ps;
  64
+    BeginPaint(hwnd, &ps);
  65
+    if (RectVisible(ps.hdc, &g_rcClock)) {
  66
+        // compute time to next update - we update once a second
  67
+        SYSTEMTIME st;
  68
+        GetSystemTime(&st);
  69
+        DWORD dwTimeToNextTick = 1000 - st.wMilliseconds;
  70
+        SetTimer(hwnd, 1, dwTimeToNextTick, InvalidateAndKillTimer);
  71
+    }
  72
+    PaintContent(hwnd,&ps);
  73
+    EndPaint(hwnd, &ps);
  74
+}
  75
+
  76
+void
  77
+OnPrintClient(HWND hwnd, HDC hdc)
  78
+{
  79
+    PAINTSTRUCT ps;
  80
+    ps.hdc = hdc;
  81
+    GetClientRect(hwnd, &ps.rcPaint);
  82
+    ps.fErase = FALSE;
  83
+    PaintContent(hwnd, &ps);
  84
+}
  85
+
  86
+LRESULT CALLBACK
  87
+WndProc(HWND hwnd, UINT uiMsg, WPARAM wParam, LPARAM lParam)
  88
+{
  89
+    switch (uiMsg) {
  90
+    HANDLE_MSG(hwnd, WM_CREATE, OnCreate);
  91
+    HANDLE_MSG(hwnd, WM_SIZE, OnSize);
  92
+    HANDLE_MSG(hwnd, WM_DESTROY, OnDestroy);
  93
+    HANDLE_MSG(hwnd, WM_PAINT, OnPaint);
  94
+    case WM_PRINTCLIENT: OnPrintClient(hwnd, (HDC)wParam); return 0;
  95
+    }
  96
+
  97
+    return DefWindowProc(hwnd, uiMsg, wParam, lParam);
  98
+}
  99
+
  100
+BOOL
  101
+InitApp(void)
  102
+{
  103
+    WNDCLASS wc;
  104
+
  105
+    wc.style = 0;
  106
+    wc.lpfnWndProc = WndProc;
  107
+    wc.cbClsExtra = 0;
  108
+    wc.cbWndExtra = 0;
  109
+    wc.hInstance = g_hinst;
  110
+    wc.hIcon = NULL;
  111
+    wc.hCursor = LoadCursor(NULL, IDC_ARROW);
  112
+    wc.hbrBackground = (HBRUSH)(COLOR_WINDOW + 1);
  113
+    wc.lpszMenuName = NULL;
  114
+    wc.lpszClassName = TEXT("Scratch");
  115
+
  116
+    if (!RegisterClass(&wc)) return FALSE;
  117
+
  118
+    InitCommonControls();               /* In case we use a common control */
  119
+
  120
+    return TRUE;
  121
+}
  122
+
  123
+int WINAPI WinMain(HINSTANCE hinst, HINSTANCE hinstPrev,
  124
+                   LPSTR lpCmdLine, int nShowCmd)
  125
+{
  126
+    MSG msg;
  127
+    HWND hwnd;
  128
+
  129
+    g_hinst = hinst;
  130
+
  131
+    if (!InitApp()) return 0;
  132
+
  133
+    if (SUCCEEDED(CoInitialize(NULL))) {/* In case we use COM */
  134
+
  135
+        hwnd = CreateWindow(
  136
+            TEXT("Scratch"),                /* Class Name */
  137
+            TEXT("Scratch"),                /* Title */
  138
+            WS_OVERLAPPEDWINDOW,            /* Style */
  139
+            CW_USEDEFAULT, CW_USEDEFAULT,   /* Position */
  140
+            CW_USEDEFAULT, CW_USEDEFAULT,   /* Size */
  141
+            NULL,                           /* Parent */
  142
+            NULL,                           /* No menu */
  143
+            hinst,                          /* Instance */
  144
+            0);                             /* No special parameters */
  145
+
  146
+        ShowWindow(hwnd, nShowCmd);
  147
+
  148
+        while (GetMessage(&msg, NULL, 0, 0)) {
  149
+            TranslateMessage(&msg);
  150
+            DispatchMessage(&msg);
  151
+        }
  152
+        CoUninitialize();
  153
+    }
  154
+
  155
+    return 0;
  156
+}
161  oldnewthing/092_covered.cpp
... ...
@@ -0,0 +1,161 @@
  1
+#define STRICT
  2
+#include <windows.h>
  3
+#include <windowsx.h>
  4
+#include <ole2.h>
  5
+#include <commctrl.h>
  6
+#include <shlwapi.h>
  7
+
  8
+HINSTANCE g_hinst;                          /* This application's HINSTANCE */
  9
+HWND g_hwndChild;                           /* Optional child window */
  10
+
  11
+void
  12
+OnSize(HWND hwnd, UINT state, int cx, int cy)
  13
+{
  14
+    if (g_hwndChild) {
  15
+        MoveWindow(g_hwndChild, 0, 0, cx, cy, TRUE);
  16
+    }
  17
+}
  18
+
  19
+void CALLBACK
  20
+PollTimer(HWND hwnd, UINT uMsg, UINT_PTR idTimer, DWORD dwTime)
  21
+{
  22
+    HDC hdc = GetDC(hwnd);
  23
+    if (hdc) {
  24
+        RECT rcClip, rcClient;
  25
+        LPCTSTR pszMsg;
  26
+        switch (GetClipBox(hdc, &rcClip)) {
  27
+        case NULLREGION:
  28
+            pszMsg = TEXT("completely covered");
  29
+            break;
  30
+        case SIMPLEREGION:
  31
+            GetClientRect(hwnd, &rcClient);
  32
+            if (EqualRect(&rcClient, &rcClip)) {
  33
+                pszMsg = TEXT("completely uncovered");
  34
+            } else {
  35
+                pszMsg = TEXT("partially covered");
  36
+            }
  37
+            break;
  38
+        case COMPLEXREGION:
  39
+            pszMsg = TEXT("partially covered");
  40
+            break;
  41
+        default:
  42
+            pszMsg = TEXT("Error");
  43
+            break;
  44
+        }
  45
+        // If we want to, we can also use RectVisible
  46
+        // or PtVisible - or go totally overboard by
  47
+        // using GetClipRgn
  48
+        ReleaseDC(hwnd, hdc);
  49
+
  50
+        SetWindowText(hwnd, pszMsg);
  51
+    }
  52
+}
  53
+
  54
+BOOL
  55
+OnCreate(HWND hwnd, LPCREATESTRUCT lpcs)
  56
+{
  57
+    SetTimer(hwnd, 1, 1000, PollTimer);
  58
+    return TRUE;
  59
+}
  60
+
  61
+void
  62
+OnDestroy(HWND hwnd)
  63
+{
  64
+    PostQuitMessage(0);
  65
+}
  66
+
  67
+void
  68
+PaintContent(HWND hwnd, PAINTSTRUCT *pps)
  69
+{
  70
+}
  71
+
  72
+void
  73
+OnPaint(HWND hwnd)
  74
+{
  75
+    PAINTSTRUCT ps;
  76
+    BeginPaint(hwnd, &ps);
  77
+    PaintContent(hwnd, &ps);
  78
+    EndPaint(hwnd, &ps);
  79
+}
  80
+
  81
+void
  82
+OnPrintClient(HWND hwnd, HDC hdc)
  83
+{
  84
+    PAINTSTRUCT ps;
  85
+    ps.hdc = hdc;
  86
+    GetClientRect(hwnd, &ps.rcPaint);
  87
+    ps.fErase = FALSE;
  88
+    PaintContent(hwnd, &ps);
  89
+}
  90
+
  91
+LRESULT CALLBACK
  92
+WndProc(HWND hwnd, UINT uiMsg, WPARAM wParam, LPARAM lParam)
  93
+{
  94
+    switch (uiMsg) {
  95
+    HANDLE_MSG(hwnd, WM_CREATE, OnCreate);
  96
+    HANDLE_MSG(hwnd, WM_SIZE, OnSize);
  97
+    HANDLE_MSG(hwnd, WM_DESTROY, OnDestroy);
  98
+    HANDLE_MSG(hwnd, WM_PAINT, OnPaint);
  99
+    case WM_PRINTCLIENT: OnPrintClient(hwnd, (HDC)wParam); return 0;
  100
+    }
  101
+
  102
+    return DefWindowProc(hwnd, uiMsg, wParam, lParam);
  103
+}
  104
+
  105
+BOOL
  106
+InitApp(void)
  107
+{
  108
+    WNDCLASS wc;
  109
+
  110
+    wc.style = 0;
  111
+    wc.lpfnWndProc = WndProc;
  112
+    wc.cbClsExtra = 0;
  113
+    wc.cbWndExtra = 0;
  114
+    wc.hInstance = g_hinst;
  115
+    wc.hIcon = NULL;
  116
+    wc.hCursor = LoadCursor(NULL, IDC_ARROW);
  117
+    wc.hbrBackground = (HBRUSH)(COLOR_WINDOW + 1);
  118
+    wc.lpszMenuName = NULL;
  119
+    wc.lpszClassName = TEXT("Scratch");
  120
+
  121
+    if (!RegisterClass(&wc)) return FALSE;
  122
+
  123
+    InitCommonControls();               /* In case we use a common control */
  124
+
  125
+    return TRUE;
  126
+}
  127
+
  128
+int WINAPI WinMain(HINSTANCE hinst, HINSTANCE hinstPrev,
  129
+                   LPSTR lpCmdLine, int nShowCmd)
  130
+{
  131
+    MSG msg;
  132
+    HWND hwnd;
  133
+
  134
+    g_hinst = hinst;
  135
+
  136
+    if (!InitApp()) return 0;
  137
+
  138
+    if (SUCCEEDED(CoInitialize(NULL))) {/* In case we use COM */
  139
+
  140
+        hwnd = CreateWindow(
  141
+            TEXT("Scratch"),                /* Class Name */
  142
+            TEXT("Scratch"),                /* Title */
  143
+            WS_OVERLAPPEDWINDOW,            /* Style */
  144
+            CW_USEDEFAULT, CW_USEDEFAULT,   /* Position */
  145
+            CW_USEDEFAULT, CW_USEDEFAULT,   /* Size */
  146
+            NULL,                           /* Parent */
  147
+            NULL,                           /* No menu */
  148
+            hinst,                          /* Instance */
  149
+            0);                             /* No special parameters */
  150
+
  151
+        ShowWindow(hwnd, nShowCmd);
  152
+
  153
+        while (GetMessage(&msg, NULL, 0, 0)) {
  154
+            TranslateMessage(&msg);
  155
+            DispatchMessage(&msg);
  156
+        }
  157
+        CoUninitialize();
  158
+    }
  159
+
  160
+    return 0;
  161
+}
139  oldnewthing/095_tiling.cpp
... ...
@@ -0,0 +1,139 @@
  1
+#define STRICT
  2
+#include <windows.h>
  3
+#include <windowsx.h>
  4
+#include <ole2.h>
  5
+#include <commctrl.h>
  6
+#include <shlwapi.h>
  7
+
  8
+HINSTANCE g_hinst;                          /* This application's HINSTANCE */
  9
+HWND g_hwndChild;                           /* Optional child window */
  10
+
  11
+void
  12
+OnSize(HWND hwnd, UINT state, int cx, int cy)
  13
+{
  14
+    if (g_hwndChild) {
  15
+        MoveWindow(g_hwndChild, 0, 0, cx, cy, TRUE);
  16
+    }
  17
+}
  18
+
  19
+BOOL
  20
+OnCreate(HWND hwnd, LPCREATESTRUCT lpcs)
  21
+{
  22
+    return TRUE;
  23
+}
  24
+
  25
+void
  26
+OnDestroy(HWND hwnd)
  27
+{
  28
+    PostQuitMessage(0);
  29
+}
  30
+
  31
+void
  32
+PaintContent(HWND hwnd, PAINTSTRUCT *pps)
  33
+{
  34
+}
  35
+
  36
+void
  37
+OnPaint(HWND hwnd)
  38
+{
  39
+    PAINTSTRUCT ps;
  40
+    BeginPaint(hwnd, &ps);
  41
+    PaintContent(hwnd, &ps);
  42
+    EndPaint(hwnd, &ps);
  43
+}
  44
+
  45
+void
  46
+OnPrintClient(HWND hwnd, HDC hdc)
  47
+{
  48
+    PAINTSTRUCT ps;
  49
+    ps.hdc = hdc;
  50
+    GetClientRect(hwnd, &ps.rcPaint);
  51
+    ps.fErase = FALSE;
  52
+    PaintContent(hwnd, &ps);
  53
+}
  54
+
  55
+LRESULT CALLBACK
  56
+WndProc(HWND hwnd, UINT uiMsg, WPARAM wParam, LPARAM lParam)
  57
+{
  58
+    switch (uiMsg) {
  59
+    HANDLE_MSG(hwnd, WM_CREATE, OnCreate);
  60
+    HANDLE_MSG(hwnd, WM_SIZE, OnSize);
  61
+    HANDLE_MSG(hwnd, WM_DESTROY, OnDestroy);
  62
+    HANDLE_MSG(hwnd, WM_PAINT, OnPaint);
  63
+    case WM_PRINTCLIENT: OnPrintClient(hwnd, (HDC)wParam); return 0;
  64
+    }
  65
+
  66
+    return DefWindowProc(hwnd, uiMsg, wParam, lParam);
  67
+}
  68
+
  69
+HBRUSH CreatePatternBrushFromFile(LPCTSTR pszFile)
  70
+{
  71
+    HBRUSH hbr = NULL;
  72
+    HBITMAP hbm = (HBITMAP)LoadImage(g_hinst, pszFile,
  73
+                   IMAGE_BITMAP, 0, 0, LR_LOADFROMFILE);
  74
+    if (hbm) {
  75
+        hbr = CreatePatternBrush(hbm);
  76
+        DeleteObject(hbm);
  77
+    }
  78
+    return hbr;
  79
+}
  80
+
  81
+BOOL
  82
+InitApp(LPSTR lpCmdLine)
  83
+{
  84
+    BOOL fSuccess = FALSE;
  85
+    HBRUSH hbr = CreatePatternBrushFromFile(lpCmdLine);
  86
+    if (hbr) {
  87
+        WNDCLASS wc;
  88
+    
  89
+        wc.style = 0;
  90
+        wc.lpfnWndProc = WndProc;
  91
+        wc.cbClsExtra = 0;
  92
+        wc.cbWndExtra = 0;
  93
+        wc.hInstance = g_hinst;
  94
+        wc.hIcon = NULL;
  95
+        wc.hCursor = LoadCursor(NULL, IDC_ARROW);
  96
+        wc.hbrBackground = hbr;
  97
+        wc.lpszMenuName = NULL;
  98
+        wc.lpszClassName = TEXT("Scratch");
  99
+    
  100
+        fSuccess = RegisterClass(&wc);
  101
+        // Do not delete the brush - the class owns it now
  102
+    }
  103
+    return fSuccess;
  104
+}