Leaked source code of windows server 2003
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.

490 lines
15 KiB

  1. /******************************Module*Header*******************************\
  2. * Module Name: wndstuff.cpp
  3. *
  4. * This file contains the code to support a simple window that has
  5. * a menu with a single item called "Test". When "Test" is selected
  6. * vTest(HWND) is called.
  7. *
  8. * Created: 09-Dec-1992 10:44:31
  9. * Author: Kirk Olynyk [kirko]
  10. *
  11. * Copyright (c) 1991 Microsoft Corporation
  12. *
  13. \**************************************************************************/
  14. // for Win95 compile
  15. #undef UNICODE
  16. #undef _UNICODE
  17. #include <windows.h>
  18. #include <stdio.h>
  19. #include <tchar.h>
  20. #include <objbase.h>
  21. #include <commdlg.h>
  22. #include "wndstuff.h"
  23. #include "../gpinit.inc"
  24. HINSTANCE ghInstance;
  25. HWND ghwndMain;
  26. HWND ghwndDebug;
  27. HWND ghwndList;
  28. HBRUSH ghbrWhite;
  29. bool buttondown = false;
  30. float flatness = 0.25f;
  31. PtFlag ifs(INT f, PtFlag v)
  32. {
  33. return f ? v : PtNoFlag;
  34. }
  35. PtFlag CalcFlags(HWND hwnd)
  36. {
  37. return (PtFlag)(
  38. ifs(GetMenuState(GetMenu(hwnd), MM_BEZIERMODE, MF_BYCOMMAND) & MF_CHECKED, PtBezierFlag) |
  39. ifs(GetMenuState(GetMenu(hwnd), MM_OBEFOREMODE, MF_BYCOMMAND) & MF_CHECKED, PtOutlineBeforeFlag) |
  40. ifs(GetMenuState(GetMenu(hwnd), MM_OAFTERMODE, MF_BYCOMMAND) & MF_CHECKED, PtOutlineAfterFlag) |
  41. ifs(GetMenuState(GetMenu(hwnd), MM_SHOWDASHSTROKE, MF_BYCOMMAND) & MF_CHECKED, PtDashPatternFlag) |
  42. ifs(GetMenuState(GetMenu(hwnd), MM_SHOWHATCHBRUSHSTROKE, MF_BYCOMMAND) & MF_CHECKED, PtHatchBrushFlag) |
  43. ifs(GetMenuState(GetMenu(hwnd), MM_SHOWTEXTUREFILL, MF_BYCOMMAND) & MF_CHECKED, PtTextureFillFlag) |
  44. ifs(GetMenuState(GetMenu(hwnd), MM_SHOWTRANSSOLIDFILL, MF_BYCOMMAND) & MF_CHECKED, PtTransSolidFillFlag) |
  45. ifs(GetMenuState(GetMenu(hwnd), MM_SHOWTRANSGRADFILL, MF_BYCOMMAND) & MF_CHECKED, PtTransGradFillFlag) |
  46. ifs(GetMenuState(GetMenu(hwnd), MM_SHOWBGGRADFILL, MF_BYCOMMAND) & MF_CHECKED, PTBackgroundGradFillFlag));}
  47. void HandleCheckUncheck(INT flag, HWND hwnd)
  48. {
  49. if (GetMenuState(GetMenu(hwnd), flag, MF_BYCOMMAND) & MF_CHECKED)
  50. CheckMenuItem(GetMenu(hwnd), flag, MF_UNCHECKED);
  51. else
  52. CheckMenuItem(GetMenu(hwnd), flag, MF_CHECKED);
  53. InvalidateRect(hwnd, NULL, false);
  54. }
  55. /***************************************************************************\
  56. * lMainWindowProc(hwnd, message, wParam, lParam)
  57. *
  58. * Processes all messages for the main window.
  59. *
  60. * History:
  61. * 04-07-91 -by- KentD
  62. * Wrote it.
  63. \***************************************************************************/
  64. LRESULT CALLBACK
  65. lMainWindowProc(
  66. HWND hwnd,
  67. UINT message,
  68. WPARAM wParam,
  69. LPARAM lParam
  70. )
  71. {
  72. INT xpos, ypos;
  73. switch (message)
  74. {
  75. case WM_CREATE:
  76. return true;
  77. case WM_SIZE:
  78. xpos = LOWORD(lParam);
  79. ypos = HIWORD(lParam);
  80. Resize(xpos, ypos);
  81. InvalidateRect(hwnd, NULL, false);
  82. return true;
  83. case WM_LBUTTONDOWN:
  84. buttondown = true;
  85. return true;
  86. case WM_LBUTTONUP:
  87. if (!buttondown)
  88. break;
  89. buttondown = false;
  90. xpos = LOWORD(lParam);
  91. ypos = HIWORD(lParam);
  92. RECT rect;
  93. GetClientRect(hwnd, &rect);
  94. AddPoint(xpos, ypos);
  95. InvalidateRect(hwnd, NULL, false);
  96. return true;
  97. case WM_COMMAND: {
  98. INT flag = LOWORD(wParam);
  99. switch(flag)
  100. {
  101. case MM_SHOWDASHSTROKE:
  102. HandleCheckUncheck(flag, hwnd);
  103. return true;
  104. case MM_SHOWHATCHBRUSHSTROKE:
  105. HandleCheckUncheck(flag, hwnd);
  106. return true;
  107. case MM_SHOWTEXTUREFILL:
  108. HandleCheckUncheck(flag, hwnd);
  109. return true;
  110. case MM_SHOWTRANSSOLIDFILL:
  111. HandleCheckUncheck(flag, hwnd);
  112. return true;
  113. case MM_SHOWTRANSGRADFILL:
  114. HandleCheckUncheck(flag, hwnd);
  115. return true;
  116. case MM_SHOWBGGRADFILL:
  117. HandleCheckUncheck(flag, hwnd);
  118. return true;
  119. case MM_CHANGETEXTUREFILL: {
  120. OPENFILENAME ofn; // common dialog box structure
  121. char szFile[260]; // buffer for file name
  122. szFile[0] = 0;
  123. ZeroMemory(&ofn, sizeof(OPENFILENAME));
  124. ofn.lStructSize = sizeof(OPENFILENAME);
  125. ofn.hwndOwner = hwnd;
  126. ofn.lpstrFile = szFile;
  127. ofn.nMaxFile = sizeof(szFile);
  128. ofn.lpstrFilter = "Images\0*.*\0";
  129. ofn.nFilterIndex = 0;
  130. ofn.lpstrFileTitle = NULL;
  131. ofn.nMaxFileTitle = 0;
  132. ofn.lpstrInitialDir = NULL;
  133. ofn.Flags = OFN_PATHMUSTEXIST | OFN_FILEMUSTEXIST;
  134. char curdir[260];
  135. GetCurrentDirectory(sizeof(curdir), curdir);
  136. if (GetOpenFileName(&ofn)==TRUE)
  137. {
  138. WCHAR wchar[256];
  139. MultiByteToWideChar(CP_ACP, MB_PRECOMPOSED, ofn.lpstrFile, -1, wchar, 256);
  140. ChangeTexture(wchar);
  141. SetCurrentDirectory(curdir);
  142. InvalidateRect(hwnd, NULL, false);
  143. }
  144. else
  145. {
  146. printf("%d", CommDlgExtendedError());
  147. }
  148. return true;}
  149. case MM_OPENFILE: {
  150. OPENFILENAME ofn; // common dialog box structure
  151. char szFile[260]; // buffer for file name
  152. szFile[0] = 0;
  153. ZeroMemory(&ofn, sizeof(OPENFILENAME));
  154. ofn.lStructSize = sizeof(OPENFILENAME);
  155. ofn.hwndOwner = hwnd;
  156. ofn.lpstrFile = szFile;
  157. ofn.nMaxFile = sizeof(szFile);
  158. ofn.lpstrFilter = "All\0*.*\0Text\0*.TXT\0";
  159. ofn.nFilterIndex = 1;
  160. ofn.lpstrFileTitle = NULL;
  161. ofn.nMaxFileTitle = 0;
  162. ofn.lpstrInitialDir = NULL;
  163. ofn.Flags = OFN_PATHMUSTEXIST | OFN_FILEMUSTEXIST;
  164. char curdir[260];
  165. GetCurrentDirectory(sizeof(curdir), curdir);
  166. if (GetOpenFileName(&ofn)==TRUE)
  167. {
  168. OpenPath(ofn.lpstrFile);
  169. SetCurrentDirectory(curdir);
  170. InvalidateRect(hwnd, NULL, false);
  171. }
  172. else
  173. {
  174. printf("%d", CommDlgExtendedError());
  175. }
  176. return true;}
  177. case MM_SAVEFILE: {
  178. OPENFILENAME ofn; // common dialog box structure
  179. char szFile[260]; // buffer for file name
  180. szFile[0] = 0;
  181. ZeroMemory(&ofn, sizeof(OPENFILENAME));
  182. ofn.lStructSize = sizeof(OPENFILENAME);
  183. ofn.hwndOwner = hwnd;
  184. ofn.lpstrFile = szFile;
  185. ofn.nMaxFile = sizeof(szFile);
  186. ofn.lpstrFilter = "All\0*.*\0Text\0*.TXT\0";
  187. ofn.nFilterIndex = 1;
  188. ofn.lpstrFileTitle = NULL;
  189. ofn.nMaxFileTitle = 0;
  190. ofn.lpstrInitialDir = NULL;
  191. ofn.Flags = OFN_PATHMUSTEXIST | OFN_OVERWRITEPROMPT;
  192. char curdir[260];
  193. GetCurrentDirectory(sizeof(curdir), curdir);
  194. if (GetOpenFileName(&ofn)==TRUE)
  195. {
  196. SavePath(ofn.lpstrFile);
  197. SetCurrentDirectory(curdir);
  198. InvalidateRect(hwnd, NULL, false);
  199. }
  200. else
  201. {
  202. printf("%d", CommDlgExtendedError());
  203. }
  204. return true;}
  205. case MM_PRINT:
  206. Print(hwnd, flatness, CalcFlags(hwnd));
  207. return true;
  208. case MM_CLOSEPATH:
  209. ClosePath();
  210. InvalidateRect(hwnd, NULL, false);
  211. return true;
  212. case MM_CLEARPATH:
  213. ClearPath();
  214. InvalidateRect(hwnd, NULL, false);
  215. return true;
  216. case MM_USEASCLIPPATH: {
  217. ClipPath(CalcFlags(hwnd) & PtBezierFlag);
  218. InvalidateRect(hwnd, NULL, false);
  219. return true;}
  220. case MM_CLEARCLIPPATH:
  221. ClearClipPath();
  222. InvalidateRect(hwnd, NULL, false);
  223. return true;
  224. case MM_LINEMODE:
  225. CheckMenuItem(GetMenu(hwnd), MM_LINEMODE, MF_CHECKED);
  226. CheckMenuItem(GetMenu(hwnd), MM_BEZIERMODE, MF_UNCHECKED);
  227. InvalidateRect(hwnd, NULL, false);
  228. return true;
  229. case MM_BEZIERMODE:
  230. CheckMenuItem(GetMenu(hwnd), MM_LINEMODE, MF_UNCHECKED);
  231. CheckMenuItem(GetMenu(hwnd), MM_BEZIERMODE, MF_CHECKED);
  232. InvalidateRect(hwnd, NULL, false);
  233. return true;
  234. case MM_OBEFOREMODE:
  235. if (GetMenuState(GetMenu(hwnd), MM_OBEFOREMODE, MF_BYCOMMAND) & MF_CHECKED)
  236. CheckMenuItem(GetMenu(hwnd), MM_OBEFOREMODE, MF_UNCHECKED);
  237. else
  238. CheckMenuItem(GetMenu(hwnd), MM_OBEFOREMODE, MF_CHECKED);
  239. InvalidateRect(hwnd, NULL, false);
  240. return true;
  241. case MM_OAFTERMODE:
  242. if (GetMenuState(GetMenu(hwnd), MM_OAFTERMODE, MF_BYCOMMAND) & MF_CHECKED)
  243. CheckMenuItem(GetMenu(hwnd), MM_OAFTERMODE, MF_UNCHECKED);
  244. else
  245. CheckMenuItem(GetMenu(hwnd), MM_OAFTERMODE, MF_CHECKED);
  246. InvalidateRect(hwnd, NULL, false);
  247. return true;
  248. case MM_FLATNESS_1:
  249. case MM_FLATNESS_2:
  250. case MM_FLATNESS_3:
  251. case MM_FLATNESS_4: {
  252. CheckMenuItem(GetMenu(hwnd), MM_FLATNESS_1, MF_UNCHECKED);
  253. CheckMenuItem(GetMenu(hwnd), MM_FLATNESS_2, MF_UNCHECKED);
  254. CheckMenuItem(GetMenu(hwnd), MM_FLATNESS_3, MF_UNCHECKED);
  255. CheckMenuItem(GetMenu(hwnd), MM_FLATNESS_4, MF_UNCHECKED);
  256. InvalidateRect(hwnd, NULL, false);
  257. switch (LOWORD(wParam))
  258. {
  259. case MM_FLATNESS_1:
  260. flatness = 10.0f;
  261. CheckMenuItem(GetMenu(hwnd), MM_FLATNESS_1, MF_CHECKED);
  262. return true;
  263. case MM_FLATNESS_2:
  264. flatness = 1.0f;
  265. CheckMenuItem(GetMenu(hwnd), MM_FLATNESS_2, MF_CHECKED);
  266. return true;
  267. case MM_FLATNESS_3:
  268. flatness = 0.25f;
  269. CheckMenuItem(GetMenu(hwnd), MM_FLATNESS_3, MF_CHECKED);
  270. return true;
  271. case MM_FLATNESS_4:
  272. flatness = 0.1f;
  273. CheckMenuItem(GetMenu(hwnd), MM_FLATNESS_4, MF_CHECKED);
  274. return true;
  275. }
  276. }
  277. case MM_COLORMODE_NOCHANGE:
  278. CheckMenuItem(GetMenu(hwnd), MM_COLORMODE_NOCHANGE, MF_CHECKED);
  279. CheckMenuItem(GetMenu(hwnd), MM_COLORMODE_TRANS50, MF_UNCHECKED);
  280. CheckMenuItem(GetMenu(hwnd), MM_COLORMODE_GRADTRANS, MF_UNCHECKED);
  281. SetColorMode(0);
  282. InvalidateRect(hwnd, NULL, false);
  283. return true;
  284. case MM_COLORMODE_TRANS50:
  285. CheckMenuItem(GetMenu(hwnd), MM_COLORMODE_NOCHANGE, MF_UNCHECKED);
  286. CheckMenuItem(GetMenu(hwnd), MM_COLORMODE_TRANS50, MF_CHECKED);
  287. CheckMenuItem(GetMenu(hwnd), MM_COLORMODE_GRADTRANS, MF_UNCHECKED);
  288. SetColorMode(1);
  289. InvalidateRect(hwnd, NULL, false);
  290. return true;
  291. case MM_COLORMODE_GRADTRANS:
  292. CheckMenuItem(GetMenu(hwnd), MM_COLORMODE_NOCHANGE, MF_UNCHECKED);
  293. CheckMenuItem(GetMenu(hwnd), MM_COLORMODE_TRANS50, MF_UNCHECKED);
  294. CheckMenuItem(GetMenu(hwnd), MM_COLORMODE_GRADTRANS, MF_CHECKED);
  295. SetColorMode(2);
  296. InvalidateRect(hwnd, NULL, false);
  297. return true;
  298. default:
  299. break;
  300. }
  301. break;}
  302. case WM_KEYUP:
  303. if(!( ((CHAR)wParam=='q') ||
  304. ((CHAR)wParam=='Q') ) )
  305. {
  306. break;
  307. }
  308. case WM_DESTROY:
  309. CleanUp();
  310. DeleteObject(ghbrWhite);
  311. PostQuitMessage(0);
  312. return(DefWindowProc(hwnd, message, wParam, lParam));
  313. case WM_PAINT:
  314. DrawPath(hwnd, NULL, NULL, flatness, CalcFlags(hwnd));
  315. return true;
  316. default:
  317. return(DefWindowProc(hwnd, message, wParam, lParam));
  318. }
  319. return(0);
  320. }
  321. /***************************************************************************\
  322. * bInitApp()
  323. *
  324. * Initializes app.
  325. *
  326. * History:
  327. * 04-07-91 -by- KentD
  328. * Wrote it.
  329. \***************************************************************************/
  330. BOOL bInitApp(BOOL debug)
  331. {
  332. debug = FALSE;
  333. WNDCLASS wc;
  334. //ghbrWhite = CreateSolidBrush(RGB(0xFF,0xFF,0xFF));
  335. wc.style = 0;
  336. wc.lpfnWndProc = lMainWindowProc;
  337. wc.cbClsExtra = 0;
  338. wc.cbWndExtra = 0;
  339. wc.hInstance = ghInstance;
  340. wc.hIcon = LoadIcon(NULL, IDI_APPLICATION);
  341. wc.hCursor = LoadCursor(NULL, IDC_ARROW);
  342. //wc.hbrBackground = ghbrWhite;
  343. wc.hbrBackground = NULL;
  344. wc.lpszMenuName = _T("MainMenu");
  345. wc.lpszClassName = _T("TestClass");
  346. if (!RegisterClass(&wc))
  347. {
  348. return(FALSE);
  349. }
  350. ghwndMain =
  351. CreateWindowEx(
  352. 0,
  353. _T("TestClass"),
  354. _T("Win32 Test"),
  355. WS_OVERLAPPED |
  356. WS_CAPTION |
  357. WS_THICKFRAME |
  358. WS_MAXIMIZEBOX |
  359. WS_BORDER |
  360. WS_MINIMIZEBOX |
  361. WS_CLIPCHILDREN |
  362. WS_VISIBLE |
  363. WS_SYSMENU,
  364. 80,
  365. 70,
  366. 500,
  367. 500,
  368. NULL,
  369. NULL,
  370. ghInstance,
  371. NULL);
  372. if (ghwndMain == NULL)
  373. {
  374. return(FALSE);
  375. }
  376. SetFocus(ghwndMain);
  377. return(TRUE);
  378. }
  379. /***************************************************************************\
  380. * main(argc, argv[])
  381. *
  382. * Sets up the message loop.
  383. *
  384. * History:
  385. * 04-07-91 -by- KentD
  386. * Wrote it.
  387. \***************************************************************************/
  388. _cdecl
  389. main(
  390. INT argc,
  391. PCHAR argv[])
  392. {
  393. MSG msg;
  394. HACCEL haccel;
  395. if (!gGdiplusInitHelper.IsValid())
  396. {
  397. return 0;
  398. }
  399. BOOL wantDebugWindow = FALSE;
  400. CoInitialize(NULL);
  401. // Parse arguments
  402. for (argc--, argv++ ; argc && '-' == **argv ; argc--, argv++ )
  403. {
  404. switch ( *(++(*argv)) )
  405. {
  406. case 'd':
  407. case 'D':
  408. wantDebugWindow = TRUE;
  409. break;
  410. }
  411. }
  412. ghInstance = GetModuleHandle(NULL);
  413. if (!bInitApp(wantDebugWindow))
  414. {
  415. return(0);
  416. }
  417. haccel = LoadAccelerators(ghInstance, MAKEINTRESOURCE(101));
  418. while (GetMessage(&msg, NULL, 0, 0))
  419. {
  420. if (!TranslateAccelerator(msg.hwnd, haccel, &msg))
  421. {
  422. TranslateMessage(&msg);
  423. DispatchMessage(&msg);
  424. }
  425. }
  426. CoUninitialize();
  427. return(1);
  428. }