Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

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
Stefan Naewe authored
Showing with 6,429 additions and 0 deletions.
  1. +125 −0 oldnewthing/079_scratch.cpp
  2. +145 −0 oldnewthing/085_captionmenu.cpp
  3. +146 −0 oldnewthing/087_usepopupmenu.cpp
  4. +157 −0 oldnewthing/088_loadpopupmenu.cpp
  5. +146 −0 oldnewthing/089_paint.cpp
  6. +156 −0 oldnewthing/091_paint2.cpp
  7. +161 −0 oldnewthing/092_covered.cpp
  8. +139 −0 oldnewthing/095_tiling.cpp
  9. +150 −0 oldnewthing/097_ellipse.cpp
  10. +138 −0 oldnewthing/098_dcbrush.cpp
  11. +49 −0 oldnewthing/100_exttextout.cpp
  12. +152 −0 oldnewthing/102_stretchblt.cpp
  13. +197 −0 oldnewthing/103_textoutfl.cpp
  14. +142 −0 oldnewthing/109_uniscribe.cpp
  15. +170 −0 oldnewthing/123_nonmodalfind.cpp
  16. +174 −0 oldnewthing/125_modalfind.cpp
  17. +137 −0 oldnewthing/129_wrongowner.cpp
  18. +137 −0 oldnewthing/131_rightowner.cpp
  19. +49 −0 oldnewthing/133_cheaptimedmbox.cpp
  20. +220 −0 oldnewthing/136_timedmbox.cpp
  21. +17 −0 oldnewthing/138_timedcontextmenu.cpp
  22. +101 −0 oldnewthing/154_wldialog.cpp
  23. +117 −0 oldnewthing/159_wldialog2.cpp
  24. +172 −0 oldnewthing/207_nonmodal.cpp
  25. +211 −0 oldnewthing/209_modal.cpp
  26. +212 −0 oldnewthing/211_subtlety.cpp
  27. +219 −0 oldnewthing/212_moresubtlety.cpp
  28. +87 −0 oldnewthing/218_nestedinner.cpp
  29. +117 −0 oldnewthing/222_resizeinner.cpp
  30. +4 −0 oldnewthing/227_setdlgfocus.cpp
  31. +7 −0 oldnewthing/228_dlgdisablewindow.cpp
  32. +214 −0 oldnewthing/230_tab.cpp
  33. +174 −0 oldnewthing/245_cpl.cpp
  34. +75 −0 oldnewthing/259_cache.cpp
  35. +85 −0 oldnewthing/262_cache2.cpp
  36. +29 −0 oldnewthing/398_shared.cpp
  37. +137 −0 oldnewthing/440_flickerdraw.cpp
  38. +158 −0 oldnewthing/441_bufferdraw.cpp
  39. +160 −0 oldnewthing/442_remotedraw.cpp
  40. +143 −0 oldnewthing/443_fus.cpp
  41. +171 −0 oldnewthing/455_power.cpp
  42. +163 −0 oldnewthing/457_ipaddr.cpp
  43. +157 −0 oldnewthing/459_cleartype.cpp
  44. +20 −0 oldnewthing/462_dpi.cpp
  45. +7 −0 oldnewthing/467_dpi.xml
  46. +24 −0 oldnewthing/467_multimon.cpp
  47. +13 −0 oldnewthing/470_workarea.cpp
  48. +372 −0 oldnewthing/472_accessibility.cpp
  49. +173 −0 oldnewthing/readme.txt
View
125 oldnewthing/079_scratch.cpp
@@ -0,0 +1,125 @@
+#define STRICT
+#include <windows.h>
+#include <windowsx.h>
+#include <ole2.h>
+#include <commctrl.h>
+#include <shlwapi.h>
+
+HINSTANCE g_hinst; /* This application's HINSTANCE */
+HWND g_hwndChild; /* Optional child window */
+
+void
+OnSize(HWND hwnd, UINT state, int cx, int cy)
+{
+ if (g_hwndChild) {
+ MoveWindow(g_hwndChild, 0, 0, cx, cy, TRUE);
+ }
+}
+
+BOOL
+OnCreate(HWND hwnd, LPCREATESTRUCT lpcs)
+{
+ return TRUE;
+}
+
+void
+OnDestroy(HWND hwnd)
+{
+ PostQuitMessage(0);
+}
+
+void
+PaintContent(HWND hwnd, PAINTSTRUCT *pps)
+{
+}
+
+void
+OnPaint(HWND hwnd)
+{
+ PAINTSTRUCT ps;
+ BeginPaint(hwnd, &ps);
+ PaintContent(hwnd, &ps);
+ EndPaint(hwnd, &ps);
+}
+
+void
+OnPrintClient(HWND hwnd, HDC hdc)
+{
+ PAINTSTRUCT ps;
+ ps.hdc = hdc;
+ GetClientRect(hwnd, &ps.rcPaint);
+ ps.fErase = FALSE;
+ PaintContent(hwnd, &ps);
+}
+
+LRESULT CALLBACK
+WndProc(HWND hwnd, UINT uiMsg, WPARAM wParam, LPARAM lParam)
+{
+ switch (uiMsg) {
+ HANDLE_MSG(hwnd, WM_CREATE, OnCreate);
+ HANDLE_MSG(hwnd, WM_SIZE, OnSize);
+ HANDLE_MSG(hwnd, WM_DESTROY, OnDestroy);
+ HANDLE_MSG(hwnd, WM_PAINT, OnPaint);
+ case WM_PRINTCLIENT: OnPrintClient(hwnd, (HDC)wParam); return 0;
+ }
+
+ return DefWindowProc(hwnd, uiMsg, wParam, lParam);
+}
+
+BOOL
+InitApp(void)
+{
+ WNDCLASS wc;
+
+ wc.style = 0;
+ wc.lpfnWndProc = WndProc;
+ wc.cbClsExtra = 0;
+ wc.cbWndExtra = 0;
+ wc.hInstance = g_hinst;
+ wc.hIcon = NULL;
+ wc.hCursor = LoadCursor(NULL, IDC_ARROW);
+ wc.hbrBackground = (HBRUSH)(COLOR_WINDOW + 1);
+ wc.lpszMenuName = NULL;
+ wc.lpszClassName = TEXT("Scratch");
+
+ if (!RegisterClass(&wc)) return FALSE;
+
+ InitCommonControls(); /* In case we use a common control */
+
+ return TRUE;
+}
+
+int WINAPI WinMain(HINSTANCE hinst, HINSTANCE hinstPrev,
+ LPSTR lpCmdLine, int nShowCmd)
+{
+ MSG msg;
+ HWND hwnd;
+
+ g_hinst = hinst;
+
+ if (!InitApp()) return 0;
+
+ if (SUCCEEDED(CoInitialize(NULL))) {/* In case we use COM */
+
+ hwnd = CreateWindow(
+ TEXT("Scratch"), /* Class Name */
+ TEXT("Scratch"), /* Title */
+ WS_OVERLAPPEDWINDOW, /* Style */
+ CW_USEDEFAULT, CW_USEDEFAULT, /* Position */
+ CW_USEDEFAULT, CW_USEDEFAULT, /* Size */
+ NULL, /* Parent */
+ NULL, /* No menu */
+ hinst, /* Instance */
+ 0); /* No special parameters */
+
+ ShowWindow(hwnd, nShowCmd);
+
+ while (GetMessage(&msg, NULL, 0, 0)) {
+ TranslateMessage(&msg);
+ DispatchMessage(&msg);
+ }
+ CoUninitialize();
+ }
+
+ return 0;
+}
View
145 oldnewthing/085_captionmenu.cpp
@@ -0,0 +1,145 @@
+#define STRICT
+#include <windows.h>
+#include <windowsx.h>
+#include <ole2.h>
+#include <commctrl.h>
+#include <shlwapi.h>
+
+HINSTANCE g_hinst; /* This application's HINSTANCE */
+HWND g_hwndChild; /* Optional child window */
+
+void
+OnSize(HWND hwnd, UINT state, int cx, int cy)
+{
+ if (g_hwndChild) {
+ MoveWindow(g_hwndChild, 0, 0, cx, cy, TRUE);
+ }
+}
+
+BOOL
+OnCreate(HWND hwnd, LPCREATESTRUCT lpcs)
+{
+ return TRUE;
+}
+
+void
+OnDestroy(HWND hwnd)
+{
+ PostQuitMessage(0);
+}
+
+void
+PaintContent(HWND hwnd, PAINTSTRUCT *pps)
+{
+}
+
+void
+OnPaint(HWND hwnd)
+{
+ PAINTSTRUCT ps;
+ BeginPaint(hwnd, &ps);
+ PaintContent(hwnd, &ps);
+ EndPaint(hwnd, &ps);
+}
+
+void
+OnPrintClient(HWND hwnd, HDC hdc)
+{
+ PAINTSTRUCT ps;
+ ps.hdc = hdc;
+ GetClientRect(hwnd, &ps.rcPaint);
+ ps.fErase = FALSE;
+ PaintContent(hwnd, &ps);
+}
+
+LRESULT CALLBACK
+WndProc(HWND hwnd, UINT uiMsg, WPARAM wParam, LPARAM lParam)
+{
+ switch (uiMsg) {
+ HANDLE_MSG(hwnd, WM_CREATE, OnCreate);
+ HANDLE_MSG(hwnd, WM_SIZE, OnSize);
+ HANDLE_MSG(hwnd, WM_DESTROY, OnDestroy);
+ HANDLE_MSG(hwnd, WM_PAINT, OnPaint);
+ case WM_PRINTCLIENT: OnPrintClient(hwnd, (HDC)wParam); return 0;
+
+ case WM_CONTEXTMENU:
+ if (lParam != -1 &&
+ SendMessage(hwnd, WM_NCHITTEST,
+ 0, lParam) == HTSYSMENU) {
+ HMENU hmenu = CreatePopupMenu();
+ if (hmenu) {
+ AppendMenu(hmenu, MF_STRING, 1,
+ TEXT("Custom menu"));
+ TrackPopupMenu(hmenu, TPM_LEFTALIGN |
+ TPM_TOPALIGN |
+ TPM_RIGHTBUTTON,
+ GET_X_LPARAM(lParam),
+ GET_Y_LPARAM(lParam), 0, hwnd,
+ NULL);
+ DestroyMenu(hmenu);
+ }
+ return 0;
+ }
+ break;
+ }
+
+ return DefWindowProc(hwnd, uiMsg, wParam, lParam);
+}
+
+BOOL
+InitApp(void)
+{
+ WNDCLASS wc;
+
+ wc.style = 0;
+ wc.lpfnWndProc = WndProc;
+ wc.cbClsExtra = 0;
+ wc.cbWndExtra = 0;
+ wc.hInstance = g_hinst;
+ wc.hIcon = NULL;
+ wc.hCursor = LoadCursor(NULL, IDC_ARROW);
+ wc.hbrBackground = (HBRUSH)(COLOR_WINDOW + 1);
+ wc.lpszMenuName = NULL;
+ wc.lpszClassName = TEXT("Scratch");
+
+ if (!RegisterClass(&wc)) return FALSE;
+
+ InitCommonControls(); /* In case we use a common control */
+
+ return TRUE;
+}
+
+int WINAPI WinMain(HINSTANCE hinst, HINSTANCE hinstPrev,
+ LPSTR lpCmdLine, int nShowCmd)
+{
+ MSG msg;
+ HWND hwnd;
+
+ g_hinst = hinst;
+
+ if (!InitApp()) return 0;
+
+ if (SUCCEEDED(CoInitialize(NULL))) {/* In case we use COM */
+
+ hwnd = CreateWindow(
+ TEXT("Scratch"), /* Class Name */
+ TEXT("Scratch"), /* Title */
+ WS_OVERLAPPEDWINDOW, /* Style */
+ CW_USEDEFAULT, CW_USEDEFAULT, /* Position */
+ CW_USEDEFAULT, CW_USEDEFAULT, /* Size */
+ NULL, /* Parent */
+ NULL, /* No menu */
+ hinst, /* Instance */
+ 0); /* No special parameters */
+
+ ShowWindow(hwnd, nShowCmd);
+
+ while (GetMessage(&msg, NULL, 0, 0)) {
+ TranslateMessage(&msg);
+ DispatchMessage(&msg);
+ }
+ CoUninitialize();
+ }
+
+ return 0;
+}
View
146 oldnewthing/087_usepopupmenu.cpp
@@ -0,0 +1,146 @@
+#define STRICT
+#include <windows.h>
+#include <windowsx.h>
+#include <ole2.h>
+#include <commctrl.h>
+#include <shlwapi.h>
+
+HINSTANCE g_hinst; /* This application's HINSTANCE */
+HWND g_hwndChild; /* Optional child window */
+
+// Sample usage: UsePopupMenu(hwnd, g_hinst, MAKEINTRESOURCE(1), lParam);
+void UsePopupMenu(HWND hwnd, HINSTANCE hinst, LPCTSTR pszMenu, LPARAM lParam)
+{
+ HMENU hmenu = LoadMenu(hinst, pszMenu);
+ if (hmenu) {
+ HMENU hmenuPopup = GetSubMenu(hmenu, 0);
+ TrackPopupMenu(hmenuPopup,
+ TPM_LEFTALIGN | TPM_TOPALIGN | TPM_RIGHTBUTTON,
+ GET_X_LPARAM(lParam),
+ GET_Y_LPARAM(lParam), 0, hwnd, NULL);
+ DestroyMenu(hmenu);
+ }
+}
+
+void
+OnSize(HWND hwnd, UINT state, int cx, int cy)
+{
+ if (g_hwndChild) {
+ MoveWindow(g_hwndChild, 0, 0, cx, cy, TRUE);
+ }
+}
+
+BOOL
+OnCreate(HWND hwnd, LPCREATESTRUCT lpcs)
+{
+ return TRUE;
+}
+
+void
+OnDestroy(HWND hwnd)
+{
+ PostQuitMessage(0);
+}
+
+void
+PaintContent(HWND hwnd, PAINTSTRUCT *pps)
+{
+}
+
+void
+OnPaint(HWND hwnd)
+{
+ PAINTSTRUCT ps;
+ BeginPaint(hwnd, &ps);
+ PaintContent(hwnd, &ps);
+ EndPaint(hwnd, &ps);
+}
+
+void
+OnPrintClient(HWND hwnd, HDC hdc)
+{
+ PAINTSTRUCT ps;
+ ps.hdc = hdc;
+ GetClientRect(hwnd, &ps.rcPaint);
+ ps.fErase = FALSE;
+ PaintContent(hwnd, &ps);
+}
+
+LRESULT CALLBACK
+WndProc(HWND hwnd, UINT uiMsg, WPARAM wParam, LPARAM lParam)
+{
+ switch (uiMsg) {
+ HANDLE_MSG(hwnd, WM_CREATE, OnCreate);
+ HANDLE_MSG(hwnd, WM_SIZE, OnSize);
+ HANDLE_MSG(hwnd, WM_DESTROY, OnDestroy);
+ HANDLE_MSG(hwnd, WM_PAINT, OnPaint);
+ case WM_PRINTCLIENT: OnPrintClient(hwnd, (HDC)wParam); return 0;
+
+ case WM_CONTEXTMENU:
+ if (lParam != -1) {
+ UsePopupMenu(hwnd, g_hinst, MAKEINTRESOURCE(1), lParam);
+ return 0;
+ }
+ break;
+ }
+
+ return DefWindowProc(hwnd, uiMsg, wParam, lParam);
+}
+
+BOOL
+InitApp(void)
+{
+ WNDCLASS wc;
+
+ wc.style = 0;
+ wc.lpfnWndProc = WndProc;
+ wc.cbClsExtra = 0;
+ wc.cbWndExtra = 0;
+ wc.hInstance = g_hinst;
+ wc.hIcon = NULL;
+ wc.hCursor = LoadCursor(NULL, IDC_ARROW);
+ wc.hbrBackground = (HBRUSH)(COLOR_WINDOW + 1);
+ wc.lpszMenuName = NULL;
+ wc.lpszClassName = TEXT("Scratch");
+
+ if (!RegisterClass(&wc)) return FALSE;
+
+ InitCommonControls(); /* In case we use a common control */
+
+ return TRUE;
+}
+
+int WINAPI WinMain(HINSTANCE hinst, HINSTANCE hinstPrev,
+ LPSTR lpCmdLine, int nShowCmd)
+{
+ MSG msg;
+ HWND hwnd;
+
+ g_hinst = hinst;
+
+ if (!InitApp()) return 0;
+
+ if (SUCCEEDED(CoInitialize(NULL))) {/* In case we use COM */
+
+ hwnd = CreateWindow(
+ TEXT("Scratch"), /* Class Name */
+ TEXT("Scratch"), /* Title */
+ WS_OVERLAPPEDWINDOW, /* Style */
+ CW_USEDEFAULT, CW_USEDEFAULT, /* Position */
+ CW_USEDEFAULT, CW_USEDEFAULT, /* Size */
+ NULL, /* Parent */
+ NULL, /* No menu */
+ hinst, /* Instance */
+ 0); /* No special parameters */
+
+ ShowWindow(hwnd, nShowCmd);
+
+ while (GetMessage(&msg, NULL, 0, 0)) {
+ TranslateMessage(&msg);
+ DispatchMessage(&msg);
+ }
+ CoUninitialize();
+ }
+
+ return 0;
+}
View
157 oldnewthing/088_loadpopupmenu.cpp
@@ -0,0 +1,157 @@
+#define STRICT
+#include <windows.h>
+#include <windowsx.h>
+#include <ole2.h>
+#include <commctrl.h>
+#include <shlwapi.h>
+
+HINSTANCE g_hinst; /* This application's HINSTANCE */
+HWND g_hwndChild; /* Optional child window */
+
+HMENU LoadPopupMenu(HINSTANCE hinst, LPCTSTR pszMenu)
+{
+ HMENU hmenuPopup = NULL;
+ HMENU hmenu = LoadMenu(hinst, pszMenu);
+ if (hmenu) {
+ hmenuPopup = GetSubMenu(hmenu, 0);
+ RemoveMenu(hmenu, 0, MF_BYPOSITION);
+ DestroyMenu(hmenu);
+ }
+ return hmenuPopup;
+}
+
+// sample usage
+void Sample(HWND hwnd, LPARAM lParam)
+{
+ HMENU hmenuPopup = LoadPopupMenu(g_hinst, MAKEINTRESOURCE(1));
+ if (hmenuPopup) {
+ TrackPopupMenu(hmenuPopup,
+ TPM_LEFTALIGN | TPM_TOPALIGN | TPM_RIGHTBUTTON,
+ GET_X_LPARAM(lParam),
+ GET_Y_LPARAM(lParam), 0, hwnd, NULL);
+ DestroyMenu(hmenuPopup);
+ }
+}
+
+void
+OnSize(HWND hwnd, UINT state, int cx, int cy)
+{
+ if (g_hwndChild) {
+ MoveWindow(g_hwndChild, 0, 0, cx, cy, TRUE);
+ }
+}
+
+BOOL
+OnCreate(HWND hwnd, LPCREATESTRUCT lpcs)
+{
+ return TRUE;
+}
+
+void
+OnDestroy(HWND hwnd)
+{
+ PostQuitMessage(0);
+}
+
+void
+PaintContent(HWND hwnd, PAINTSTRUCT *pps)
+{
+}
+
+void
+OnPaint(HWND hwnd)
+{
+ PAINTSTRUCT ps;
+ BeginPaint(hwnd, &ps);
+ PaintContent(hwnd, &ps);
+ EndPaint(hwnd, &ps);
+}
+
+void
+OnPrintClient(HWND hwnd, HDC hdc)
+{
+ PAINTSTRUCT ps;
+ ps.hdc = hdc;
+ GetClientRect(hwnd, &ps.rcPaint);
+ ps.fErase = FALSE;
+ PaintContent(hwnd, &ps);
+}
+
+LRESULT CALLBACK
+WndProc(HWND hwnd, UINT uiMsg, WPARAM wParam, LPARAM lParam)
+{
+ switch (uiMsg) {
+ HANDLE_MSG(hwnd, WM_CREATE, OnCreate);
+ HANDLE_MSG(hwnd, WM_SIZE, OnSize);
+ HANDLE_MSG(hwnd, WM_DESTROY, OnDestroy);
+ HANDLE_MSG(hwnd, WM_PAINT, OnPaint);
+ case WM_PRINTCLIENT: OnPrintClient(hwnd, (HDC)wParam); return 0;
+
+ case WM_CONTEXTMENU:
+ if (lParam != -1) {
+ Sample(hwnd, lParam);
+ return 0;
+ }
+ break;
+ }
+
+ return DefWindowProc(hwnd, uiMsg, wParam, lParam);
+}
+
+BOOL
+InitApp(void)
+{
+ WNDCLASS wc;
+
+ wc.style = 0;
+ wc.lpfnWndProc = WndProc;
+ wc.cbClsExtra = 0;
+ wc.cbWndExtra = 0;
+ wc.hInstance = g_hinst;
+ wc.hIcon = NULL;
+ wc.hCursor = LoadCursor(NULL, IDC_ARROW);
+ wc.hbrBackground = (HBRUSH)(COLOR_WINDOW + 1);
+ wc.lpszMenuName = NULL;
+ wc.lpszClassName = TEXT("Scratch");
+
+ if (!RegisterClass(&wc)) return FALSE;
+
+ InitCommonControls(); /* In case we use a common control */
+
+ return TRUE;
+}
+
+int WINAPI WinMain(HINSTANCE hinst, HINSTANCE hinstPrev,
+ LPSTR lpCmdLine, int nShowCmd)
+{
+ MSG msg;
+ HWND hwnd;
+
+ g_hinst = hinst;
+
+ if (!InitApp()) return 0;
+
+ if (SUCCEEDED(CoInitialize(NULL))) {/* In case we use COM */
+
+ hwnd = CreateWindow(
+ TEXT("Scratch"), /* Class Name */
+ TEXT("Scratch"), /* Title */
+ WS_OVERLAPPEDWINDOW, /* Style */
+ CW_USEDEFAULT, CW_USEDEFAULT, /* Position */
+ CW_USEDEFAULT, CW_USEDEFAULT, /* Size */
+ NULL, /* Parent */
+ NULL, /* No menu */
+ hinst, /* Instance */
+ 0); /* No special parameters */
+
+ ShowWindow(hwnd, nShowCmd);
+
+ while (GetMessage(&msg, NULL, 0, 0)) {
+ TranslateMessage(&msg);
+ DispatchMessage(&msg);
+ }
+ CoUninitialize();
+ }
+
+ return 0;
+}
View
146 oldnewthing/089_paint.cpp
@@ -0,0 +1,146 @@
+#define STRICT
+#include <windows.h>
+#include <windowsx.h>
+#include <ole2.h>
+#include <commctrl.h>
+#include <shlwapi.h>
+
+HINSTANCE g_hinst; /* This application's HINSTANCE */
+HWND g_hwndChild; /* Optional child window */
+
+void
+OnSize(HWND hwnd, UINT state, int cx, int cy)
+{
+ if (g_hwndChild) {
+ MoveWindow(g_hwndChild, 0, 0, cx, cy, TRUE);
+ }
+}
+
+BOOL
+OnCreate(HWND hwnd, LPCREATESTRUCT lpcs)
+{
+ return TRUE;
+}
+
+void
+OnDestroy(HWND hwnd)
+{
+ PostQuitMessage(0);
+}
+
+void
+PaintContent(HWND hwnd, PAINTSTRUCT *pps)
+{
+ TCHAR szTime[100];
+ if (GetTimeFormat(LOCALE_USER_DEFAULT, 0, NULL, NULL,
+ szTime, 100)) {
+ SetWindowText(hwnd, szTime);
+ TextOut(pps->hdc, 0, 0, szTime, lstrlen(szTime));
+ }
+}
+
+void CALLBACK
+InvalidateAndKillTimer(HWND hwnd, UINT uMsg,
+ UINT_PTR idTimer, DWORD dwTime)
+{
+ KillTimer(hwnd, idTimer);
+ InvalidateRect(hwnd, NULL, TRUE);
+}
+
+void
+OnPaint(HWND hwnd)
+{
+ PAINTSTRUCT ps;
+ BeginPaint(hwnd, &ps);
+ if (!IsRectEmpty(&ps.rcPaint)) {
+ // compute time to next update - we update once a second
+ SYSTEMTIME st;
+ GetSystemTime(&st);
+ DWORD dwTimeToNextTick = 1000 - st.wMilliseconds;
+ SetTimer(hwnd, 1, dwTimeToNextTick, InvalidateAndKillTimer);
+ }
+ PaintContent(hwnd,&ps);
+ EndPaint(hwnd, &ps);
+}
+
+void
+OnPrintClient(HWND hwnd, HDC hdc)
+{
+ PAINTSTRUCT ps;
+ ps.hdc = hdc;
+ GetClientRect(hwnd, &ps.rcPaint);
+ ps.fErase = FALSE;
+ PaintContent(hwnd, &ps);
+}
+
+LRESULT CALLBACK
+WndProc(HWND hwnd, UINT uiMsg, WPARAM wParam, LPARAM lParam)
+{
+ switch (uiMsg) {
+ HANDLE_MSG(hwnd, WM_CREATE, OnCreate);
+ HANDLE_MSG(hwnd, WM_SIZE, OnSize);
+ HANDLE_MSG(hwnd, WM_DESTROY, OnDestroy);
+ HANDLE_MSG(hwnd, WM_PAINT, OnPaint);
+ case WM_PRINTCLIENT: OnPrintClient(hwnd, (HDC)wParam); return 0;
+ }
+
+ return DefWindowProc(hwnd, uiMsg, wParam, lParam);
+}
+
+BOOL
+InitApp(void)
+{
+ WNDCLASS wc;
+
+ wc.style = 0;
+ wc.lpfnWndProc = WndProc;
+ wc.cbClsExtra = 0;
+ wc.cbWndExtra = 0;
+ wc.hInstance = g_hinst;
+ wc.hIcon = NULL;
+ wc.hCursor = LoadCursor(NULL, IDC_ARROW);
+ wc.hbrBackground = (HBRUSH)(COLOR_WINDOW + 1);
+ wc.lpszMenuName = NULL;
+ wc.lpszClassName = TEXT("Scratch");
+
+ if (!RegisterClass(&wc)) return FALSE;
+
+ InitCommonControls(); /* In case we use a common control */
+
+ return TRUE;
+}
+
+int WINAPI WinMain(HINSTANCE hinst, HINSTANCE hinstPrev,
+ LPSTR lpCmdLine, int nShowCmd)
+{
+ MSG msg;
+ HWND hwnd;
+
+ g_hinst = hinst;
+
+ if (!InitApp()) return 0;
+
+ if (SUCCEEDED(CoInitialize(NULL))) {/* In case we use COM */
+
+ hwnd = CreateWindow(
+ TEXT("Scratch"), /* Class Name */
+ TEXT("Scratch"), /* Title */
+ WS_OVERLAPPEDWINDOW, /* Style */
+ CW_USEDEFAULT, CW_USEDEFAULT, /* Position */
+ CW_USEDEFAULT, CW_USEDEFAULT, /* Size */
+ NULL, /* Parent */
+ NULL, /* No menu */
+ hinst, /* Instance */
+ 0); /* No special parameters */
+
+ ShowWindow(hwnd, nShowCmd);
+
+ while (GetMessage(&msg, NULL, 0, 0)) {
+ TranslateMessage(&msg);
+ DispatchMessage(&msg);
+ }
+ CoUninitialize();
+ }
+
+ return 0;
+}
View
156 oldnewthing/091_paint2.cpp
@@ -0,0 +1,156 @@
+#define STRICT
+#include <windows.h>
+#include <windowsx.h>
+#include <ole2.h>
+#include <commctrl.h>
+#include <shlwapi.h>
+
+HINSTANCE g_hinst; /* This application's HINSTANCE */
+HWND g_hwndChild; /* Optional child window */
+
+// We'll put our clock here
+RECT g_rcClock = { 50, 50, 200, 100 };
+
+void
+OnSize(HWND hwnd, UINT state, int cx, int cy)
+{
+ if (g_hwndChild) {
+ MoveWindow(g_hwndChild, 0, 0, cx, cy, TRUE);
+ }
+}
+
+BOOL
+OnCreate(HWND hwnd, LPCREATESTRUCT lpcs)
+{
+ return TRUE;
+}
+
+void
+OnDestroy(HWND hwnd)
+{
+ PostQuitMessage(0);
+}
+
+void
+PaintContent(HWND hwnd, PAINTSTRUCT *pps)
+{
+ TCHAR szTime[100];
+ if (GetTimeFormat(LOCALE_USER_DEFAULT, 0, NULL, NULL, szTime,
+ 100)) {
+ SetWindowText(hwnd, szTime);
+ COLORREF clrTextPrev = SetTextColor(pps->hdc,
+ GetSysColor(COLOR_HIGHLIGHTTEXT));
+ COLORREF clrBkPrev = SetBkColor(pps->hdc,
+ GetSysColor(COLOR_HIGHLIGHT));
+ ExtTextOut(pps->hdc, g_rcClock.left, g_rcClock.top,
+ ETO_CLIPPED | ETO_OPAQUE, &g_rcClock,
+ szTime, lstrlen(szTime), NULL);
+ SetBkColor(pps->hdc, clrBkPrev);
+ SetTextColor(pps->hdc, clrTextPrev);
+ }
+}
+
+void CALLBACK
+InvalidateAndKillTimer(HWND hwnd, UINT uMsg,
+ UINT_PTR idTimer, DWORD dwTime) {
+ KillTimer(hwnd, idTimer);
+ InvalidateRect(hwnd, &g_rcClock, FALSE);
+}
+
+void
+OnPaint(HWND hwnd)
+{
+ PAINTSTRUCT ps;
+ BeginPaint(hwnd, &ps);
+ if (RectVisible(ps.hdc, &g_rcClock)) {
+ // compute time to next update - we update once a second
+ SYSTEMTIME st;
+ GetSystemTime(&st);
+ DWORD dwTimeToNextTick = 1000 - st.wMilliseconds;
+ SetTimer(hwnd, 1, dwTimeToNextTick, InvalidateAndKillTimer);
+ }
+ PaintContent(hwnd,&ps);
+ EndPaint(hwnd, &ps);
+}
+
+void
+OnPrintClient(HWND hwnd, HDC hdc)
+{
+ PAINTSTRUCT ps;
+ ps.hdc = hdc;
+ GetClientRect(hwnd, &ps.rcPaint);
+ ps.fErase = FALSE;
+ PaintContent(hwnd, &ps);
+}
+
+LRESULT CALLBACK
+WndProc(HWND hwnd, UINT uiMsg, WPARAM wParam, LPARAM lParam)
+{
+ switch (uiMsg) {
+ HANDLE_MSG(hwnd, WM_CREATE, OnCreate);
+ HANDLE_MSG(hwnd, WM_SIZE, OnSize);
+ HANDLE_MSG(hwnd, WM_DESTROY, OnDestroy);
+ HANDLE_MSG(hwnd, WM_PAINT, OnPaint);
+ case WM_PRINTCLIENT: OnPrintClient(hwnd, (HDC)wParam); return 0;
+ }
+
+ return DefWindowProc(hwnd, uiMsg, wParam, lParam);
+}
+
+BOOL
+InitApp(void)
+{
+ WNDCLASS wc;
+
+ wc.style = 0;
+ wc.lpfnWndProc = WndProc;
+ wc.cbClsExtra = 0;
+ wc.cbWndExtra = 0;
+ wc.hInstance = g_hinst;
+ wc.hIcon = NULL;
+ wc.hCursor = LoadCursor(NULL, IDC_ARROW);
+ wc.hbrBackground = (HBRUSH)(COLOR_WINDOW + 1);
+ wc.lpszMenuName = NULL;
+ wc.lpszClassName = TEXT("Scratch");
+
+ if (!RegisterClass(&wc)) return FALSE;
+
+ InitCommonControls(); /* In case we use a common control */
+
+ return TRUE;
+}
+
+int WINAPI WinMain(HINSTANCE hinst, HINSTANCE hinstPrev,
+ LPSTR lpCmdLine, int nShowCmd)
+{
+ MSG msg;
+ HWND hwnd;
+
+ g_hinst = hinst;
+
+ if (!InitApp()) return 0;
+
+ if (SUCCEEDED(CoInitialize(NULL))) {/* In case we use COM */
+
+ hwnd = CreateWindow(
+ TEXT("Scratch"), /* Class Name */
+ TEXT("Scratch"), /* Title */
+ WS_OVERLAPPEDWINDOW, /* Style */
+ CW_USEDEFAULT, CW_USEDEFAULT, /* Position */
+ CW_USEDEFAULT, CW_USEDEFAULT, /* Size */
+ NULL, /* Parent */
+ NULL, /* No menu */
+ hinst, /* Instance */
+ 0); /* No special parameters */
+
+ ShowWindow(hwnd, nShowCmd);
+
+ while (GetMessage(&msg, NULL, 0, 0)) {
+ TranslateMessage(&msg);
+ DispatchMessage(&msg);
+ }
+ CoUninitialize();
+ }
+
+ return 0;
+}
View
161 oldnewthing/092_covered.cpp
@@ -0,0 +1,161 @@
+#define STRICT
+#include <windows.h>
+#include <windowsx.h>
+#include <ole2.h>
+#include <commctrl.h>
+#include <shlwapi.h>
+
+HINSTANCE g_hinst; /* This application's HINSTANCE */
+HWND g_hwndChild; /* Optional child window */
+
+void
+OnSize(HWND hwnd, UINT state, int cx, int cy)
+{
+ if (g_hwndChild) {
+ MoveWindow(g_hwndChild, 0, 0, cx, cy, TRUE);
+ }
+}
+
+void CALLBACK
+PollTimer(HWND hwnd, UINT uMsg, UINT_PTR idTimer, DWORD dwTime)
+{
+ HDC hdc = GetDC(hwnd);
+ if (hdc) {
+ RECT rcClip, rcClient;
+ LPCTSTR pszMsg;
+ switch (GetClipBox(hdc, &rcClip)) {
+ case NULLREGION:
+ pszMsg = TEXT("completely covered");
+ break;
+ case SIMPLEREGION:
+ GetClientRect(hwnd, &rcClient);
+ if (EqualRect(&rcClient, &rcClip)) {
+ pszMsg = TEXT("completely uncovered");
+ } else {
+ pszMsg = TEXT("partially covered");
+ }
+ break;
+ case COMPLEXREGION:
+ pszMsg = TEXT("partially covered");
+ break;
+ default:
+ pszMsg = TEXT("Error");
+ break;
+ }
+ // If we want to, we can also use RectVisible
+ // or PtVisible - or go totally overboard by
+ // using GetClipRgn
+ ReleaseDC(hwnd, hdc);
+
+ SetWindowText(hwnd, pszMsg);
+ }
+}
+
+BOOL
+OnCreate(HWND hwnd, LPCREATESTRUCT lpcs)
+{
+ SetTimer(hwnd, 1, 1000, PollTimer);
+ return TRUE;
+}
+
+void
+OnDestroy(HWND hwnd)
+{
+ PostQuitMessage(0);
+}
+
+void
+PaintContent(HWND hwnd, PAINTSTRUCT *pps)
+{
+}
+
+void
+OnPaint(HWND hwnd)
+{
+ PAINTSTRUCT ps;
+ BeginPaint(hwnd, &ps);
+ PaintContent(hwnd, &ps);
+ EndPaint(hwnd, &ps);
+}
+
+void
+OnPrintClient(HWND hwnd, HDC hdc)
+{
+ PAINTSTRUCT ps;
+ ps.hdc = hdc;
+ GetClientRect(hwnd, &ps.rcPaint);
+ ps.fErase = FALSE;
+ PaintContent(hwnd, &ps);
+}
+
+LRESULT CALLBACK
+WndProc(HWND hwnd, UINT uiMsg, WPARAM wParam, LPARAM lParam)
+{
+ switch (uiMsg) {
+ HANDLE_MSG(hwnd, WM_CREATE, OnCreate);
+ HANDLE_MSG(hwnd, WM_SIZE, OnSize);
+ HANDLE_MSG(hwnd, WM_DESTROY, OnDestroy);
+ HANDLE_MSG(hwnd, WM_PAINT, OnPaint);
+ case WM_PRINTCLIENT: OnPrintClient(hwnd, (HDC)wParam); return 0;
+ }
+
+ return DefWindowProc(hwnd, uiMsg, wParam, lParam);
+}
+
+BOOL
+InitApp(void)
+{
+ WNDCLASS wc;
+
+ wc.style = 0;
+ wc.lpfnWndProc = WndProc;
+ wc.cbClsExtra = 0;
+ wc.cbWndExtra = 0;
+ wc.hInstance = g_hinst;
+ wc.hIcon = NULL;
+ wc.hCursor = LoadCursor(NULL, IDC_ARROW);
+ wc.hbrBackground = (HBRUSH)(COLOR_WINDOW + 1);
+ wc.lpszMenuName = NULL;
+ wc.lpszClassName = TEXT("Scratch");
+
+ if (!RegisterClass(&wc)) return FALSE;
+
+ InitCommonControls(); /* In case we use a common control */
+
+ return TRUE;
+}
+
+int WINAPI WinMain(HINSTANCE hinst, HINSTANCE hinstPrev,
+ LPSTR lpCmdLine, int nShowCmd)
+{
+ MSG msg;
+ HWND hwnd;
+
+ g_hinst = hinst;
+
+ if (!InitApp()) return 0;
+
+ if (SUCCEEDED(CoInitialize(NULL))) {/* In case we use COM */
+
+ hwnd = CreateWindow(
+ TEXT("Scratch"), /* Class Name */
+ TEXT("Scratch"), /* Title */
+ WS_OVERLAPPEDWINDOW, /* Style */
+ CW_USEDEFAULT, CW_USEDEFAULT, /* Position */
+ CW_USEDEFAULT, CW_USEDEFAULT, /* Size */
+ NULL, /* Parent */
+ NULL, /* No menu */
+ hinst, /* Instance */
+ 0); /* No special parameters */
+
+ ShowWindow(hwnd, nShowCmd);
+
+ while (GetMessage(&msg, NULL, 0, 0)) {
+ TranslateMessage(&msg);
+ DispatchMessage(&msg);
+ }
+ CoUninitialize();
+ }
+
+ return 0;
+}
View
139 oldnewthing/095_tiling.cpp
@@ -0,0 +1,139 @@
+#define STRICT
+#include <windows.h>
+#include <windowsx.h>
+#include <ole2.h>
+#include <commctrl.h>
+#include <shlwapi.h>
+
+HINSTANCE g_hinst; /* This application's HINSTANCE */
+HWND g_hwndChild; /* Optional child window */
+
+void
+OnSize(HWND hwnd, UINT state, int cx, int cy)
+{
+ if (g_hwndChild) {
+ MoveWindow(g_hwndChild, 0, 0, cx, cy, TRUE);
+ }
+}
+
+BOOL
+OnCreate(HWND hwnd, LPCREATESTRUCT lpcs)
+{
+ return TRUE;
+}
+
+void
+OnDestroy(HWND hwnd)
+{
+ PostQuitMessage(0);
+}
+
+void
+PaintContent(HWND hwnd, PAINTSTRUCT *pps)
+{
+}
+
+void
+OnPaint(HWND hwnd)
+{
+ PAINTSTRUCT ps;
+ BeginPaint(hwnd, &ps);
+ PaintContent(hwnd, &ps);
+ EndPaint(hwnd, &ps);
+}
+
+void
+OnPrintClient(HWND hwnd, HDC hdc)
+{
+ PAINTSTRUCT ps;
+ ps.hdc = hdc;
+ GetClientRect(hwnd, &ps.rcPaint);
+ ps.fErase = FALSE;
+ PaintContent(hwnd, &ps);
+}
+
+LRESULT CALLBACK
+WndProc(HWND hwnd, UINT uiMsg, WPARAM wParam, LPARAM lParam)
+{
+ switch (uiMsg) {
+ HANDLE_MSG(hwnd, WM_CREATE, OnCreate);
+ HANDLE_MSG(hwnd, WM_SIZE, OnSize);
+ HANDLE_MSG(hwnd, WM_DESTROY, OnDestroy);
+ HANDLE_MSG(hwnd, WM_PAINT, OnPaint);
+ case WM_PRINTCLIENT: OnPrintClient(hwnd, (HDC)wParam); return 0;
+ }
+
+ return DefWindowProc(hwnd, uiMsg, wParam, lParam);
+}
+
+HBRUSH CreatePatternBrushFromFile(LPCTSTR pszFile)
+{
+ HBRUSH hbr = NULL;
+ HBITMAP hbm = (HBITMAP)LoadImage(g_hinst, pszFile,
+ IMAGE_BITMAP, 0, 0, LR_LOADFROMFILE);
+ if (hbm) {
+ hbr = CreatePatternBrush(hbm);
+ DeleteObject(hbm);
+ }
+ return hbr;
+}
+
+BOOL
+InitApp(LPSTR lpCmdLine)
+{
+ BOOL fSuccess = FALSE;
+ HBRUSH hbr = CreatePatternBrushFromFile(lpCmdLine);
+ if (hbr) {
+ WNDCLASS wc;
+
+ wc.style = 0;
+ wc.lpfnWndProc = WndProc;
+ wc.cbClsExtra = 0;
+ wc.cbWndExtra = 0;
+ wc.hInstance = g_hinst;
+ wc.hIcon = NULL;
+ wc.hCursor = LoadCursor(NULL, IDC_ARROW);
+ wc.hbrBackground = hbr;
+ wc.lpszMenuName = NULL;
+ wc.lpszClassName = TEXT("Scratch");
+
+ fSuccess = RegisterClass(&wc);
+ // Do not delete the brush - the class owns it now
+ }
+ return fSuccess;
+}
+
+int WINAPI WinMain(HINSTANCE hinst, HINSTANCE hinstPrev,
+ LPSTR lpCmdLine, int nShowCmd)
+{
+ MSG msg;
+ HWND hwnd;
+
+ g_hinst = hinst;
+
+ if (!InitApp(lpCmdLine)) return 0;
+
+ if (SUCCEEDED(CoInitialize(NULL))) {/* In case we use COM */
+
+ hwnd = CreateWindow(
+ TEXT("Scratch"), /* Class Name */
+ TEXT("Scratch"), /* Title */
+ WS_OVERLAPPEDWINDOW, /* Style */
+ CW_USEDEFAULT, CW_USEDEFAULT, /* Position */
+ CW_USEDEFAULT, CW_USEDEFAULT, /* Size */
+ NULL, /* Parent */
+ NULL, /* No menu */
+ hinst, /* Instance */
+ 0); /* No special parameters */
+
+ ShowWindow(hwnd, nShowCmd);
+
+ while (GetMessage(&msg, NULL, 0, 0)) {
+ TranslateMessage(&msg);
+ DispatchMessage(&msg);
+ }
+ CoUninitialize();
+ }
+
+ return 0;
+}
View
150 oldnewthing/097_ellipse.cpp
@@ -0,0 +1,150 @@
+#define STRICT
+#include <windows.h>
+#include <windowsx.h>
+#include <ole2.h>
+#include <commctrl.h>
+#include <shlwapi.h>
+
+HINSTANCE g_hinst; /* This application's HINSTANCE */
+HWND g_hwndChild; /* Optional child window */
+
+void
+OnSize(HWND hwnd, UINT state, int cx, int cy)
+{
+ if (g_hwndChild) {
+ MoveWindow(g_hwndChild, 0, 0, cx, cy, TRUE);
+ }
+}
+
+BOOL
+OnCreate(HWND hwnd, LPCREATESTRUCT lpcs)
+{
+ return TRUE;
+}
+
+void
+OnDestroy(HWND hwnd)
+{
+ PostQuitMessage(0);
+}
+
+HBRUSH g_hbr; // the pattern brush we created
+
+HBRUSH CreatePatternBrushFromFile(LPCTSTR pszFile)
+{
+ HBRUSH hbr = NULL;
+ HBITMAP hbm = (HBITMAP)LoadImage(g_hinst, pszFile,
+ IMAGE_BITMAP, 0, 0, LR_LOADFROMFILE);
+ if (hbm) {
+ hbr = CreatePatternBrush(hbm);
+ DeleteObject(hbm);
+ }
+ return hbr;
+}
+
+void
+PaintContent(HWND hwnd, PAINTSTRUCT *pps)
+{
+ BeginPath(pps->hdc);
+ Ellipse(pps->hdc, 0, 0, 200, 100);
+ EndPath(pps->hdc);
+ HBRUSH hbrOld = SelectBrush(pps->hdc, g_hbr);
+ FillPath(pps->hdc);
+ SelectBrush(pps->hdc, hbrOld);
+}
+
+void
+OnPaint(HWND hwnd)
+{
+ PAINTSTRUCT ps;
+ BeginPaint(hwnd, &ps);
+ PaintContent(hwnd, &ps);
+ EndPaint(hwnd, &ps);
+}
+
+void
+OnPrintClient(HWND hwnd, HDC hdc)
+{
+ PAINTSTRUCT ps;
+ ps.hdc = hdc;
+ GetClientRect(hwnd, &ps.rcPaint);
+ ps.fErase = FALSE;
+ PaintContent(hwnd, &ps);
+}
+
+LRESULT CALLBACK
+WndProc(HWND hwnd, UINT uiMsg, WPARAM wParam, LPARAM lParam)
+{
+ switch (uiMsg) {
+ HANDLE_MSG(hwnd, WM_CREATE, OnCreate);
+ HANDLE_MSG(hwnd, WM_SIZE, OnSize);
+ HANDLE_MSG(hwnd, WM_DESTROY, OnDestroy);
+ HANDLE_MSG(hwnd, WM_PAINT, OnPaint);
+ case WM_PRINTCLIENT: OnPrintClient(hwnd, (HDC)wParam); return 0;
+ }
+
+ return DefWindowProc(hwnd, uiMsg, wParam, lParam);
+}
+
+BOOL
+InitApp(void)
+{
+ WNDCLASS wc;
+
+ wc.style = 0;
+ wc.lpfnWndProc = WndProc;
+ wc.cbClsExtra = 0;
+ wc.cbWndExtra = 0;
+ wc.hInstance = g_hinst;
+ wc.hIcon = NULL;
+ wc.hCursor = LoadCursor(NULL, IDC_ARROW);
+ wc.hbrBackground = (HBRUSH)(COLOR_WINDOW + 1);
+ wc.lpszMenuName = NULL;
+ wc.lpszClassName = TEXT("Scratch");
+
+ if (!RegisterClass(&wc)) return FALSE;
+
+ InitCommonControls(); /* In case we use a common control */
+
+ return TRUE;
+}
+
+int WINAPI WinMain(HINSTANCE hinst, HINSTANCE hinstPrev,
+ LPSTR lpCmdLine, int nShowCmd)
+{
+ MSG msg;
+ HWND hwnd;
+
+ g_hinst = hinst;
+
+ if (!InitApp()) return 0;
+
+ if (SUCCEEDED(CoInitialize(NULL))) {/* In case we use COM */
+
+ g_hbr = CreatePatternBrushFromFile(lpCmdLine);
+ if (!g_hbr) return 0;
+
+ hwnd = CreateWindow(
+ TEXT("Scratch"), /* Class Name */
+ TEXT("Scratch"), /* Title */
+ WS_OVERLAPPEDWINDOW, /* Style */
+ CW_USEDEFAULT, CW_USEDEFAULT, /* Position */
+ CW_USEDEFAULT, CW_USEDEFAULT, /* Size */
+ NULL, /* Parent */
+ NULL, /* No menu */
+ hinst, /* Instance */
+ 0); /* No special parameters */
+
+ ShowWindow(hwnd, nShowCmd);
+
+ while (GetMessage(&msg, NULL, 0, 0)) {
+ TranslateMessage(&msg);
+ DispatchMessage(&msg);
+ }
+ CoUninitialize();
+
+ DeleteObject(g_hbr);
+ }
+
+ return 0;
+}
View
138 oldnewthing/098_dcbrush.cpp
@@ -0,0 +1,138 @@
+#define STRICT
+#include <windows.h>
+#include <windowsx.h>
+#include <ole2.h>
+#include <commctrl.h>
+#include <shlwapi.h>
+
+HINSTANCE g_hinst; /* This application's HINSTANCE */
+HWND g_hwndChild; /* Optional child window */
+
+void
+OnSize(HWND hwnd, UINT state, int cx, int cy)
+{
+ if (g_hwndChild) {
+ MoveWindow(g_hwndChild, 0, 0, cx, cy, TRUE);
+ }
+}
+
+BOOL
+OnCreate(HWND hwnd, LPCREATESTRUCT lpcs)
+{
+ g_hwndChild = CreateWindow(TEXT("static"), NULL,
+ WS_VISIBLE | WS_CHILD, 0, 0, 0, 0,
+ hwnd, NULL, g_hinst, 0);
+ if (!g_hwndChild) return FALSE;
+ return TRUE;
+}
+
+
+void
+OnDestroy(HWND hwnd)
+{
+ PostQuitMessage(0);
+}
+
+void
+PaintContent(HWND hwnd, PAINTSTRUCT *pps)
+{
+}
+
+void
+OnPaint(HWND hwnd)
+{
+ PAINTSTRUCT ps;
+ BeginPaint(hwnd, &ps);
+ PaintContent(hwnd, &ps);
+ EndPaint(hwnd, &ps);
+}
+
+void
+OnPrintClient(HWND hwnd, HDC hdc)
+{
+ PAINTSTRUCT ps;
+ ps.hdc = hdc;
+ GetClientRect(hwnd, &ps.rcPaint);
+ ps.fErase = FALSE;
+ PaintContent(hwnd, &ps);
+}
+
+HBRUSH OnCtlColor(HWND hwnd, HDC hdc, HWND hwndChild, int type)
+{
+ FORWARD_WM_CTLCOLORSTATIC(hwnd, hdc, hwndChild, DefWindowProc);
+ SetDCBrushColor(hdc, RGB(255,0,0));
+ return GetStockBrush(DC_BRUSH);
+}
+
+LRESULT CALLBACK
+WndProc(HWND hwnd, UINT uiMsg, WPARAM wParam, LPARAM lParam)
+{
+ switch (uiMsg) {
+ HANDLE_MSG(hwnd, WM_CREATE, OnCreate);
+ HANDLE_MSG(hwnd, WM_SIZE, OnSize);
+ HANDLE_MSG(hwnd, WM_DESTROY, OnDestroy);
+ HANDLE_MSG(hwnd, WM_PAINT, OnPaint);
+ case WM_PRINTCLIENT: OnPrintClient(hwnd, (HDC)wParam); return 0;
+ HANDLE_MSG(hwnd, WM_CTLCOLORSTATIC, OnCtlColor);
+ }
+
+ return DefWindowProc(hwnd, uiMsg, wParam, lParam);
+}
+
+BOOL
+InitApp(void)
+{
+ WNDCLASS wc;
+
+ wc.style = 0;
+ wc.lpfnWndProc = WndProc;
+ wc.cbClsExtra = 0;
+ wc.cbWndExtra = 0;
+ wc.hInstance = g_hinst;
+ wc.hIcon = NULL;
+ wc.hCursor = LoadCursor(NULL, IDC_ARROW);
+ wc.hbrBackground = (HBRUSH)(COLOR_WINDOW + 1);
+ wc.lpszMenuName = NULL;
+ wc.lpszClassName = TEXT("Scratch");
+
+ if (!RegisterClass(&wc)) return FALSE;
+
+ InitCommonControls(); /* In case we use a common control */
+
+ return TRUE;
+}
+
+int WINAPI WinMain(HINSTANCE hinst, HINSTANCE hinstPrev,
+ LPSTR lpCmdLine, int nShowCmd)
+{
+ MSG msg;
+ HWND hwnd;
+
+ g_hinst = hinst;
+
+ if (!InitApp()) return 0;
+
+ if (SUCCEEDED(CoInitialize(NULL))) {/* In case we use COM */
+
+ hwnd = CreateWindow(
+ TEXT("Scratch"), /* Class Name */
+ TEXT("Scratch"), /* Title */
+ WS_OVERLAPPEDWINDOW, /* Style */
+ CW_USEDEFAULT, CW_USEDEFAULT, /* Position */
+ CW_USEDEFAULT, CW_USEDEFAULT, /* Size */
+ NULL, /* Parent */
+ NULL, /* No menu */
+ hinst, /* Instance */
+ 0); /* No special parameters */
+
+ ShowWindow(hwnd, nShowCmd);
+
+ while (GetMessage(&msg, NULL, 0, 0)) {
+ TranslateMessage(&msg);
+ DispatchMessage(&msg);
+ }
+ CoUninitialize();
+ }
+
+ return 0;
+}
View
49 oldnewthing/100_exttextout.cpp
@@ -0,0 +1,49 @@
+BOOL DrawSolidRect1(HDC hdc, LPCRECT prc, COLORREF clr)
+{
+ BOOL fDrawn = FALSE;
+ HPEN hpenPrev = SelectPen(hdc, GetStockPen(NULL_PEN));
+ HBRUSH hbrSolid = CreateSolidBrush(clr);
+ if (hbrSolid) {
+ HBRUSH hbrPrev = SelectBrush(hdc, hbrSolid);
+ fDrawn = Rectangle(hdc, prc->left, prc->top,
+ prc->right + 1, prc->bottom + 1);
+ SelectBrush(hdc, hbrPrev);
+ DeleteObject(hbrSolid);
+ }
+ SelectPen(hdc, hpenPrev);
+ return fDrawn;
+}
+
+BOOL DrawSolidRect2(HDC hdc, LPCRECT prc, COLORREF clr)
+{
+ BOOL fDrawn = FALSE;
+ HBRUSH hbrSolid = CreateSolidBrush(clr);
+ if (hbrSolid) {
+ fDrawn = FillRect(hdc, prc, hbrSolid);
+ DeleteObject(hbrSolid);
+ }
+ return fDrawn;
+}
+
+BOOL DrawSolidRect3(HDC hdc, LPCRECT prc, COLORREF clr)
+{
+ BOOL fDrawn = FALSE;
+ COLORREF clrPrev = SetDCBrushColor(hdc, clr);
+ if (clrPrev != CLR_INVALID) {
+ fDrawn = FillRect(hdc, prc, GetStockBrush(DC_BRUSH));
+ SetDCBrushColor(hdc, clrPrev);
+ }
+ return fDrawn;
+}
+
+BOOL DrawSolidRect4(HDC hdc, LPCRECT prc, COLORREF clr)
+{
+ BOOL fDrawn = FALSE;
+ COLORREF clrPrev = SetBkColor(hdc, clr);
+ if (clrPrev != CLR_INVALID) {
+ fDrawn = ExtTextOut(hdc, 0, 0, ETO_OPAQUE, prc, NULL, 0, NULL);
+ SetBkColor(hdc, clrPrev);
+ }
+ return fDrawn;
+}
+
View
152 oldnewthing/102_stretchblt.cpp
@@ -0,0 +1,152 @@
+#define STRICT
+#include <windows.h>
+#include <windowsx.h>
+#include <ole2.h>
+#include <commctrl.h>
+#include <shlwapi.h>
+
+HINSTANCE g_hinst; /* This application's HINSTANCE */
+HWND g_hwndChild; /* Optional child window */
+
+void
+OnSize(HWND hwnd, UINT state, int cx, int cy)
+{
+ if (g_hwndChild) {
+ MoveWindow(g_hwndChild, 0, 0, cx, cy, TRUE);
+ }
+}
+
+BOOL
+OnCreate(HWND hwnd, LPCREATESTRUCT lpcs)
+{
+ return TRUE;
+}
+
+void
+OnDestroy(HWND hwnd)
+{
+ PostQuitMessage(0);
+}
+
+HBITMAP g_hbm;
+
+void
+PaintContent(HWND hwnd, PAINTSTRUCT *pps)
+{
+ HDC hdcMem = CreateCompatibleDC(pps->hdc);
+ if (hdcMem) {
+ HBITMAP hbmPrev = SelectBitmap(hdcMem, g_hbm);
+ if (hbmPrev) {
+ BITMAP bm;
+ if (GetObject(g_hbm, sizeof(bm), &bm)) {
+ RECT rc;
+ GetClientRect(hwnd, &rc);
+ int cxClient = rc.right - rc.left;
+ int cyClient = rc.bottom - rc.top;
+ StretchBlt(pps->hdc, rc.left, rc.top, cxClient, cyClient,
+ hdcMem, 0, 0, 1, 1, SRCCOPY);
+ BitBlt(pps->hdc, rc.left, rc.top, cxClient, cyClient,
+ hdcMem, 0, 0, SRCCOPY);
+ }
+ SelectBitmap(hdcMem, hbmPrev);
+ }
+ DeleteDC(hdcMem);
+ }
+}
+
+void
+OnPaint(HWND hwnd)
+{
+ PAINTSTRUCT ps;
+ BeginPaint(hwnd, &ps);
+ PaintContent(hwnd, &ps);
+ EndPaint(hwnd, &ps);
+}
+
+void
+OnPrintClient(HWND hwnd, HDC hdc)
+{
+ PAINTSTRUCT ps;
+ ps.hdc = hdc;
+ GetClientRect(hwnd, &ps.rcPaint);
+ ps.fErase = FALSE;
+ PaintContent(hwnd, &ps);
+}
+
+LRESULT CALLBACK
+WndProc(HWND hwnd, UINT uiMsg, WPARAM wParam, LPARAM lParam)
+{
+ switch (uiMsg) {
+ HANDLE_MSG(hwnd, WM_CREATE, OnCreate);
+ HANDLE_MSG(hwnd, WM_SIZE, OnSize);
+ HANDLE_MSG(hwnd, WM_DESTROY, OnDestroy);
+ HANDLE_MSG(hwnd, WM_PAINT, OnPaint);
+ case WM_PRINTCLIENT: OnPrintClient(hwnd, (HDC)wParam); return 0;
+ }
+
+ return DefWindowProc(hwnd, uiMsg, wParam, lParam);
+}
+
+BOOL
+InitApp(void)
+{
+ WNDCLASS wc;
+
+ wc.style = 0;
+ wc.lpfnWndProc = WndProc;
+ wc.cbClsExtra = 0;
+ wc.cbWndExtra = 0;
+ wc.hInstance = g_hinst;
+ wc.hIcon = NULL;
+ wc.hCursor = LoadCursor(NULL, IDC_ARROW);
+ wc.hbrBackground = (HBRUSH)(COLOR_WINDOW + 1);
+ wc.lpszMenuName = NULL;
+ wc.lpszClassName = TEXT("Scratch");
+
+ if (!RegisterClass(&wc)) return FALSE;
+
+ InitCommonControls(); /* In case we use a common control */
+
+ return TRUE;
+}
+
+int WINAPI WinMain(HINSTANCE hinst, HINSTANCE hinstPrev,
+ LPSTR lpCmdLine, int nShowCmd)
+{
+ MSG msg;
+ HWND hwnd;
+
+ g_hinst = hinst;
+
+ if (!InitApp()) return 0;
+
+ if (SUCCEEDED(CoInitialize(NULL))) {/* In case we use COM */
+
+ g_hbm = (HBITMAP)LoadImage(g_hinst, lpCmdLine,
+ IMAGE_BITMAP, 0, 0, LR_LOADFROMFILE);
+ if (!g_hbm) return 0;
+
+ hwnd = CreateWindow(
+ TEXT("Scratch"), /* Class Name */
+ TEXT("Scratch"), /* Title */
+ WS_OVERLAPPEDWINDOW, /* Style */
+ CW_USEDEFAULT, CW_USEDEFAULT, /* Position */
+ CW_USEDEFAULT, CW_USEDEFAULT, /* Size */
+ NULL, /* Parent */
+ NULL, /* No menu */
+ hinst, /* Instance */
+ 0); /* No special parameters */
+
+ ShowWindow(hwnd, nShowCmd);
+
+ while (GetMessage(&msg, NULL, 0, 0)) {
+ TranslateMessage(&msg);
+ DispatchMessage(&msg);
+ }
+ CoUninitialize();
+
+ DeleteObject(g_hbm);
+ }
+
+ return 0;
+}
View
197 oldnewthing/103_textoutfl.cpp
@@ -0,0 +1,197 @@
+#define STRICT
+#include <windows.h>
+#include <windowsx.h>
+#include <ole2.h>
+#include <commctrl.h>
+#include <shlwapi.h>
+#include <mlang.h>
+
+HINSTANCE g_hinst; /* This application's HINSTANCE */
+HWND g_hwndChild; /* Optional child window */
+
+void
+OnSize(HWND hwnd, UINT state, int cx, int cy)
+{
+ if (g_hwndChild) {
+ MoveWindow(g_hwndChild, 0, 0, cx, cy, TRUE);
+ }
+}
+
+BOOL
+OnCreate(HWND hwnd, LPCREATESTRUCT lpcs)
+{
+ return TRUE;
+}
+
+void
+OnDestroy(HWND hwnd)
+{
+ PostQuitMessage(0);
+}
+
+HRESULT TextOutFL(HDC hdc, int x, int y, LPCWSTR psz, int cch)
+{
+ HRESULT hr;
+ IMLangFontLink2 *pfl;
+ if (SUCCEEDED(hr = CoCreateInstance(CLSID_CMultiLanguage,
+ NULL, CLSCTX_ALL, IID_IMLangFontLink2,
+ (void**)&pfl))) {
+ HFONT hfOrig = (HFONT)GetCurrentObject(hdc, OBJ_FONT);
+ POINT ptOrig;
+ DWORD dwAlignOrig = GetTextAlign(hdc);
+ if (!(dwAlignOrig & TA_UPDATECP)) {
+ SetTextAlign(hdc, dwAlignOrig | TA_UPDATECP);
+ }
+ MoveToEx(hdc, x, y, &ptOrig);
+ DWORD dwFontCodePages = 0;
+ hr = pfl->GetFontCodePages(hdc, hfOrig, &dwFontCodePages);
+ if (SUCCEEDED(hr)) {
+ while (cch > 0) {
+ DWORD dwActualCodePages;
+ long cchActual;
+ hr = pfl->GetStrCodePages(psz, cch, dwFontCodePages,
+ &dwActualCodePages, &cchActual);
+ if (FAILED(hr)) {
+ break;
+ }
+
+ if (dwActualCodePages & dwFontCodePages) {
+ TextOutW(hdc, 0, 0, psz, cchActual);
+ } else {
+ HFONT hfLinked;
+ if (FAILED(hr = pfl->MapFont(hdc, dwActualCodePages, 0,
+ &hfLinked))) {
+ break;
+ }
+ SelectFont(hdc, hfLinked);
+ TextOutW(hdc, 0, 0, psz, cchActual);
+ SelectFont(hdc, hfOrig);
+ pfl->ReleaseFont(hfLinked);
+ }
+ psz += cchActual;
+ cch -= cchActual;
+ }
+ if (FAILED(hr)) {
+ // We started outputting characters so we must finish.
+ // Do the rest without font linking since we have
+ // no choice.
+ TextOutW(hdc, 0, 0, psz, cch);
+ hr = S_FALSE;
+ }
+ }
+
+ pfl->Release();
+
+ if (!(dwAlignOrig & TA_UPDATECP)) {
+ SetTextAlign(hdc, dwAlignOrig);
+ MoveToEx(hdc, ptOrig.x, ptOrig.y, NULL);
+ }
+ }
+
+ return hr;
+}
+
+void TextOutTryFL(HDC hdc, int x, int y, LPCWSTR psz, int cch)
+{
+ if (FAILED(TextOutFL(hdc, x, y, psz, cch))) {
+ TextOutW(hdc, x, y, psz, cch);
+ }
+}
+
+void
+PaintContent(HWND hwnd, PAINTSTRUCT *pps)
+{
+ TextOutTryFL(pps->hdc, 0, 0,
+ L"ABC\x0410\x0411\x0412\x0E01\x0E02\x0E03", 9);
+}
+
+void
+OnPaint(HWND hwnd)
+{
+ PAINTSTRUCT ps;
+ BeginPaint(hwnd, &ps);
+ PaintContent(hwnd, &ps);
+ EndPaint(hwnd, &ps);
+}
+
+void
+OnPrintClient(HWND hwnd, HDC hdc)
+{
+ PAINTSTRUCT ps;
+ ps.hdc = hdc;
+ GetClientRect(hwnd, &ps.rcPaint);
+ ps.fErase = FALSE;
+ PaintContent(hwnd, &ps);
+}
+
+LRESULT CALLBACK
+WndProc(HWND hwnd, UINT uiMsg, WPARAM wParam, LPARAM lParam)
+{
+ switch (uiMsg) {
+ HANDLE_MSG(hwnd, WM_CREATE, OnCreate);
+ HANDLE_MSG(hwnd, WM_SIZE, OnSize);
+ HANDLE_MSG(hwnd, WM_DESTROY, OnDestroy);
+ HANDLE_MSG(hwnd, WM_PAINT, OnPaint);
+ case WM_PRINTCLIENT: OnPrintClient(hwnd, (HDC)wParam); return 0;
+ }
+
+ return DefWindowProc(hwnd, uiMsg, wParam, lParam);
+}
+
+BOOL
+InitApp(void)
+{
+ WNDCLASS wc;
+
+ wc.style = 0;
+ wc.lpfnWndProc = WndProc;
+ wc.cbClsExtra = 0;
+ wc.cbWndExtra = 0;
+ wc.hInstance = g_hinst;
+ wc.hIcon = NULL;
+ wc.hCursor = LoadCursor(NULL, IDC_ARROW);
+ wc.hbrBackground = (HBRUSH)(COLOR_WINDOW + 1);
+ wc.lpszMenuName = NULL;
+ wc.lpszClassName = TEXT("Scratch");
+
+ if (!RegisterClass(&wc)) return FALSE;
+
+ InitCommonControls(); /* In case we use a common control */
+
+ return TRUE;
+}
+
+int WINAPI WinMain(HINSTANCE hinst, HINSTANCE hinstPrev,
+ LPSTR lpCmdLine, int nShowCmd)
+{
+ MSG msg;
+ HWND hwnd;
+
+ g_hinst = hinst;
+
+ if (!InitApp()) return 0;
+
+ if (SUCCEEDED(CoInitialize(NULL))) {/* In case we use COM */
+
+ hwnd = CreateWindow(
+ TEXT("Scratch"), /* Class Name */
+ TEXT("Scratch"), /* Title */
+ WS_OVERLAPPEDWINDOW, /* Style */
+ CW_USEDEFAULT, CW_USEDEFAULT, /* Position */
+ CW_USEDEFAULT, CW_USEDEFAULT, /* Size */
+ NULL, /* Parent */
+ NULL, /* No menu */
+ hinst, /* Instance */
+ 0); /* No special parameters */
+
+ ShowWindow(hwnd, nShowCmd);
+
+ while (GetMessage(&msg, NULL, 0, 0)) {
+ TranslateMessage(&msg);
+ DispatchMessage(&msg);
+ }
+ CoUninitialize();
+ }
+
+ return 0;
+}
View
142 oldnewthing/109_uniscribe.cpp
@@ -0,0 +1,142 @@
+#define STRICT
+#include <windows.h>
+#include <windowsx.h>
+#include <ole2.h>
+#include <commctrl.h>
+#include <shlwapi.h>
+#include <usp10.h>
+
+HINSTANCE g_hinst; /* This application's HINSTANCE */
+HWND g_hwndChild; /* Optional child window */
+
+void
+OnSize(HWND hwnd, UINT state, int cx, int cy)
+{
+ if (g_hwndChild) {
+ MoveWindow(g_hwndChild, 0, 0, cx, cy, TRUE);
+ }
+}
+
+BOOL
+OnCreate(HWND hwnd, LPCREATESTRUCT lpcs)
+{
+ return TRUE;
+}
+
+void
+OnDestroy(HWND hwnd)
+{
+ PostQuitMessage(0);
+}
+
+HRESULT TextOutUniscribe(HDC hdc, int x, int y, LPCWSTR psz, int cch)
+{
+ if (cch == 0) return S_OK;
+ SCRIPT_STRING_ANALYSIS ssa;
+ HRESULT hr = ScriptStringAnalyse(hdc, psz, cch, 0, -1,
+ SSA_FALLBACK | SSA_GLYPHS, MAXLONG,
+ NULL, NULL, NULL, NULL, NULL, &ssa);
+ if (SUCCEEDED(hr)) {
+ hr = ScriptStringOut(ssa, x, y, 0, NULL, 0, 0, FALSE);
+ ScriptStringFree(&ssa);
+ }
+ return hr;
+}
+
+void
+PaintContent(HWND hwnd, PAINTSTRUCT *pps)
+{
+ TextOutUniscribe(pps->hdc, 0, 0,
+ L"ABC\x0410\x0411\x0412\x0E01\x0E02\x0E03", 9);
+}
+
+void
+OnPaint(HWND hwnd)
+{
+ PAINTSTRUCT ps;
+ BeginPaint(hwnd, &ps);
+ PaintContent(hwnd, &ps);
+ EndPaint(hwnd, &ps);
+}
+
+void
+OnPrintClient(HWND hwnd, HDC hdc)
+{
+ PAINTSTRUCT ps;
+ ps.hdc = hdc;
+ GetClientRect(hwnd, &ps.rcPaint);
+ ps.fErase = FALSE;
+ PaintContent(hwnd, &ps);
+}
+
+LRESULT CALLBACK
+WndProc(HWND hwnd, UINT uiMsg, WPARAM wParam, LPARAM lParam)
+{
+ switch (uiMsg) {
+ HANDLE_MSG(hwnd, WM_CREATE, OnCreate);
+ HANDLE_MSG(hwnd, WM_SIZE, OnSize);
+ HANDLE_MSG(hwnd, WM_DESTROY, OnDestroy);
+ HANDLE_MSG(hwnd, WM_PAINT, OnPaint);
+ case WM_PRINTCLIENT: OnPrintClient(hwnd, (HDC)wParam); return 0;
+ }
+
+ return DefWindowProc(hwnd, uiMsg, wParam, lParam);
+}
+
+BOOL
+InitApp(void)
+{
+ WNDCLASS wc;
+
+ wc.style = 0;
+ wc.lpfnWndProc = WndProc;
+ wc.cbClsExtra = 0;
+ wc.cbWndExtra = 0;
+ wc.hInstance = g_hinst;
+ wc.hIcon = NULL;
+ wc.hCursor = LoadCursor(NULL, IDC_ARROW);
+ wc.hbrBackground = (HBRUSH)(COLOR_WINDOW + 1);
+ wc.lpszMenuName = NULL;
+ wc.lpszClassName = TEXT("Scratch");
+
+ if (!RegisterClass(&wc)) return FALSE;
+
+ InitCommonControls(); /* In case we use a common control */
+
+ return TRUE;
+}
+
+int WINAPI WinMain(HINSTANCE hinst, HINSTANCE hinstPrev,
+ LPSTR lpCmdLine, int nShowCmd)
+{
+ MSG msg;
+ HWND hwnd;
+
+ g_hinst = hinst;
+
+ if (!InitApp()) return 0;
+
+ if (SUCCEEDED(CoInitialize(NULL))) {/* In case we use COM */
+
+ hwnd = CreateWindow(
+ TEXT("Scratch"), /* Class Name */
+ TEXT("Scratch"), /* Title */
+ WS_OVERLAPPEDWINDOW, /* Style */
+ CW_USEDEFAULT, CW_USEDEFAULT, /* Position */
+ CW_USEDEFAULT, CW_USEDEFAULT, /* Size */
+ NULL, /* Parent */
+ NULL, /* No menu */
+ hinst, /* Instance */
+ 0); /* No special parameters */
+
+ ShowWindow(hwnd, nShowCmd);
+
+ while (GetMessage(&msg, NULL, 0, 0)) {
+ TranslateMessage(&msg);
+ DispatchMessage(&msg);
+ }
+ CoUninitialize();
+ }
+
+ return 0;
+}
View
170 oldnewthing/123_nonmodalfind.cpp
@@ -0,0 +1,170 @@
+#define STRICT
+#include <windows.h>
+#include <windowsx.h>
+#include <ole2.h>
+#include <commctrl.h>
+#include <shlwapi.h>
+#include <commdlg.h>
+
+HWND g_hwndFR;
+TCHAR g_szFind[80];
+FINDREPLACE g_fr = { sizeof(g_fr) };
+UINT g_uMsgFindMsgString;
+HINSTANCE g_hinst; /* This application's HINSTANCE */
+HWND g_hwndChild; /* Optional child window */
+
+void
+OnSize(HWND hwnd, UINT state, int cx, int cy)
+{
+ if (g_hwndChild) {
+ MoveWindow(g_hwndChild, 0, 0, cx, cy, TRUE);
+ }
+}
+
+BOOL
+OnCreate(HWND hwnd, LPCREATESTRUCT lpcs)
+{
+ return TRUE;
+}
+
+void
+OnDestroy(HWND hwnd)
+{
+ PostQuitMessage(0);
+}
+
+void
+PaintContent(HWND hwnd, PAINTSTRUCT *pps)
+{
+}
+
+void
+OnPaint(HWND hwnd)
+{
+ PAINTSTRUCT ps;
+ BeginPaint(hwnd, &ps);
+ PaintContent(hwnd, &ps);
+ EndPaint(hwnd, &ps);
+}
+
+void
+OnPrintClient(HWND hwnd, HDC hdc)
+{
+ PAINTSTRUCT ps;
+ ps.hdc = hdc;
+ GetClientRect(hwnd, &ps.rcPaint);
+ ps.fErase = FALSE;
+ PaintContent(hwnd, &ps);
+}
+
+void CreateFindDialogUIModally(HWND hwnd)
+{
+ if (!g_hwndFR) {
+ g_uMsgFindMsgString = RegisterWindowMessage(FINDMSGSTRING);
+ if (g_uMsgFindMsgString) {
+ g_fr.hwndOwner = hwnd;
+ g_fr.hInstance = g_hinst;
+ g_fr.lpstrFindWhat = g_szFind;
+ g_fr.wFindWhatLen = 80;
+ g_hwndFR = FindText(&g_fr);
+ }
+ }
+}
+
+void OnChar(HWND hwnd, TCHAR ch, int cRepeat)
+{
+ switch (ch) {
+ case ' ': CreateFindDialogUIModally(hwnd); break;
+ }
+}
+
+void OnFindReplace(HWND hwnd, FINDREPLACE *pfr)
+{
+ if (pfr->Flags & FR_DIALOGTERM) {
+ DestroyWindow(g_hwndFR);
+ g_hwndFR = NULL;
+ }
+}
+
+LRESULT CALLBACK
+WndProc(HWND hwnd, UINT uiMsg, WPARAM wParam, LPARAM lParam)
+{
+ switch (uiMsg) {
+ HANDLE_MSG(hwnd, WM_CREATE, OnCreate);
+ HANDLE_MSG(hwnd, WM_SIZE, OnSize);
+ HANDLE_MSG(hwnd, WM_DESTROY, OnDestroy);
+ HANDLE_MSG(hwnd, WM_PAINT, OnPaint);
+ case WM_PRINTCLIENT: OnPrintClient(hwnd, (HDC)wParam); return 0;
+ HANDLE_MSG(hwnd, WM_CHAR, OnChar);
+
+ default:
+ if (uiMsg == g_uMsgFindMsgString && g_uMsgFindMsgString) {
+ OnFindReplace(hwnd, (FINDREPLACE*)lParam);
+ }
+ break;
+ }
+
+ return DefWindowProc(hwnd, uiMsg, wParam, lParam);
+}
+
+BOOL
+InitApp(void)
+{
+ WNDCLASS wc;
+
+ wc.style = 0;
+ wc.lpfnWndProc = WndProc;
+ wc.cbClsExtra = 0;
+ wc.cbWndExtra = 0;
+ wc.hInstance = g_hinst;
+ wc.hIcon = NULL;
+ wc.hCursor = LoadCursor(NULL, IDC_ARROW);
+ wc.hbrBackground = (HBRUSH)(COLOR_WINDOW + 1);
+ wc.lpszMenuName = NULL;
+ wc.lpszClassName = TEXT("Scratch");
+
+ if (!RegisterClass(&wc)) return FALSE;
+
+ InitCommonControls(); /* In case we use a common control */
+
+ return TRUE;
+}
+
+int WINAPI WinMain(HINSTANCE hinst, HINSTANCE hinstPrev,
+ LPSTR lpCmdLine, int nShowCmd)
+{
+ MSG msg;
+ HWND hwnd;
+
+ g_hinst = hinst;
+
+ if (!InitApp()) return 0;
+
+ if (SUCCEEDED(CoInitialize(NULL))) {/* In case we use COM */
+
+ hwnd = CreateWindow(
+ TEXT("Scratch"), /* Class Name */
+ TEXT("Scratch"), /* Title */
+ WS_OVERLAPPEDWINDOW, /* Style */
+ CW_USEDEFAULT, CW_USEDEFAULT, /* Position */
+ CW_USEDEFAULT, CW_USEDEFAULT, /* Size */
+ NULL, /* Parent */
+ NULL, /* No menu */
+ hinst, /* Instance */
+ 0); /* No special parameters */
+
+ ShowWindow(hwnd, nShowCmd);
+
+ while (GetMessage(&msg, NULL, 0, 0)) {
+ if (g_hwndFR && IsDialogMessage(g_hwndFR, &msg)) {
+ } else {
+ TranslateMessage(&msg);
+ DispatchMessage(&msg);
+ }
+ }
+ CoUninitialize();
+ }
+
+ return 0;
+}
+
View
174 oldnewthing/125_modalfind.cpp
@@ -0,0 +1,174 @@
+#define STRICT
+#include <windows.h>
+#include <windowsx.h>
+#include <ole2.h>
+#include <commctrl.h>
+#include <shlwapi.h>
+#include <commdlg.h>
+
+HWND g_hwndFR;
+TCHAR g_szFind[80];
+FINDREPLACE g_fr = { sizeof(g_fr) };
+UINT g_uMsgFindMsgString;
+HINSTANCE g_hinst; /* This application's HINSTANCE */
+HWND g_hwndChild; /* Optional child window */
+
+void
+OnSize(HWND hwnd, UINT state, int cx, int cy)
+{
+ if (g_hwndChild) {
+ MoveWindow(g_hwndChild, 0, 0, cx, cy, TRUE);
+ }
+}
+
+BOOL
+OnCreate(HWND hwnd, LPCREATESTRUCT lpcs)
+{
+ return TRUE;
+}
+
+void
+OnDestroy(HWND hwnd)
+{
+ PostQuitMessage(0);
+}
+
+void
+PaintContent(HWND hwnd, PAINTSTRUCT *pps)
+{
+}
+
+void
+OnPaint(HWND hwnd)
+{
+ PAINTSTRUCT ps;
+ BeginPaint(hwnd, &ps);
+ PaintContent(hwnd, &ps);
+ EndPaint(hwnd, &ps);
+}
+
+void
+OnPrintClient(HWND hwnd, HDC hdc)
+{
+ PAINTSTRUCT ps;
+ ps.hdc = hdc;
+ GetClientRect(hwnd, &ps.rcPaint);
+ ps.fErase = FALSE;
+ PaintContent(hwnd, &ps);
+}
+
+void CreateFindDialogUIModally(HWND hwnd)
+{
+ if (!g_hwndFR) {
+ g_uMsgFindMsgString = RegisterWindowMessage(FINDMSGSTRING);
+ if (g_uMsgFindMsgString) {
+ g_fr.hwndOwner = hwnd;
+ g_fr.hInstance = g_hinst;
+ g_fr.lpstrFindWhat = g_szFind;
+ g_fr.wFindWhatLen = 80;
+ g_hwndFR = FindText(&g_fr);
+ if (g_hwndFR) {
+ EnableWindow(hwnd, FALSE);
+ }
+ }
+ }
+}
+
+void OnChar(HWND hwnd, TCHAR ch, int cRepeat)
+{
+ switch (ch) {
+ case ' ': CreateFindDialogUIModally(hwnd); break;
+ }
+}
+
+void OnFindReplace(HWND hwnd, FINDREPLACE *pfr)
+{
+ if (pfr->Flags & FR_DIALOGTERM) {
+ EnableWindow(hwnd, TRUE);
+ DestroyWindow(g_hwndFR);
+ g_hwndFR = NULL;
+ }
+}
+
+LRESULT CALLBACK
+WndProc(HWND hwnd, UINT uiMsg, WPARAM wParam, LPARAM lParam)
+{
+ switch (uiMsg) {
+ HANDLE_MSG(hwnd, WM_CREATE, OnCreate);
+ HANDLE_MSG(hwnd, WM_SIZE, OnSize);
+ HANDLE_MSG(hwnd, WM_DESTROY, OnDestroy);
+ HANDLE_MSG(hwnd, WM_PAINT, OnPaint);
+ case WM_PRINTCLIENT: OnPrintClient(hwnd, (HDC)wParam); return 0;
+ HANDLE_MSG(hwnd, WM_CHAR, OnChar);
+
+ default:
+ if (uiMsg == g_uMsgFindMsgString && g_uMsgFindMsgString) {
+ OnFindReplace(hwnd, (FINDREPLACE*)lParam);
+ }
+ break;
+ }
+
+ return DefWindowProc(hwnd, uiMsg, wParam, lParam);
+}
+
+BOOL
+InitApp(void)
+{
+ WNDCLASS wc;
+
+ wc.style = 0;
+ wc.lpfnWndProc = WndProc;
+ wc.cbClsExtra = 0;
+ wc.cbWndExtra = 0;
+ wc.hInstance = g_hinst;
+ wc.hIcon = NULL;
+ wc.hCursor = LoadCursor(NULL, IDC_ARROW);
+ wc.hbrBackground = (HBRUSH)(COLOR_WINDOW + 1);
+ wc.lpszMenuName = NULL;
+ wc.lpszClassName = TEXT("Scratch");
+
+ if (!RegisterClass(&wc)) return FALSE;
+
+ InitCommonControls(); /* In case we use a common control */
+
+ return TRUE;
+}
+
+int WINAPI WinMain(HINSTANCE hinst, HINSTANCE hinstPrev,
+ LPSTR lpCmdLine, int nShowCmd)
+{
+ MSG msg;
+ HWND hwnd;
+
+ g_hinst = hinst;
+
+ if (!InitApp()) return 0;
+
+ if (SUCCEEDED(CoInitialize(NULL))) {/* In case we use COM */
+
+ hwnd = CreateWindow(
+ TEXT("Scratch"), /* Class Name */
+ TEXT("Scratch"), /* Title */
+ WS_OVERLAPPEDWINDOW, /* Style */
+ CW_USEDEFAULT, CW_USEDEFAULT, /* Position */
+ CW_USEDEFAULT, CW_USEDEFAULT, /* Size */
+ NULL, /* Parent */
+ NULL, /* No menu */
+ hinst, /* Instance */
+ 0); /* No special parameters */
+
+ ShowWindow(hwnd, nShowCmd);
+
+ while (GetMessage(&msg, NULL, 0, 0)) {
+ if (g_hwndFR && IsDialogMessage(g_hwndFR, &msg)) {
+ } else {
+ TranslateMessage(&msg);
+ DispatchMessage(&msg);
+ }
+ }
+ CoUninitialize();
+ }
+
+ return 0;
+}
+
View
137 oldnewthing/129_wrongowner.cpp
@@ -0,0 +1,137 @@
+#define STRICT
+#include <windows.h>
+#include <windowsx.h>
+#include <ole2.h>
+#include <commctrl.h>
+#include <shlwapi.h>
+
+HINSTANCE g_hinst; /* This application's HINSTANCE */
+HWND g_hwndChild; /* Optional child window */
+
+void
+OnSize(HWND hwnd, UINT state, int cx, int cy)
+{
+ if (g_hwndChild) {
+ MoveWindow(g_hwndChild, 0, 0, cx, cy, TRUE);
+ }
+}
+
+BOOL
+OnCreate(HWND hwnd, LPCREATESTRUCT lpcs)
+{
+ return TRUE;
+}
+
+void
+OnDestroy(HWND hwnd)
+{
+ PostQuitMessage(0);
+}
+
+void
+PaintContent(HWND hwnd, PAINTSTRUCT *pps)
+{
+}
+
+void
+OnPaint(HWND hwnd)
+{
+ PAINTSTRUCT ps;
+ BeginPaint(hwnd, &ps);
+ PaintContent(hwnd, &ps);
+ EndPaint(hwnd, &ps);
+}
+
+void
+OnPrintClient(HWND hwnd, HDC hdc)
+{
+ PAINTSTRUCT ps;
+ ps.hdc = hdc;
+ GetClientRect(hwnd, &ps.rcPaint);
+ ps.fErase = FALSE;
+ PaintContent(hwnd, &ps);
+}
+
+void OnChar(HWND hwnd, TCHAR ch, int cRepeat)
+{
+ switch (ch) {
+ case ' ':
+ // Wrong!
+ MessageBox(NULL, TEXT("Message"), TEXT("Title"), MB_OK);
+ if (!IsWindow(hwnd)) MessageBeep(-1);
+ break;
+ }
+}
+
+LRESULT CALLBACK
+WndProc(HWND hwnd, UINT uiMsg, WPARAM wParam, LPARAM lParam)
+{
+ switch (uiMsg) {
+ HANDLE_MSG(hwnd, WM_CREATE, OnCreate);
+ HANDLE_MSG(hwnd, WM_SIZE, OnSize);
+ HANDLE_MSG(hwnd, WM_DESTROY, OnDestroy);
+ HANDLE_MSG(hwnd, WM_PAINT, OnPaint);
+ case WM_PRINTCLIENT: OnPrintClient(hwnd, (HDC)wParam); return 0;
+ HANDLE_MSG(hwnd, WM_CHAR, OnChar);
+ }
+
+ return DefWindowProc(hwnd, uiMsg, wParam, lParam);
+}
+
+BOOL
+InitApp(void)
+{
+ WNDCLASS wc;
+
+ wc.style = 0;
+ wc.lpfnWndProc = WndProc;
+ wc.cbClsExtra = 0;
+ wc.cbWndExtra = 0;
+ wc.hInstance = g_hinst;
+ wc.hIcon = NULL;
+ wc.hCursor = LoadCursor(NULL, IDC_ARROW);
+ wc.hbrBackground = (HBRUSH)(COLOR_WINDOW + 1);
+ wc.lpszMenuName = NULL;
+ wc.lpszClassName = TEXT("Scratch");
+
+ if (!RegisterClass(&wc)) return FALSE;
+
+ InitCommonControls(); /* In case we use a common control */
+
+ return TRUE;
+}
+
+int WINAPI WinMain(HINSTANCE hinst, HINSTANCE hinstPrev,
+ LPSTR lpCmdLine, int nShowCmd)
+{
+ MSG msg;
+ HWND hwnd;
+
+ g_hinst = hinst;
+
+ if (!InitApp()) return 0;
+
+ if (SUCCEEDED(CoInitialize(NULL))) {/* In case we use COM */
+
+ hwnd = CreateWindow(
+ TEXT("Scratch"), /* Class Name */
+ TEXT("Scratch"), /* Title */
+ WS_OVERLAPPEDWINDOW, /* Style */
+ CW_USEDEFAULT, CW_USEDEFAULT, /* Position */
+ CW_USEDEFAULT, CW_USEDEFAULT, /* Size */
+ NULL, /* Parent */
+ NULL, /* No menu */
+ hinst, /* Instance */
+ 0); /* No special parameters */
+
+ ShowWindow(hwnd, nShowCmd);
+
+ while (GetMessage(&msg, NULL, 0, 0)) {
+ TranslateMessage(&msg);
+ DispatchMessage(&msg);
+ }
+ CoUninitialize();
+ }
+
+ return 0;
+}
View
137 oldnewthing/131_rightowner.cpp
@@ -0,0 +1,137 @@
+#define STRICT
+#include <windows.h>
+#include <windowsx.h>
+#include <ole2.h>
+#include <commctrl.h>
+#include <shlwapi.h>
+
+HINSTANCE g_hinst; /* This application's HINSTANCE */