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.

473 lines
10 KiB

  1. // gdipdraw.cpp : Defines the entry point for the application.
  2. //
  3. #include "stdafx.h"
  4. #include "gdiptest.h"
  5. #pragma hdrstop
  6. // end of precompiled header segment
  7. //using namespace Gdiplus;
  8. // Global Variables:
  9. HINSTANCE hInst; // current instance
  10. TCHAR szTitle[MAX_LOADSTRING]; // The title bar text
  11. TCHAR szWindowClass[MAX_LOADSTRING]; // The title bar text
  12. int APIENTRY WinMain(HINSTANCE hInstance,
  13. HINSTANCE hPrevInstance,
  14. LPSTR lpCmdLine,
  15. int nCmdShow)
  16. {
  17. MSG msg;
  18. HACCEL hAccelTable;
  19. HWND hWnd;
  20. // Initialize global strings
  21. LoadString(hInstance, IDS_APP_TITLE, szTitle, MAX_LOADSTRING);
  22. LoadString(hInstance, IDC_GDIPTEST, szWindowClass, MAX_LOADSTRING);
  23. MyRegisterClass(hInstance);
  24. TestDraw draw;
  25. // Perform application initialization:
  26. hWnd = InitInstance (hInstance, nCmdShow,
  27. (LPVOID)(static_cast<TestDrawInterface*>(&draw)));
  28. if (hWnd == (HWND)0)
  29. {
  30. return FALSE;
  31. }
  32. // initialize global control point colors
  33. blackColor = new Color(0x80, 0, 0, 0);
  34. blackBrush = new SolidBrush(*blackColor);
  35. blackPen = new Pen(*blackColor, 5.0f);
  36. Color whiteColor(0xFFFFFFFF);
  37. backBrush = new SolidBrush(whiteColor);
  38. draw.UpdateStatus(hWnd);
  39. // initialize menu check marks
  40. SetMenuCheckPos(hWnd, MenuShapePosition, 0, TRUE);
  41. SetMenuCheckPos(hWnd, MenuBrushPosition, 0, TRUE);
  42. hAccelTable = LoadAccelerators(hInstance, (LPCTSTR)IDC_GDIPTEST);
  43. // Main message loop:
  44. while (GetMessage(&msg, NULL, 0, 0))
  45. {
  46. if (!TranslateAccelerator(msg.hwnd, hAccelTable, &msg))
  47. {
  48. TranslateMessage(&msg);
  49. DispatchMessage(&msg);
  50. }
  51. }
  52. delete blackColor;
  53. delete blackBrush;
  54. delete blackPen;
  55. delete backBrush;
  56. return msg.wParam;
  57. }
  58. //
  59. // FUNCTION: MyRegisterClass()
  60. //
  61. // PURPOSE: Registers the window class.
  62. //
  63. // COMMENTS:
  64. //
  65. // This function and its usage is only necessary if you want this code
  66. // to be compatible with Win32 systems prior to the 'RegisterClassEx'
  67. // function that was added to Windows 95. It is important to call this function
  68. // so that the application will get 'well formed' small icons associated
  69. // with it.
  70. //
  71. ATOM MyRegisterClass(HINSTANCE hInstance)
  72. {
  73. WNDCLASSEX wcex;
  74. wcex.cbSize = sizeof(WNDCLASSEX);
  75. wcex.style = CS_HREDRAW | CS_VREDRAW;
  76. wcex.lpfnWndProc = WndTestDrawProc;
  77. wcex.cbClsExtra = 0;
  78. wcex.cbWndExtra = 0;
  79. wcex.hInstance = hInstance;
  80. wcex.hIcon = LoadIcon(hInstance, (LPCTSTR)IDI_GDIPTEST);
  81. wcex.hCursor = LoadCursor(NULL, IDC_ARROW);
  82. wcex.hbrBackground = (HBRUSH)(COLOR_WINDOW+1);
  83. wcex.lpszMenuName = (LPCSTR)IDC_GDIPTEST;
  84. wcex.lpszClassName = szWindowClass;
  85. wcex.hIconSm = LoadIcon(wcex.hInstance, (LPCTSTR)IDI_SMALL);
  86. return RegisterClassEx(&wcex);
  87. }
  88. //
  89. // FUNCTION: InitInstance(HANDLE, int)
  90. //
  91. // PURPOSE: Saves instance handle and creates main window
  92. //
  93. // COMMENTS:
  94. //
  95. // In this function, we save the instance handle in a global variable and
  96. // create and display the main program window.
  97. //
  98. HWND InitInstance(HINSTANCE hInstance, int nCmdShow, LPVOID param)
  99. {
  100. HWND hWnd;
  101. hInst = hInstance; // Store instance handle in our global variable
  102. hWnd = CreateWindow(
  103. szWindowClass,
  104. szTitle,
  105. WS_OVERLAPPEDWINDOW,
  106. CW_USEDEFAULT,
  107. 0,
  108. CW_USEDEFAULT,
  109. 0,
  110. NULL,
  111. NULL,
  112. hInstance,
  113. param);
  114. if (!hWnd)
  115. {
  116. return (HWND)0;
  117. }
  118. ShowWindow(hWnd, nCmdShow);
  119. UpdateWindow(hWnd);
  120. return hWnd;
  121. }
  122. //
  123. // FUNCTION: WndTestDrawProc(HWND, unsigned, WORD, LONG)
  124. //
  125. // PURPOSE: Processes messages for the main window.
  126. //
  127. // WM_COMMAND - process the application menu
  128. // WM_PAINT - Paint the main window
  129. // WM_DESTROY - post a quit message and return
  130. //
  131. //
  132. LRESULT CALLBACK WndTestDrawProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam)
  133. {
  134. int wmId, wmEvent;
  135. switch (message)
  136. {
  137. case WM_CREATE:
  138. {
  139. TestDrawInterface* dlgInt =
  140. static_cast<TestDrawInterface*>
  141. (((LPCREATESTRUCT)lParam)->lpCreateParams);
  142. SetWindowLong(hWnd, GWL_USERDATA, (LONG)dlgInt);
  143. break;
  144. }
  145. case WM_COMMAND:
  146. {
  147. wmId = LOWORD(wParam);
  148. wmEvent = HIWORD(wParam);
  149. TestDrawInterface* drawInt =
  150. (TestDrawInterface*)GetWindowLong(hWnd, GWL_USERDATA);
  151. TestDraw* draw = static_cast<TestDraw*>(drawInt);
  152. TestGradDraw* graddraw = static_cast<TestGradDraw*>(drawInt);
  153. // Parse the menu selections:
  154. switch (wmId)
  155. {
  156. // Shape Menu
  157. case IDM_LINE:
  158. draw->ChangeShape(hWnd, LineType);
  159. break;
  160. case IDM_ARC:
  161. draw->ChangeShape(hWnd, ArcType);
  162. break;
  163. case IDM_BEZIER:
  164. draw->ChangeShape(hWnd, BezierType);
  165. break;
  166. case IDM_RECT:
  167. draw->ChangeShape(hWnd, RectType);
  168. break;
  169. case IDM_ELLIPSE:
  170. draw->ChangeShape(hWnd, EllipseType);
  171. break;
  172. case IDM_PIE:
  173. draw->ChangeShape(hWnd, PieType);
  174. break;
  175. case IDM_POLYGON:
  176. draw->ChangeShape(hWnd, PolygonType);
  177. break;
  178. case IDM_CURVE:
  179. draw->ChangeShape(hWnd, CurveType);
  180. break;
  181. case IDM_CLOSED:
  182. draw->ChangeShape(hWnd, ClosedCurveType);
  183. break;
  184. case IDM_REGION:
  185. // do complete redraw if leaving incomplete shape
  186. break;
  187. // Brush Menu
  188. case IDM_SOLIDBRUSH:
  189. draw->ChangeBrush(hWnd, SolidColorBrush);
  190. break;
  191. case IDM_TEXTURE:
  192. draw->ChangeBrush(hWnd, TextureFillBrush);
  193. break;
  194. case IDM_RECTGRAD:
  195. draw->ChangeBrush(hWnd, RectGradBrush);
  196. break;
  197. case IDM_RADGRAD:
  198. draw->ChangeBrush(hWnd, RadialGradBrush);
  199. break;
  200. case IDM_TRIGRAD:
  201. draw->ChangeBrush(hWnd, TriangleGradBrush);
  202. break;
  203. case IDM_POLYGRAD:
  204. draw->ChangeBrush(hWnd, PathGradBrush);
  205. break;
  206. case IDM_HATCH:
  207. draw->ChangeBrush(hWnd, HatchFillBrush);
  208. break;
  209. // Pen Menu
  210. case IDM_PEN:
  211. draw->ChangePen(hWnd);
  212. break;
  213. // Redraw Menu
  214. case IDM_REDRAWALL:
  215. draw->redrawAll = !draw->redrawAll;
  216. SetMenuCheckCmd(hWnd,
  217. MenuOtherPosition,
  218. wmId,
  219. draw->redrawAll);
  220. // force redraw of all stacked shapes
  221. InvalidateRect(hWnd, NULL, TRUE);
  222. UpdateWindow(hWnd);
  223. break;
  224. case IDM_KEEPCONTROLPOINTS:
  225. draw->keepControlPoints = !draw->keepControlPoints;
  226. SetMenuCheckCmd(hWnd,
  227. MenuOtherPosition,
  228. wmId,
  229. draw->keepControlPoints);
  230. // force redraw of all stacked shapes
  231. InvalidateRect(hWnd, NULL, TRUE);
  232. UpdateWindow(hWnd);
  233. break;
  234. case IDM_ANTIALIASED:
  235. draw->antiAlias = !draw->antiAlias;
  236. SetMenuCheckCmd(hWnd,
  237. MenuOtherPosition,
  238. wmId,
  239. draw->keepControlPoints);
  240. // force redraw of all stacked shapes
  241. InvalidateRect(hWnd, NULL, TRUE);
  242. UpdateWindow(hWnd);
  243. break;
  244. case IDM_USECLIP:
  245. draw->useClip = !draw->useClip;
  246. SetMenuCheckCmd(hWnd,
  247. MenuOtherPosition,
  248. wmId,
  249. draw->useClip);
  250. // force redraw of all stacked shapes
  251. InvalidateRect(hWnd, NULL, TRUE);
  252. UpdateWindow(hWnd);
  253. break;
  254. case IDM_WORLD_TRANSFORM:
  255. {
  256. Matrix *matrix = draw->GetWorldMatrix()->Clone();
  257. TestTransform transDlg;
  258. transDlg.Initialize(&matrix);
  259. transDlg.ChangeSettings(hWnd);
  260. draw->SetWorldMatrix(matrix);
  261. delete matrix;
  262. break;
  263. }
  264. case IDM_SETCLIP:
  265. draw->SetClipRegion(hWnd);
  266. break;
  267. case IDM_SAVEFILE:
  268. draw->SaveAsFile(hWnd);
  269. break;
  270. case IDM_DELETE:
  271. draw->RemovePoint(hWnd);
  272. InvalidateRect(hWnd, NULL, TRUE);
  273. UpdateWindow(hWnd);
  274. break;
  275. case IDM_RESET:
  276. graddraw->Reset(hWnd);
  277. break;
  278. case IDM_INSTRUCTIONS:
  279. graddraw->Instructions(hWnd);
  280. break;
  281. case IDM_CANCEL:
  282. DestroyWindow(hWnd);
  283. PostQuitMessage(FALSE);
  284. break;
  285. case IDM_DONE:
  286. DestroyWindow(hWnd);
  287. PostQuitMessage(TRUE);
  288. break;
  289. // Exit Test App
  290. case IDM_EXIT:
  291. DestroyWindow(hWnd);
  292. break;
  293. default:
  294. return DefWindowProc(hWnd, message, wParam, lParam);
  295. }
  296. break;
  297. }
  298. case WM_LBUTTONUP:
  299. {
  300. Point pt(LOWORD(lParam),
  301. HIWORD(lParam));
  302. TestDrawInterface* drawInt =
  303. (TestDrawInterface*)GetWindowLong(hWnd, GWL_USERDATA);
  304. drawInt->AddPoint(hWnd, pt);
  305. InvalidateRect(hWnd, NULL, TRUE);
  306. UpdateWindow(hWnd);
  307. }
  308. break;
  309. case WM_MBUTTONUP:
  310. {
  311. Point pt(LOWORD(lParam),
  312. HIWORD(lParam));
  313. TestDrawInterface* drawInt =
  314. (TestDrawInterface*)GetWindowLong(hWnd, GWL_USERDATA);
  315. drawInt->EndPoint(hWnd, pt);
  316. InvalidateRect(hWnd, NULL, TRUE);
  317. UpdateWindow(hWnd);
  318. }
  319. break;
  320. case WM_RBUTTONDOWN:
  321. {
  322. Point pt(LOWORD(lParam),
  323. HIWORD(lParam));
  324. TestDrawInterface* drawInt =
  325. (TestDrawInterface*)GetWindowLong(hWnd, GWL_USERDATA);
  326. drawInt->RememberPoint(pt);
  327. }
  328. break;
  329. case WM_RBUTTONUP:
  330. {
  331. Point pt(LOWORD(lParam),
  332. HIWORD(lParam));
  333. TestDrawInterface* drawInt =
  334. (TestDrawInterface*)GetWindowLong(hWnd, GWL_USERDATA);
  335. drawInt->MoveControlPoint(pt);
  336. InvalidateRect(hWnd, NULL, TRUE);
  337. UpdateWindow(hWnd);
  338. }
  339. break;
  340. case WM_PAINT:
  341. {
  342. TestDrawInterface* drawInt =
  343. (TestDrawInterface*)GetWindowLong(hWnd, GWL_USERDATA);
  344. if (drawInt)
  345. drawInt->Draw(hWnd);
  346. }
  347. break;
  348. case WM_ENTERSIZEMOVE:
  349. {
  350. // reposition the status window
  351. TestDrawInterface* drawInt =
  352. (TestDrawInterface*)GetWindowLong(hWnd, GWL_USERDATA);
  353. if (drawInt)
  354. drawInt->UpdateStatus((HWND)-1);
  355. }
  356. break;
  357. case WM_SIZE:
  358. {
  359. // reposition the status window
  360. TestDrawInterface* drawInt =
  361. (TestDrawInterface*)GetWindowLong(hWnd, GWL_USERDATA);
  362. if (drawInt)
  363. drawInt->UpdateStatus(hWnd);
  364. }
  365. break;
  366. case WM_DESTROY:
  367. PostQuitMessage(0);
  368. break;
  369. default:
  370. return DefWindowProc(hWnd, message, wParam, lParam);
  371. }
  372. return 0;
  373. }