Source code of Windows XP (NT5)
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

878 lines
34 KiB

  1. /******************************************************************************\
  2. * This is a part of the Microsoft Source Code Samples.
  3. * Copyright (C) 1993 Microsoft Corporation.
  4. * All rights reserved.
  5. * This source code is only intended as a supplement to
  6. * Microsoft Development Tools and/or WinHelp documentation.
  7. * See these sources for detailed information regarding the
  8. * Microsoft samples programs.
  9. \******************************************************************************/
  10. /****************************************************************************
  11. PROGRAM: Generic.c
  12. PURPOSE: Generic template for Windows applications
  13. FUNCTIONS:
  14. WinMain() - calls initialization function, processes message loop
  15. InitApplication() - initializes window data and registers window
  16. InitInstance() - saves instance handle and creates main window
  17. WndProc() - processes messages
  18. CenterWindow() - used to center the "About" box over application window
  19. About() - processes messages for "About" dialog box
  20. COMMENTS:
  21. The Windows SDK Generic Application Example is a sample application
  22. that you can use to get an idea of how to perform some of the simple
  23. functionality that all Applications written for Microsoft Windows
  24. should implement. You can use this application as either a starting
  25. point from which to build your own applications, or for quickly
  26. testing out functionality of an interesting Windows API.
  27. This application is source compatible for with Windows 3.1 and
  28. Windows NT.
  29. ****************************************************************************/
  30. #include <windows.h> // required for all Windows applications
  31. #include "UxTheme.h"
  32. #include "tmschema.h"
  33. #include "resource.h" // specific to this program
  34. #define countof(x) (sizeof(x) / sizeof(x[0]))
  35. HINSTANCE hInst; // current instance
  36. HWND ghWnd;
  37. HTHEME ghTheme;
  38. HTHEME ghThemeTB;
  39. /****************************************************************************/
  40. BOOL InitApplication(HINSTANCE);
  41. BOOL InitInstance(HINSTANCE, int);
  42. LRESULT CALLBACK WndProc(HWND, UINT, WPARAM, LPARAM);
  43. LRESULT CALLBACK About(HWND, UINT, WPARAM, LPARAM);
  44. /****************************************************************************/
  45. DWORD GetLastErrorBox(HWND hWnd, LPTSTR lpTitle)
  46. {
  47. LPVOID lpv;
  48. DWORD dwRv;
  49. if (GetLastError() == 0) return 0;
  50. dwRv = FormatMessage(FORMAT_MESSAGE_ALLOCATE_BUFFER |
  51. FORMAT_MESSAGE_FROM_SYSTEM,
  52. NULL,
  53. GetLastError(),
  54. MAKELANGID(LANG_ENGLISH, SUBLANG_ENGLISH_US),
  55. (LPVOID)&lpv,
  56. 0,
  57. NULL);
  58. MessageBox(hWnd, lpv, lpTitle, MB_OK);
  59. if(dwRv)
  60. LocalFree(lpv);
  61. return dwRv;
  62. }
  63. /****************************************************************************
  64. FUNCTION: WinMain(HINSTANCE, HINSTANCE, LPTSTR, int)
  65. PURPOSE: calls initialization function, processes message loop
  66. COMMENTS:
  67. Windows recognizes this function by name as the initial entry point
  68. for the program. This function calls the application initialization
  69. routine, if no other instance of the program is running, and always
  70. calls the instance initialization routine. It then executes a message
  71. retrieval and dispatch loop that is the top-level control structure
  72. for the remainder of execution. The loop is terminated when a WM_QUIT
  73. message is received, at which time this function exits the application
  74. instance by returning the value passed by PostQuitMessage().
  75. If this function must abort before entering the message loop, it
  76. returns the conventional value NULL.
  77. ****************************************************************************/
  78. int APIENTRY WinMain(
  79. HINSTANCE hInstance,
  80. HINSTANCE hPrevInstance,
  81. LPSTR lpCmdLine,
  82. int nCmdShow)
  83. {
  84. MSG msg;
  85. HANDLE hAccelTable;
  86. if (!hPrevInstance) // Other instances of app running?
  87. if (!InitApplication(hInstance)) // Initialize shared things
  88. return (FALSE); // Exits if unable to initialize
  89. /* Perform initializations that apply to a specific instance */
  90. if (!InitInstance(hInstance, nCmdShow))
  91. return (FALSE);
  92. hAccelTable = LoadAccelerators (hInstance, L"DEACCEL");
  93. /* Acquire and dispatch messages until a WM_QUIT message is received. */
  94. while (GetMessage(&msg, // message structure
  95. NULL, // handle of window receiving the message
  96. 0, // lowest message to examine
  97. 0)) // highest message to examine
  98. {
  99. if (!TranslateAccelerator (msg.hwnd, hAccelTable, &msg)) {
  100. TranslateMessage(&msg);// Translates virtual key codes
  101. DispatchMessage(&msg); // Dispatches message to window
  102. }
  103. }
  104. DestroyAcceleratorTable(hAccelTable);
  105. if (ghTheme)
  106. CloseThemeData(ghTheme);
  107. if (ghThemeTB)
  108. CloseThemeData(ghThemeTB);
  109. return (msg.wParam); // Returns the value from PostQuitMessage
  110. lpCmdLine; // This will prevent 'unused formal parameter' warnings
  111. }
  112. /****************************************************************************
  113. FUNCTION: InitApplication(HINSTANCE)
  114. PURPOSE: Initializes window data and registers window class
  115. COMMENTS:
  116. This function is called at initialization time only if no other
  117. instances of the application are running. This function performs
  118. initialization tasks that can be done once for any number of running
  119. instances.
  120. In this case, we initialize a window class by filling out a data
  121. structure of type WNDCLASS and calling the Windows RegisterClass()
  122. function. Since all instances of this application use the same window
  123. class, we only need to do this when the first instance is initialized.
  124. ****************************************************************************/
  125. BOOL InitApplication(HINSTANCE hInstance)
  126. {
  127. WNDCLASS wc;
  128. // Fill in window class structure with parameters that describe the
  129. // main window.
  130. wc.style = CS_HREDRAW | CS_VREDRAW;// Class style(s).
  131. wc.lpfnWndProc = (WNDPROC)WndProc; // Window Procedure
  132. wc.cbClsExtra = 0; // No per-class extra data.
  133. wc.cbWndExtra = 0; // No per-window extra data.
  134. wc.hInstance = hInstance; // Owner of this class
  135. wc.hIcon = LoadIcon (hInstance, L"DEICON"); // Icon name from .RC
  136. wc.hCursor = LoadCursor(NULL, IDC_ARROW);// Cursor
  137. wc.hbrBackground = GetStockObject(WHITE_BRUSH); // Default color
  138. wc.lpszMenuName = L"DEMENU"; // Menu name from .RC
  139. wc.lpszClassName = L"DrawEdgeClass"; // Name to register as
  140. // Register the window class and return success/failure code.
  141. return (RegisterClass(&wc));
  142. }
  143. /****************************************************************************
  144. FUNCTION: InitInstance(HINSTANCE, int)
  145. PURPOSE: Saves instance handle and creates main window
  146. COMMENTS:
  147. This function is called at initialization time for every instance of
  148. this application. This function performs initialization tasks that
  149. cannot be shared by multiple instances.
  150. In this case, we save the instance handle in a static variable and
  151. create and display the main program window.
  152. ****************************************************************************/
  153. BOOL InitInstance(
  154. HINSTANCE hInstance,
  155. int nCmdShow)
  156. {
  157. // Save the instance handle in static variable, which will be used in
  158. // many subsequence calls from this application to Windows.
  159. hInst = hInstance; // Store instance handle in our global variable
  160. // Create a main window for this application instance.
  161. ghWnd = CreateWindow(
  162. L"DrawEdgeClass", // See RegisterClass() call.
  163. L"DrawEdge() Demo", // Text for window title bar.
  164. WS_OVERLAPPEDWINDOW, // Window style.
  165. CW_USEDEFAULT, 0, CW_USEDEFAULT, 0, // Use default positioning
  166. NULL, // Overlapped windows have no parent.
  167. NULL, // Use the window class menu.
  168. hInstance, // This instance owns this window.
  169. NULL // We don't use any data in our WM_CREATE
  170. );
  171. // If window could not be created, return "failure"
  172. if (!ghWnd)
  173. return (FALSE);
  174. ghTheme = OpenThemeData(NULL, L"Button");
  175. ghThemeTB = OpenThemeData(NULL, L"Rebar");
  176. // Make the window visible; update its client area; and return "success"
  177. ShowWindow(ghWnd, nCmdShow); // Show the window
  178. UpdateWindow(ghWnd); // Sends WM_PAINT message
  179. return (TRUE); // We succeeded...
  180. }
  181. void UpdateMenu(HMENU hMenu, UINT iEdge, UINT iBorder)
  182. {
  183. // Set checks set for menu items
  184. CheckMenuItem (hMenu, IDM_BDR_RAISEDINNER, (iEdge & BDR_RAISEDINNER) == BDR_RAISEDINNER ? MF_CHECKED : MF_UNCHECKED);
  185. CheckMenuItem (hMenu, IDM_BDR_SUNKENINNER, (iEdge & BDR_SUNKENINNER) == BDR_SUNKENINNER ? MF_CHECKED : MF_UNCHECKED);
  186. CheckMenuItem (hMenu, IDM_BDR_RAISEDOUTER, (iEdge & BDR_RAISEDOUTER) == BDR_RAISEDOUTER ? MF_CHECKED : MF_UNCHECKED);
  187. CheckMenuItem (hMenu, IDM_BDR_SUNKENOUTER, (iEdge & BDR_SUNKENOUTER) == BDR_SUNKENOUTER ? MF_CHECKED : MF_UNCHECKED);
  188. CheckMenuItem (hMenu, IDM_EDGE_EDGE_BUMP, (iEdge & EDGE_BUMP) == EDGE_BUMP ? MF_CHECKED : MF_UNCHECKED);
  189. CheckMenuItem (hMenu, IDM_EDGE_EDGE_ETCHED, (iEdge & EDGE_ETCHED) == EDGE_ETCHED ? MF_CHECKED : MF_UNCHECKED);
  190. CheckMenuItem (hMenu, IDM_EDGE_EDGE_RAISED, (iEdge & EDGE_RAISED) == EDGE_RAISED ? MF_CHECKED : MF_UNCHECKED);
  191. CheckMenuItem (hMenu, IDM_EDGE_EDGE_SUNKEN, (iEdge & EDGE_SUNKEN) == EDGE_SUNKEN ? MF_CHECKED : MF_UNCHECKED);
  192. CheckMenuItem (hMenu, IDM_BORDER_BF_ADJUST, (iBorder & BF_ADJUST) == BF_ADJUST ? MF_CHECKED : MF_UNCHECKED);
  193. CheckMenuItem (hMenu, IDM_BORDER_BF_BOTTOM, (iBorder & BF_BOTTOM) == BF_BOTTOM ? MF_CHECKED : MF_UNCHECKED);
  194. CheckMenuItem (hMenu, IDM_BORDER_BF_DIAGONAL, (iBorder & BF_DIAGONAL) == BF_DIAGONAL ? MF_CHECKED : MF_UNCHECKED);
  195. CheckMenuItem (hMenu, IDM_BORDER_BF_FLAT, (iBorder & BF_FLAT) == BF_FLAT ? MF_CHECKED : MF_UNCHECKED);
  196. CheckMenuItem (hMenu, IDM_BORDER_BF_LEFT, (iBorder & BF_LEFT) == BF_LEFT ? MF_CHECKED : MF_UNCHECKED);
  197. CheckMenuItem (hMenu, IDM_BORDER_BF_MIDDLE, (iBorder & BF_MIDDLE) == BF_MIDDLE ? MF_CHECKED : MF_UNCHECKED);
  198. CheckMenuItem (hMenu, IDM_BORDER_BF_MONO, (iBorder & BF_MONO) == BF_MONO ? MF_CHECKED : MF_UNCHECKED);
  199. CheckMenuItem (hMenu, IDM_BORDER_BF_RIGHT, (iBorder & BF_RIGHT) == BF_RIGHT ? MF_CHECKED : MF_UNCHECKED);
  200. CheckMenuItem (hMenu, IDM_BORDER_BF_SOFT, (iBorder & BF_SOFT) == BF_SOFT ? MF_CHECKED : MF_UNCHECKED);
  201. CheckMenuItem (hMenu, IDM_BORDER_BF_TOP, (iBorder & BF_TOP) == BF_TOP ? MF_CHECKED : MF_UNCHECKED);
  202. CheckMenuItem (hMenu, IDM_BORDER_BF_RECT, (iBorder & BF_RECT) == BF_RECT ? MF_CHECKED : MF_UNCHECKED);
  203. CheckMenuItem (hMenu, IDM_BORDER_BF_BOTTOMLEFT, (iBorder & BF_BOTTOMLEFT) == BF_BOTTOMLEFT ? MF_CHECKED : MF_UNCHECKED);
  204. CheckMenuItem (hMenu, IDM_BORDER_BF_BOTTOMRIGHT, (iBorder & BF_BOTTOMRIGHT) == BF_BOTTOMRIGHT ? MF_CHECKED : MF_UNCHECKED);
  205. CheckMenuItem (hMenu, IDM_BORDER_BF_TOPLEFT, (iBorder & BF_TOPLEFT) == BF_TOPLEFT ? MF_CHECKED : MF_UNCHECKED);
  206. CheckMenuItem (hMenu, IDM_BORDER_BF_TOPRIGHT, (iBorder & BF_TOPRIGHT) == BF_TOPRIGHT ? MF_CHECKED : MF_UNCHECKED);
  207. CheckMenuItem (hMenu, IDM_BORDER_BF_DIAGONAL_ENDBOTTOMLEFT, (iBorder & BF_DIAGONAL_ENDBOTTOMLEFT) == BF_DIAGONAL_ENDBOTTOMLEFT ? MF_CHECKED : MF_UNCHECKED);
  208. CheckMenuItem (hMenu, IDM_BORDER_BF_DIAGONAL_ENDBOTTOMRIGHT, (iBorder & BF_DIAGONAL_ENDBOTTOMRIGHT) == BF_DIAGONAL_ENDBOTTOMRIGHT ? MF_CHECKED : MF_UNCHECKED);
  209. CheckMenuItem (hMenu, IDM_BORDER_BF_DIAGONAL_ENDTOPLEFT, (iBorder & BF_DIAGONAL_ENDTOPLEFT) == BF_DIAGONAL_ENDTOPLEFT ? MF_CHECKED : MF_UNCHECKED);
  210. CheckMenuItem (hMenu, IDM_BORDER_BF_DIAGONAL_ENDTOPRIGHT, (iBorder & BF_DIAGONAL_ENDTOPRIGHT) == BF_DIAGONAL_ENDTOPRIGHT ? MF_CHECKED : MF_UNCHECKED);
  211. DrawMenuBar(ghWnd);
  212. }
  213. void FillRectClr(HDC hdc, LPRECT prc, COLORREF clr)
  214. {
  215. COLORREF clrSave = SetBkColor(hdc, clr);
  216. ExtTextOut(hdc,0,0,ETO_OPAQUE,prc,NULL,0,NULL);
  217. SetBkColor(hdc, clrSave);
  218. }
  219. BOOL CCDrawEdge(HDC hdc, LPRECT lprc, UINT edge, UINT flags)
  220. {
  221. RECT rc, rcD;
  222. UINT bdrType;
  223. COLORREF clrTL, clrBR;
  224. int cxBorder = GetSystemMetrics(SM_CXBORDER);
  225. int cyBorder = GetSystemMetrics(SM_CYBORDER);
  226. //
  227. // Enforce monochromicity and flatness
  228. //
  229. // if (oemInfo.BitCount == 1)
  230. // flags |= BF_MONO;
  231. if (flags & BF_MONO)
  232. flags |= BF_FLAT;
  233. CopyRect(&rc, lprc);
  234. //
  235. // Draw the border segment(s), and calculate the remaining space as we
  236. // go.
  237. //
  238. if (bdrType = (edge & BDR_OUTER))
  239. {
  240. DrawBorder:
  241. //
  242. // Get colors. Note the symmetry between raised outer, sunken inner and
  243. // sunken outer, raised inner.
  244. //
  245. if (flags & BF_FLAT)
  246. {
  247. if (flags & BF_MONO)
  248. clrBR = (bdrType & BDR_OUTER) ? GetSysColor(COLOR_WINDOWFRAME) : GetSysColor(COLOR_WINDOW);
  249. else
  250. clrBR = (bdrType & BDR_OUTER) ? GetSysColor(COLOR_BTNSHADOW): GetSysColor(COLOR_BTNFACE);
  251. clrTL = clrBR;
  252. }
  253. else
  254. {
  255. // 5 == HILIGHT
  256. // 4 == LIGHT
  257. // 3 == FACE
  258. // 2 == SHADOW
  259. // 1 == DKSHADOW
  260. switch (bdrType)
  261. {
  262. // +2 above surface
  263. case BDR_RAISEDOUTER: // 5 : 4
  264. clrTL = ((flags & BF_SOFT) ? GetSysColor(COLOR_BTNHIGHLIGHT) : GetSysColor(COLOR_3DLIGHT));
  265. clrBR = GetSysColor(COLOR_3DDKSHADOW); // 1
  266. break;
  267. // +0 above surface
  268. case BDR_RAISEDINNER: // 4 : 5
  269. clrTL = ((flags & BF_SOFT) ? GetSysColor(COLOR_3DLIGHT) : GetSysColor(COLOR_BTNHIGHLIGHT));
  270. clrBR = GetSysColor(COLOR_BTNSHADOW); // 2
  271. break;
  272. // -1 below surface
  273. case BDR_SUNKENOUTER: // 1 : 2
  274. clrTL = ((flags & BF_SOFT) ? GetSysColor(COLOR_3DDKSHADOW) : GetSysColor(COLOR_BTNSHADOW));
  275. clrBR = GetSysColor(COLOR_BTNHIGHLIGHT); // 5
  276. break;
  277. // -2 below surface
  278. case BDR_SUNKENINNER: // 2 : 1
  279. clrTL = ((flags & BF_SOFT) ? GetSysColor(COLOR_BTNSHADOW) : GetSysColor(COLOR_3DDKSHADOW));
  280. clrBR = GetSysColor(COLOR_3DLIGHT); // 4
  281. break;
  282. default:
  283. return(FALSE);
  284. }
  285. }
  286. //
  287. // Draw the sides of the border. NOTE THAT THE ALGORITHM FAVORS THE
  288. // BOTTOM AND RIGHT SIDES, since the light source is assumed to be top
  289. // left. If we ever decide to let the user set the light source to a
  290. // particular corner, then change this algorithm.
  291. //
  292. // Bottom Right edges
  293. if (flags & (BF_RIGHT | BF_BOTTOM))
  294. {
  295. // Right
  296. if (flags & BF_RIGHT)
  297. {
  298. rc.right -= cxBorder;
  299. // PatBlt(hdc, rc.right, rc.top, cxBorder, rc.bottom - rc.top, PATCOPY);
  300. rcD.left = rc.right;
  301. rcD.right = rc.right + cxBorder;
  302. rcD.top = rc.top;
  303. rcD.bottom = rc.bottom;
  304. FillRectClr(hdc, &rcD, clrBR);
  305. }
  306. // Bottom
  307. if (flags & BF_BOTTOM)
  308. {
  309. rc.bottom -= cyBorder;
  310. // PatBlt(hdc, rc.left, rc.bottom, rc.right - rc.left, cyBorder, PATCOPY);
  311. rcD.left = rc.left;
  312. rcD.right = rc.right;
  313. rcD.top = rc.bottom;
  314. rcD.bottom = rc.bottom + cyBorder;
  315. FillRectClr(hdc, &rcD, clrBR);
  316. }
  317. }
  318. // Top Left edges
  319. if (flags & (BF_TOP | BF_LEFT))
  320. {
  321. // Left
  322. if (flags & BF_LEFT)
  323. {
  324. // PatBlt(hdc, rc.left, rc.top, cxBorder, rc.bottom - rc.top, PATCOPY);
  325. rc.left += cxBorder;
  326. rcD.left = rc.left - cxBorder;
  327. rcD.right = rc.left;
  328. rcD.top = rc.top;
  329. rcD.bottom = rc.bottom;
  330. FillRectClr(hdc, &rcD, clrTL);
  331. }
  332. // Top
  333. if (flags & BF_TOP)
  334. {
  335. // PatBlt(hdc, rc.left, rc.top, rc.right - rc.left, cyBorder, PATCOPY);
  336. rc.top += cyBorder;
  337. rcD.left = rc.left;
  338. rcD.right = rc.right;
  339. rcD.top = rc.top - cyBorder;
  340. rcD.bottom = rc.top;
  341. FillRectClr(hdc, &rcD, clrTL);
  342. }
  343. }
  344. }
  345. if (bdrType = (edge & BDR_INNER))
  346. {
  347. //
  348. // Strip this so the next time through, bdrType will be 0.
  349. // Otherwise, we'll loop forever.
  350. //
  351. edge &= ~BDR_INNER;
  352. goto DrawBorder;
  353. }
  354. //
  355. // Fill the middle & clean up if asked
  356. //
  357. if (flags & BF_MIDDLE)
  358. FillRectClr(hdc, &rc, (flags & BF_MONO) ? GetSysColor(COLOR_WINDOW) : GetSysColor(COLOR_BTNFACE));
  359. if (flags & BF_ADJUST)
  360. CopyRect(lprc, &rc);
  361. return(TRUE);
  362. }
  363. void PaintRect(HDC hDC, RECT *prect, HBRUSH hBrush, UINT iEdge, UINT iBorder, UINT nStyle)
  364. {
  365. RECT rc;
  366. FillRect(hDC, prect, hBrush);
  367. SetRect(&rc, prect->left+16, prect->top +16, prect->right-16, prect->bottom-16);
  368. switch (nStyle)
  369. {
  370. case 0:
  371. DrawEdge(hDC, &rc, iEdge, iBorder);
  372. break;
  373. case 1:
  374. CCDrawEdge(hDC, &rc, iEdge, iBorder);
  375. break;
  376. case 2:
  377. if (ghTheme)
  378. DrawThemeEdge(ghTheme, hDC, 0, 0, &rc, iEdge, iBorder, NULL);
  379. break;
  380. case 3:
  381. if (ghThemeTB)
  382. DrawThemeEdge(ghThemeTB, hDC, 0, 0, &rc, iEdge, iBorder, NULL);
  383. break;
  384. default:
  385. ;
  386. }
  387. }
  388. /****************************************************************************
  389. FUNCTION: WndProc(HWND, UINT, WPARAM, LPARAM)
  390. PURPOSE: Processes messages
  391. MESSAGES:
  392. WM_COMMAND - application menu (About dialog box)
  393. WM_DESTROY - destroy window
  394. COMMENTS:
  395. To process the IDM_ABOUT message, call MakeProcInstance() to get the
  396. current instance address of the About() function. Then call Dialog
  397. box which will create the box according to the information in your
  398. generic.rc file and turn control over to the About() function. When
  399. it returns, free the intance address.
  400. ****************************************************************************/
  401. LRESULT CALLBACK WndProc(
  402. HWND hWnd, // window handle
  403. UINT message, // type of message
  404. WPARAM uParam, // additional information
  405. LPARAM lParam) // additional information
  406. {
  407. int wmId, wmEvent;
  408. static UINT iEdge = EDGE_SUNKEN;
  409. static UINT iBorder = BF_RECT | BF_MIDDLE;
  410. switch (message) {
  411. case WM_INITMENU:
  412. UpdateMenu(GetMenu(hWnd), iEdge, iBorder);
  413. break;
  414. case WM_THEMECHANGED:
  415. if (ghTheme)
  416. CloseThemeData(ghTheme);
  417. if (ghThemeTB)
  418. CloseThemeData(ghThemeTB);
  419. ghTheme = OpenThemeData(NULL, L"Button");
  420. ghThemeTB = OpenThemeData(NULL, L"Rebar");
  421. InvalidateRect(hWnd, NULL, TRUE);
  422. break;
  423. case WM_PAINT:
  424. {
  425. PAINTSTRUCT ps;
  426. HDC hDC = BeginPaint(hWnd, &ps);
  427. RECT rect;
  428. RECT rectCC, rectTH, rectTB;
  429. SIZE sizeText;
  430. int delta;
  431. WCHAR szDrawEdge[] = L"DrawEdge";
  432. WCHAR szCCDrawEdge[] = L"CCDrawEdge";
  433. WCHAR szDrawThemeEdge[] = L"DrawThemeEdge (Button)";
  434. WCHAR szDrawThemeEdgeTB[] = L"DrawThemeEdge (Rebar)";
  435. GetClientRect(hWnd, &rect);
  436. GetTextExtentPoint32(hDC, L"Dg", 2, &sizeText);
  437. rect.top += sizeText.cy;
  438. rect.bottom -= sizeText.cy;
  439. SetRect(&rect, rect.left, rect.top, (rect.right >> 1), rect.top + ((rect.bottom - rect.top) >> 1));
  440. CopyRect(&rectCC, &rect);
  441. CopyRect(&rectTH, &rect);
  442. CopyRect(&rectTB, &rect);
  443. OffsetRect(&rectCC, rect.right, 0);
  444. OffsetRect(&rectTH, 0, rect.bottom);
  445. OffsetRect(&rectTB, rect.right, rect.bottom);
  446. // Divide into quarters
  447. SetRect(&rect, rect.left, rect.top, (rect.right >> 1), rect.top + ((rect.bottom - rect.top) >> 1));
  448. SetRect(&rectCC, rectCC.left, rectCC.top,
  449. rectCC.left + ((rectCC.right - rectCC.left) >> 1), rectCC.top + ((rectCC.bottom - rectCC.top) >> 1));
  450. SetRect(&rectTH, rectTH.left, rectTH.top,
  451. rectTH.left + ((rectTH.right - rectTH.left) >> 1), rectTH.top + ((rectTH.bottom - rectTH.top) >> 1));
  452. SetRect(&rectTB, rectTB.left, rectTB.top,
  453. rectTB.left + ((rectTB.right - rectTB.left) >> 1), rectTB.top + ((rectTB.bottom - rectTB.top) >> 1));
  454. // Fill upper left quarter
  455. PaintRect(hDC, &rect, GetStockObject(BLACK_BRUSH), iEdge, iBorder, 0);
  456. PaintRect(hDC, &rectCC, GetStockObject(BLACK_BRUSH), iEdge, iBorder, 1);
  457. PaintRect(hDC, &rectTH, GetStockObject(BLACK_BRUSH), iEdge, iBorder, 2);
  458. PaintRect(hDC, &rectTB, GetStockObject(BLACK_BRUSH), iEdge, iBorder, 3);
  459. // Fill upper right quarter
  460. delta = rect.right;
  461. OffsetRect(&rect, delta, 0);
  462. OffsetRect(&rectCC, delta, 0);
  463. OffsetRect(&rectTH, delta, 0);
  464. OffsetRect(&rectTB, delta, 0);
  465. PaintRect(hDC, &rect, GetStockObject(DKGRAY_BRUSH), iEdge, iBorder, 0);
  466. PaintRect(hDC, &rectCC, GetStockObject(DKGRAY_BRUSH), iEdge, iBorder, 1);
  467. PaintRect(hDC, &rectTH, GetStockObject(DKGRAY_BRUSH), iEdge, iBorder, 2);
  468. PaintRect(hDC, &rectTB, GetStockObject(DKGRAY_BRUSH), iEdge, iBorder, 3);
  469. // Fill lower right quarter
  470. delta = rect.bottom - rect.top;
  471. OffsetRect(&rect, 0, delta);
  472. OffsetRect(&rectCC, 0, delta);
  473. OffsetRect(&rectTH, 0, delta);
  474. OffsetRect(&rectTB, 0, delta);
  475. PaintRect(hDC, &rect, GetStockObject(GRAY_BRUSH), iEdge, iBorder, 0);
  476. PaintRect(hDC, &rectCC, GetStockObject(GRAY_BRUSH), iEdge, iBorder, 1);
  477. PaintRect(hDC, &rectTH, GetStockObject(GRAY_BRUSH), iEdge, iBorder, 2);
  478. PaintRect(hDC, &rectTB, GetStockObject(GRAY_BRUSH), iEdge, iBorder, 3);
  479. // Fill lower left quarter
  480. delta = -rect.left;
  481. OffsetRect(&rect, delta, 0);
  482. OffsetRect(&rectCC, delta, 0);
  483. OffsetRect(&rectTH, delta, 0);
  484. OffsetRect(&rectTB, delta, 0);
  485. PaintRect(hDC, &rect, GetStockObject(LTGRAY_BRUSH), iEdge, iBorder, 0);
  486. PaintRect(hDC, &rectCC, GetStockObject(LTGRAY_BRUSH), iEdge, iBorder, 1);
  487. PaintRect(hDC, &rectTH, GetStockObject(LTGRAY_BRUSH), iEdge, iBorder, 2);
  488. PaintRect(hDC, &rectTB, GetStockObject(LTGRAY_BRUSH), iEdge, iBorder, 3);
  489. TextOut(hDC, 0, 0, szDrawEdge, countof(szDrawEdge) - 1);
  490. TextOut(hDC, rectCC.left, 0, szCCDrawEdge, countof(szCCDrawEdge) - 1);
  491. TextOut(hDC, 0, rect.bottom, szDrawThemeEdge, countof(szDrawThemeEdge) - 1);
  492. TextOut(hDC, rectTB.left, rect.bottom, szDrawThemeEdgeTB, countof(szDrawThemeEdgeTB) - 1);
  493. EndPaint(hWnd, &ps);
  494. }
  495. break;
  496. case WM_COMMAND:
  497. wmId = LOWORD(uParam);
  498. wmEvent = HIWORD(uParam);
  499. switch (wmId) {
  500. case IDM_BDR_RAISEDINNER:
  501. if (iEdge & BDR_SUNKENINNER) iEdge ^= BDR_SUNKENINNER;
  502. iEdge ^= BDR_RAISEDINNER;
  503. break;
  504. case IDM_BDR_SUNKENINNER:
  505. if (iEdge & BDR_RAISEDINNER) iEdge ^= BDR_RAISEDINNER;
  506. iEdge ^= BDR_SUNKENINNER;
  507. break;
  508. case IDM_BDR_RAISEDOUTER:
  509. if (iEdge & BDR_SUNKENOUTER) iEdge ^= BDR_SUNKENOUTER;
  510. iEdge ^= BDR_RAISEDOUTER;
  511. break;
  512. case IDM_BDR_SUNKENOUTER:
  513. if (iEdge & BDR_RAISEDOUTER) iEdge ^= BDR_RAISEDOUTER;
  514. iEdge ^= BDR_SUNKENOUTER;
  515. break;
  516. case IDM_EDGE_EDGE_BUMP:
  517. iEdge ^= (iEdge & (BDR_RAISEDINNER | BDR_SUNKENINNER | BDR_RAISEDOUTER | BDR_SUNKENOUTER));
  518. iEdge ^= EDGE_BUMP;
  519. break;
  520. case IDM_EDGE_EDGE_ETCHED:
  521. iEdge ^= (iEdge & (BDR_RAISEDINNER | BDR_SUNKENINNER | BDR_RAISEDOUTER | BDR_SUNKENOUTER));
  522. iEdge ^= EDGE_ETCHED;
  523. break;
  524. case IDM_EDGE_EDGE_RAISED:
  525. iEdge ^= (iEdge & (BDR_RAISEDINNER | BDR_SUNKENINNER | BDR_RAISEDOUTER | BDR_SUNKENOUTER));
  526. iEdge ^= EDGE_RAISED;
  527. break;
  528. case IDM_EDGE_EDGE_SUNKEN:
  529. iEdge ^= (iEdge & (BDR_RAISEDINNER | BDR_SUNKENINNER | BDR_RAISEDOUTER | BDR_SUNKENOUTER));
  530. iEdge ^= EDGE_SUNKEN;
  531. break;
  532. case IDM_BORDER_BF_ADJUST:
  533. iBorder ^= BF_ADJUST;
  534. break;
  535. case IDM_BORDER_BF_BOTTOM:
  536. iBorder ^= BF_BOTTOM;
  537. break;
  538. case IDM_BORDER_BF_DIAGONAL:
  539. iBorder ^= BF_DIAGONAL;
  540. break;
  541. case IDM_BORDER_BF_FLAT:
  542. iBorder ^= BF_FLAT;
  543. break;
  544. case IDM_BORDER_BF_LEFT:
  545. iBorder ^= BF_LEFT;
  546. break;
  547. case IDM_BORDER_BF_MIDDLE:
  548. iBorder ^= BF_MIDDLE;
  549. break;
  550. case IDM_BORDER_BF_MONO:
  551. iBorder ^= BF_MONO;
  552. break;
  553. case IDM_BORDER_BF_RIGHT:
  554. iBorder ^= BF_RIGHT;
  555. break;
  556. case IDM_BORDER_BF_SOFT:
  557. iBorder ^= BF_SOFT;
  558. break;
  559. case IDM_BORDER_BF_TOP:
  560. iBorder ^= BF_TOP;
  561. break;
  562. case IDM_BORDER_BF_RECT:
  563. iBorder ^= (iBorder & (BF_RECT | BF_DIAGONAL));
  564. iBorder ^= BF_RECT;
  565. break;
  566. case IDM_BORDER_BF_BOTTOMLEFT:
  567. iBorder ^= (iBorder & (BF_RECT | BF_DIAGONAL));
  568. iBorder ^= BF_BOTTOMLEFT;
  569. break;
  570. case IDM_BORDER_BF_BOTTOMRIGHT:
  571. iBorder ^= (iBorder & (BF_RECT | BF_DIAGONAL));
  572. iBorder ^= BF_BOTTOMRIGHT;
  573. break;
  574. case IDM_BORDER_BF_TOPLEFT:
  575. iBorder ^= (iBorder & (BF_RECT | BF_DIAGONAL));
  576. iBorder ^= BF_TOPLEFT;
  577. break;
  578. case IDM_BORDER_BF_TOPRIGHT:
  579. iBorder ^= (iBorder & (BF_RECT | BF_DIAGONAL));
  580. iBorder ^= BF_TOPRIGHT;
  581. break;
  582. case IDM_BORDER_BF_DIAGONAL_ENDBOTTOMLEFT:
  583. iBorder ^= (iBorder & (BF_RECT | BF_DIAGONAL));
  584. iBorder ^= BF_DIAGONAL_ENDBOTTOMLEFT;
  585. break;
  586. case IDM_BORDER_BF_DIAGONAL_ENDBOTTOMRIGHT:
  587. iBorder ^= (iBorder & (BF_RECT | BF_DIAGONAL));
  588. iBorder ^= BF_DIAGONAL_ENDBOTTOMRIGHT;
  589. break;
  590. case IDM_BORDER_BF_DIAGONAL_ENDTOPLEFT:
  591. iBorder ^= (iBorder & (BF_RECT | BF_DIAGONAL));
  592. iBorder ^= BF_DIAGONAL_ENDTOPLEFT;
  593. break;
  594. case IDM_BORDER_BF_DIAGONAL_ENDTOPRIGHT:
  595. iBorder ^= (iBorder & (BF_RECT | BF_DIAGONAL));
  596. iBorder ^= BF_DIAGONAL_ENDTOPRIGHT;
  597. break;
  598. case IDM_ABOUT:
  599. DialogBox(hInst, // current instance
  600. L"ABOUTBOX", // dlg resource to use
  601. hWnd, // parent handle
  602. (DLGPROC)About); // About() instance address
  603. break;
  604. case IDM_EXIT:
  605. DestroyWindow (hWnd);
  606. break;
  607. default:
  608. return (DefWindowProc(hWnd, message, uParam, lParam));
  609. };
  610. UpdateMenu(GetMenu(hWnd), iEdge, iBorder);
  611. InvalidateRect(hWnd, NULL, TRUE);
  612. break;
  613. case WM_DESTROY: // message: window being destroyed
  614. PostQuitMessage(0);
  615. break;
  616. default: // Passes it on if unproccessed
  617. return (DefWindowProc(hWnd, message, uParam, lParam));
  618. }
  619. return (0);
  620. }
  621. /*****************************************************************************
  622. * *
  623. * FUNCTION: CenterWindow (HWND, HWND) *
  624. * *
  625. * PURPOSE: Center one window over another *
  626. * *
  627. * COMMENTS: *
  628. * *
  629. * Dialog boxes take on the screen position that they were designed at, *
  630. * which is not always appropriate. Centering the dialog over a particular *
  631. * window usually results in a better position. *
  632. * *
  633. ****************************************************************************/
  634. BOOL CenterWindow (HWND hwndChild, HWND hwndParent)
  635. {
  636. RECT rChild, rParent;
  637. int wChild, hChild, wParent, hParent;
  638. int wScreen, hScreen, xNew, yNew;
  639. HDC hdc;
  640. // Get the Height and Width of the child window
  641. GetWindowRect (hwndChild, &rChild);
  642. wChild = rChild.right - rChild.left;
  643. hChild = rChild.bottom - rChild.top;
  644. // Get the Height and Width of the parent window
  645. GetWindowRect (hwndParent, &rParent);
  646. wParent = rParent.right - rParent.left;
  647. hParent = rParent.bottom - rParent.top;
  648. // Get the display limits
  649. hdc = GetDC (hwndChild);
  650. wScreen = GetDeviceCaps (hdc, HORZRES);
  651. hScreen = GetDeviceCaps (hdc, VERTRES);
  652. ReleaseDC (hwndChild, hdc);
  653. // Calculate new X position, then adjust for screen
  654. xNew = rParent.left + ((wParent - wChild) /2);
  655. if (xNew < 0) {
  656. xNew = 0;
  657. } else if ((xNew+wChild) > wScreen) {
  658. xNew = wScreen - wChild;
  659. }
  660. // Calculate new Y position, then adjust for screen
  661. yNew = rParent.top + ((hParent - hChild) /2);
  662. if (yNew < 0) {
  663. yNew = 0;
  664. } else if ((yNew+hChild) > hScreen) {
  665. yNew = hScreen - hChild;
  666. }
  667. // Set it, and return
  668. return SetWindowPos (hwndChild, NULL,
  669. xNew, yNew, 0, 0, SWP_NOSIZE | SWP_NOZORDER);
  670. }
  671. /*****************************************************************************
  672. * *
  673. * FUNCTION: About(HWND, UINT, WPARAM, LPARAM) *
  674. * *
  675. * PURPOSE: Processes messages for "About" dialog box *
  676. * *
  677. * MESSAGES: *
  678. * *
  679. * WM_INITDIALOG - initialize dialog box *
  680. * WM_COMMAND - Input received *
  681. * *
  682. * COMMENTS: *
  683. * *
  684. * Display version information from the version section of the *
  685. * application resource. *
  686. * *
  687. * Wait for user to click on "Ok" button, then close the dialog box. *
  688. * *
  689. ****************************************************************************/
  690. LRESULT CALLBACK About(
  691. HWND hDlg, // window handle of the dialog box
  692. UINT message, // type of message
  693. WPARAM uParam, // message-specific information
  694. LPARAM lParam)
  695. {
  696. switch (message) {
  697. case WM_INITDIALOG: // message: initialize dialog box
  698. // Center the dialog over the application window
  699. CenterWindow (hDlg, GetWindow (hDlg, GW_OWNER));
  700. return (TRUE);
  701. case WM_COMMAND: // message: received a command
  702. if (LOWORD(uParam) == IDOK || LOWORD(uParam) == IDCANCEL) {
  703. EndDialog(hDlg, TRUE); // Exit the dialog
  704. return (TRUE);
  705. }
  706. break;
  707. }
  708. return (FALSE); // Didn't process the message
  709. UNREFERENCED_PARAMETER(lParam); // This will prevent 'unused formal parameter' warnings
  710. }