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.

401 lines
9.6 KiB

  1. //
  2. // GDI+ test program
  3. //
  4. #include <stddef.h>
  5. #include <stdlib.h>
  6. #include <stdio.h>
  7. #include <math.h>
  8. #include <float.h>
  9. #include <windows.h>
  10. #include <objbase.h>
  11. #include <tchar.h>
  12. #include <Commctrl.h>
  13. #include "Gdiplus.h"
  14. // Use the given namespace
  15. using namespace Gdiplus;
  16. HINSTANCE appInstance; // handle to the application instance
  17. HWND hwndMain; // handle to application's main window
  18. HWND hStatusWnd; // Status window
  19. //
  20. // Display an error message dialog and quit
  21. //
  22. VOID Error(PCSTR fmt,...)
  23. {
  24. va_list arglist;
  25. va_start(arglist, fmt);
  26. vfprintf(stderr, fmt, arglist);
  27. va_end(arglist);
  28. exit(-1);
  29. }
  30. #define CHECKERROR(e) \
  31. { \
  32. if (!(e)) \
  33. { \
  34. Error("Error on line %d\n", __LINE__); \
  35. } \
  36. }
  37. //
  38. // Perform GDI+ tests
  39. //
  40. VOID DrawImages(Graphics *g)
  41. {
  42. RadialGradientBrush gradBrush2(
  43. RectF(0,0,200,200),
  44. Color(0,128,255),
  45. Color(200,20,97)
  46. );
  47. GraphicsPath aPath(FillModeWinding);
  48. aPath.AddRectangle(Rect(48,0,70,30));
  49. /*
  50. aPath.AddRectangle(Rect(0,80,20,50));
  51. aPath.AddBezier(
  52. PointF(20,20),
  53. PointF(60,30),
  54. PointF(80,80),
  55. PointF(30,100));
  56. */
  57. // Region aRegion(&aPath);
  58. GraphicsPath aPath2;
  59. Region aRegion3(&aPath2);
  60. Region aRegion4(&aPath2);
  61. Region aRegion5(&aPath2);
  62. Region aRegion6(&aPath2);
  63. g->FillPath(&gradBrush2,&aPath);
  64. // aPath2.AddArc(140,100,30,50,50,77);
  65. // aPath2.AddPie(100,200,76,20,0,200);
  66. // Region aRegion2(&aPath2);
  67. // aPath2.AddLine(100,100,130,130);
  68. // aPath2.AddLine(130,130,200,225);
  69. // aPath2.AddRectangle(Rect(350,300,60,70));
  70. // aPath2.AddBezier(200,225,230,250,270,200,290,300);
  71. /*
  72. SolidBrush aBrush(Color (255,0,0));
  73. SolidBrush aBrush2(Color(20,40,250));
  74. SolidBrush aBrush3(Color(20,200,30));
  75. SolidBrush aBrush4(Color(140,200,250));
  76. SolidBrush aBrushA(Color(150,200,50,130));
  77. SolidBrush aBrushA2(Color(80,15,150,4));
  78. Bitmap bitmap(L"c:\\frisbee.bmp");
  79. TextureBrush aBrushBitmap(&bitmap);
  80. HatchBrush aHatchBrush(
  81. HatchStyleDiagonalCross,
  82. Color(0,255,0),
  83. Color(0,0,255));
  84. HatchBrush aHatchBrushT(
  85. HatchStyleDiagonalCross,
  86. Color(0,255,0),
  87. Color(0,0,0,0));
  88. RadialGradientBrush gradBrush(
  89. RectF(0,0,50,50),
  90. Color(255,0,255),
  91. Color(0,0,255)
  92. );
  93. RadialGradientBrush gradBrush2(
  94. RectF(0,0,200,200),
  95. Color(0,128,255),
  96. Color(200,20,97)
  97. );
  98. RadialGradientBrush gradBrushA(
  99. RectF(0,0,200,200),
  100. Color(80,0,0,255),
  101. Color(170,0,255,0)
  102. );
  103. RadialGradientBrush gradBrushHuge(
  104. RectF(0,0,400,400),
  105. Color(80,0,0,255),
  106. Color(170,0,255,0)
  107. );
  108. Color colors[4] = {
  109. Color(0,0,0),
  110. Color(255,0,0),
  111. Color(0,255,0),
  112. Color(0,0,255)
  113. };
  114. RectangleGradientBrush gradBrushRect(
  115. RectF(0,0,500,500),
  116. colors,
  117. WrapModeTile
  118. );
  119. Pen aPen(Color(40,80,160),3,UnitWorld);
  120. Pen aPen2(&gradBrushRect,8,UnitWorld);
  121. Pen aPen3(Color(0,0,0),0,UnitWorld);
  122. Pen aPen4(Color(0,0,0),15,UnitWorld);
  123. // aPen4.SetDashStyle(DashStyleDash);
  124. aPen4.SetLineCap(LineCapRound,LineCapRound,LineCapRound);
  125. GraphicsPath aPath(FillModeWinding);
  126. aPath.AddRectangle(Rect(48,0,70,30));
  127. aPath.AddRectangle(Rect(0,80,20,50));
  128. aPath.AddBezier(
  129. PointF(20,20),
  130. PointF(60,30),
  131. PointF(80,80),
  132. PointF(30,100));
  133. Region aRegion(&aPath);
  134. GraphicsPath aPath2;
  135. aPath2.AddArc(140,100,30,50,50,77);
  136. aPath2.AddPie(100,200,76,20,0,200);
  137. Region aRegion2(&aPath2);
  138. aPath2.AddLine(100,100,130,130);
  139. aPath2.AddLine(130,130,200,225);
  140. aPath2.AddRectangle(Rect(350,300,60,70));
  141. aPath2.AddBezier(200,225,230,250,270,200,290,300);
  142. Region aRegion3(&aPath2);
  143. Region aRegion4(&aPath2);
  144. aRegion4.Or(&aRegion);
  145. */
  146. // g->DrawPath(&aPen,&aPath);
  147. // g->FillPath(&gradBrush2,&aPath);
  148. // g->FillPath(&aBrush2,&aPath);
  149. /*
  150. g->FillEllipse(&gradBrushA,20,40,150,130);
  151. */
  152. /*
  153. g->FillRectangle(&gradBrushA,48,0,70,30);
  154. g->FillPath(&gradBrush2,&aPath);
  155. g->FillRectangle(&gradBrush,0,50,50,50);
  156. g->FillRectangle(&gradBrush,90,90,30,30);
  157. g->TranslateWorldTransform(50,50);
  158. g->FillRectangle(&gradBrushA,0,130,20,20);
  159. */
  160. /*
  161. g->FillRectangle(&aBrushBitmap,0,0,400,400);
  162. g->FillRegion(&aBrush2,&aRegion4);
  163. g->TranslateWorldTransform(100,100);
  164. g->FillPath(&gradBrushRect,&aPath2);
  165. */
  166. //////////// Final Test Case ///////////////
  167. /*
  168. g->FillRectangle(&gradBrushHuge,0,0,400,400);
  169. g->FillRectangle(&aBrushA2,0,81,30,20);
  170. g->FillRectangle(&aBrushA2,81,0,20,30);
  171. g->FillRectangle(&aBrushA,0,0,100,100);
  172. g->FillRectangle(&aBrushA,110,110,5,5);
  173. g->TranslateWorldTransform(50,50);
  174. g->FillPath(&gradBrush2,&aPath);
  175. */
  176. //////////// Solid Test Case ///////////////
  177. /*
  178. g->FillRectangle(&aBrush3,0,0,400,400);
  179. g->FillRectangle(&aBrush2,0,81,30,20);
  180. g->FillRectangle(&aBrush2,81,0,20,30);
  181. g->FillRectangle(&aBrush,0,0,100,100);
  182. g->FillRectangle(&aBrush,110,110,5,5);
  183. */
  184. /*
  185. g->TranslateWorldTransform(40,40);
  186. g->FillPath(&aBrush,&aPath);
  187. g->FillPath(&aBrush2,&aPath2);
  188. g->DrawPath(&aPen2,&aPath2);
  189. g->TranslateWorldTransform(110,35);
  190. g->FillPath(&aBrush3,&aPath);
  191. g->DrawPath(&aPen,&aPath);
  192. g->DrawEllipse(&aPen3,100,20,90,50);
  193. g->DrawRectangle(&aPen4,10,200,90,30);
  194. g->DrawBezier(&aPen4,10,300,80,360,180,350,250,280);
  195. */
  196. }
  197. VOID RecordMetafile(HWND hwnd)
  198. {
  199. HDC aDC = GetDC(hwnd);
  200. Metafile * recording = new Metafile(L"c:\\TestEmfP.Emf",
  201. aDC, NULL, PageUnitInch, NULL);
  202. Graphics * gMeta = Graphics::GetFromImage(recording);
  203. DrawImages(gMeta);
  204. delete gMeta;
  205. delete recording;
  206. ReleaseDC(hwnd,aDC);
  207. }
  208. VOID DoTest(HWND hwnd,HDC hdc)
  209. {
  210. Graphics * gScreen = Graphics::GetFromHwnd(hwnd);
  211. DrawImages(gScreen);
  212. /*
  213. Metafile * playback = new Metafile(L"c:\\TestEmfP.Emf");
  214. GpRectF playbackRect;
  215. gScreen->GetVisibleClipBounds(playbackRect);
  216. playbackRect.Width -= 10;
  217. playbackRect.Height -= 10;
  218. gScreen->DrawImage(playback, playbackRect);
  219. delete playback;
  220. */
  221. delete gScreen;
  222. }
  223. //
  224. // Window callback procedure
  225. //
  226. LRESULT CALLBACK
  227. MainWndProc(HWND hwnd,UINT uMsg,WPARAM wParam,LPARAM lParam)
  228. {
  229. static BOOL once = FALSE;
  230. switch (uMsg)
  231. {
  232. case WM_ACTIVATE:
  233. if (!once)
  234. {
  235. once = TRUE;
  236. RecordMetafile(hwnd);
  237. }
  238. break;
  239. case WM_PAINT:
  240. {
  241. HDC hdc;
  242. PAINTSTRUCT ps;
  243. ps.fErase = TRUE;
  244. hdc = BeginPaint(hwnd, &ps);
  245. DoTest(hwnd, hdc);
  246. EndPaint(hwnd, &ps);
  247. }
  248. break;
  249. case WM_DESTROY:
  250. PostQuitMessage(0);
  251. break;
  252. default:
  253. return DefWindowProc(hwnd, uMsg, wParam, lParam);
  254. }
  255. return 0;
  256. }
  257. /***************************************************************************\
  258. * bInitApp()
  259. *
  260. * Initializes app.
  261. *
  262. * History:
  263. * 04-07-91 -by- KentD
  264. * Wrote it.
  265. \***************************************************************************/
  266. BOOL bInitApp(VOID)
  267. {
  268. WNDCLASS wc;
  269. _TCHAR classname[] = _T("PseudoTestClass");
  270. appInstance = GetModuleHandle(NULL);
  271. wc.style = CS_HREDRAW | CS_VREDRAW;
  272. wc.lpfnWndProc = MainWndProc;
  273. wc.cbClsExtra = 0;
  274. wc.cbWndExtra = 0;
  275. wc.hInstance = appInstance;
  276. wc.hIcon = LoadIcon(NULL, IDI_APPLICATION);
  277. wc.hCursor = LoadCursor(NULL, IDC_ARROW);
  278. wc.hbrBackground = (HBRUSH) GetStockObject(WHITE_BRUSH);
  279. wc.lpszMenuName = NULL;
  280. wc.lpszClassName = classname;
  281. if (!RegisterClass(&wc))
  282. {
  283. return(FALSE);
  284. }
  285. hwndMain =
  286. CreateWindowEx(
  287. 0,
  288. classname,
  289. _T("PseudoDriver Functionality Test"),
  290. WS_OVERLAPPED |
  291. WS_CAPTION |
  292. WS_BORDER |
  293. WS_THICKFRAME |
  294. WS_MAXIMIZEBOX |
  295. WS_MINIMIZEBOX |
  296. WS_CLIPCHILDREN |
  297. WS_MAXIMIZE |
  298. WS_SYSMENU,
  299. 80,
  300. 70,
  301. 512,
  302. 512,
  303. NULL,
  304. NULL,
  305. appInstance,
  306. NULL);
  307. if (hwndMain == NULL)
  308. {
  309. return(FALSE);
  310. }
  311. /*
  312. hStatusWnd = CreateStatusWindow(WS_CHILD | WS_VISIBLE,
  313. _T("Functionality Test App"),
  314. hwndMain,
  315. -1);
  316. */
  317. return(TRUE);
  318. }
  319. /***************************************************************************\
  320. * main(argc, argv[])
  321. *
  322. * Sets up the message loop.
  323. *
  324. * History:
  325. * 04-07-91 -by- KentD
  326. * Wrote it.
  327. \***************************************************************************/
  328. _cdecl
  329. main(
  330. INT argc,
  331. PCHAR argv[])
  332. {
  333. MSG msg;
  334. HACCEL haccel;
  335. CHAR* pSrc;
  336. CHAR* pDst;
  337. if (!bInitApp())
  338. {
  339. return(0);
  340. }
  341. ShowWindow(hwndMain,SW_RESTORE);
  342. haccel = LoadAccelerators(appInstance, MAKEINTRESOURCE(1));
  343. while (GetMessage(&msg, NULL, 0, 0))
  344. {
  345. if (!TranslateAccelerator(msg.hwnd, haccel, &msg))
  346. {
  347. TranslateMessage(&msg);
  348. DispatchMessage(&msg);
  349. }
  350. }
  351. return(1);
  352. }