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.

395 lines
8.1 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 "Gdiplus.h"
  12. // Use the given namespace
  13. using namespace Gdiplus;
  14. CHAR* programName; // program name
  15. HINSTANCE appInstance; // handle to the application instance
  16. HWND hwndMain; // handle to application's main window
  17. INT argCount; // command line argument count
  18. CHAR** argArray; // command line arguments
  19. //
  20. // Display an error message dialog and quit
  21. //
  22. VOID
  23. Error(
  24. PCSTR fmt,
  25. ...
  26. )
  27. {
  28. va_list arglist;
  29. va_start(arglist, fmt);
  30. vfprintf(stderr, fmt, arglist);
  31. va_end(arglist);
  32. exit(-1);
  33. }
  34. #define CHECKERROR(e) \
  35. { \
  36. if (!(e)) \
  37. { \
  38. Error("Error on line %d\n", __LINE__); \
  39. } \
  40. }
  41. //
  42. // Perform GDI+ tests
  43. //
  44. VOID
  45. DoTest(
  46. HWND hwnd,
  47. HDC hdc
  48. )
  49. {
  50. {
  51. Graphics *g = Graphics::GetFromHwnd(hwnd);
  52. Rect rect(0, 0, 120, 100);
  53. Region *region = new Region(rect);
  54. g->SetClip(region);
  55. delete region;
  56. delete g;
  57. }
  58. {
  59. Graphics* g = Graphics::GetFromHwnd(hwnd);
  60. // Scale everything up by 1.5
  61. g->SetPageTransform(PageUnitDisplay, 1.5);
  62. Color red(255, 0, 0);
  63. SolidBrush redBrush(red);
  64. g->FillRectangle(&redBrush, 20, 20, 50, 50);
  65. Color alphacolor(128, 0, 255, 0);
  66. SolidBrush alphaBrush(alphacolor);
  67. g->FillRectangle(&alphaBrush, 10, 10, 40, 40);
  68. Point points[10];
  69. points[0].X = 50;
  70. points[0].Y = 50;
  71. points[1].X = 100;
  72. points[1].Y = 50;
  73. points[2].X = 120;
  74. points[2].Y = 120;
  75. points[3].X = 50;
  76. points[3].Y = 100;
  77. Color blue(128, 0, 0, 255);
  78. SolidBrush blueBrush(blue);
  79. g->FillPolygon(&blueBrush, (Point*)&points[0], 4);
  80. // Currently only Geometric pen works for lines. - ikkof 1/6/99.
  81. REAL width = 4;
  82. Color black(0,0,0);
  83. SolidBrush blackBrush(black);
  84. Pen blackPen(&blackBrush, width);
  85. g->DrawPolygon(&blackPen, (Point*)&points[0], 4);
  86. // g->DrawLines(&blackPen, points, 4, FALSE);
  87. points[0].X = 100;
  88. points[0].Y = 10;
  89. points[1].X = -50;
  90. points[1].Y = 50;
  91. points[2].X = 150;
  92. points[2].Y = 200;
  93. points[3].X = 200;
  94. points[3].Y = 70;
  95. Color yellow(128, 255, 255, 0);
  96. SolidBrush yellowBrush(yellow);
  97. GraphicsPath* path = new GraphicsPath(FillModeAlternate);
  98. path->AddBeziers((Point*)&points[0], 4);
  99. Region * region = new Region(path);
  100. g->FillRegion(&yellowBrush, region);
  101. // g->FillPath(&yellowBrush, path);
  102. g->DrawPath(&blackPen, path);
  103. delete path;
  104. delete region;
  105. // Create a rectangular gradient brush.
  106. RectF brushRect(0, 0, 32, 32);
  107. Color* colors[4];
  108. colors[0] = new Color(255, 255, 255, 255);
  109. colors[1] = new Color(255, 255, 0, 0);
  110. colors[2] = new Color(255, 0, 255, 0);
  111. colors[3] = new Color(255, 0, 0, 255);
  112. RectangleGradientBrush rectGrad(brushRect, (Color*)&colors[0], WrapModeTile);
  113. delete colors[0];
  114. delete colors[1];
  115. delete colors[2];
  116. delete colors[3];
  117. g->FillRectangle(&rectGrad, 200, 20, 100, 80);
  118. // Change the wrapping mode and fill.
  119. rectGrad.SetWrapMode(WrapModeTileFlipXY);
  120. g->FillRectangle(&rectGrad, 350, 20, 100, 80);
  121. g->DrawRectangle(&blackPen, brushRect);
  122. // Create a radial gradient brush.
  123. Color centerColor(255, 255, 255, 255);
  124. Color boundaryColor(255, 0, 0, 0);
  125. brushRect.X = 380;
  126. brushRect.Y = 130;
  127. RadialGradientBrush radGrad(brushRect, centerColor,
  128. boundaryColor, WrapModeClamp);
  129. g->FillRectangle(&radGrad, 320, 120, 120, 100);
  130. // Load bmp files.
  131. WCHAR *filename = L"winnt256.bmp";
  132. Bitmap *bitmap = new Bitmap(filename);
  133. // Create a texture brush.
  134. /*
  135. Rect copyRect;
  136. copyRect.X = 60;
  137. copyRect.Y = 60;
  138. copyRect.Width = 80;
  139. copyRect.Height = 60;
  140. Bitmap *copiedBitmap = bitmap->CopyArea(&copyRect, Bm32bppARGB);
  141. if(copiedBitmap)
  142. {
  143. // Create a texture brush.
  144. Texture textureBrush = Texture(copiedBitmap, WrapModeTile);
  145. copiedBitmap->Dispose();
  146. // Create a radial gradient pen.
  147. GeometricPen gradPen(width, &rectGrad);
  148. points[0].X = 50;
  149. points[0].Y = 300;
  150. points[1].X = 100;
  151. points[1].Y = 300;
  152. points[2].X = 120;
  153. points[2].Y = 370;
  154. points[3].X = 50;
  155. points[3].Y = 350;
  156. g->FillPolygon(&textureBrush, (Point*)&points[0], 4);
  157. g->DrawPolygon(&gradPen, (Point*)&points[0], 4);
  158. points[0].X = 100;
  159. points[0].Y = 160;
  160. points[1].X = -50;
  161. points[1].Y = 160;
  162. points[2].X = 150;
  163. points[2].Y = 350;
  164. points[3].X = 200;
  165. points[3].Y = 220;
  166. path = new Path(FillModeAlternate);
  167. path->AddBeziers((Point*)&points[0], 4);
  168. g->FillPath(&textureBrush, path);
  169. // g->FillPath(&rectGrad, path);
  170. g->DrawPath(&gradPen, path);
  171. delete path;
  172. }
  173. Rectangle destRect(220, 300, 180, 120);
  174. Rectangle srcRect;
  175. srcRect.X = 20;
  176. srcRect.Y = 20;
  177. srcRect.Width = 180;
  178. srcRect.Height = 180;
  179. g->DrawImage(bitmap, &destRect);
  180. // g->DrawImage(bitmap, destRect, srcRect);
  181. bitmap->Dispose();
  182. /
  183. // TestPath2(g);
  184. // TestPrimitives(g);
  185. delete g;
  186. // TODO: Mem leaks on other allocated memory.
  187. /*
  188. {
  189. GeometricPen *pen =
  190. new GeometricPen((REAL)1.0, (Gdiplus::Brush*)0);
  191. Rectangle rectf;
  192. Point pointf(1.0, 2.0);
  193. }
  194. {
  195. Gdiplus::GeometricPen *pen =
  196. new Gdiplus::GeometricPen((REAL)1.0, (Gdiplus::Brush*)0);
  197. Gdiplus::Rectangle rectf;
  198. Gdiplus::Point pointf(1.0, 2.0);
  199. }
  200. */
  201. }
  202. }
  203. //
  204. // Window callback procedure
  205. //
  206. LRESULT CALLBACK
  207. MyWindowProc(
  208. HWND hwnd,
  209. UINT uMsg,
  210. WPARAM wParam,
  211. LPARAM lParam
  212. )
  213. {
  214. switch (uMsg)
  215. {
  216. case WM_PAINT:
  217. {
  218. HDC hdc;
  219. PAINTSTRUCT ps;
  220. hdc = BeginPaint(hwnd, &ps);
  221. DoTest(hwnd, hdc);
  222. EndPaint(hwnd, &ps);
  223. }
  224. break;
  225. case WM_DESTROY:
  226. PostQuitMessage(0);
  227. break;
  228. default:
  229. return DefWindowProc(hwnd, uMsg, wParam, lParam);
  230. }
  231. return 0;
  232. }
  233. //
  234. // Create main application window
  235. //
  236. VOID
  237. CreateMainWindow(
  238. VOID
  239. )
  240. #define MYWNDCLASSNAME TEXT("GdiplusDllTest")
  241. {
  242. //
  243. // Register window class if necessary
  244. //
  245. static BOOL wndclassRegistered = FALSE;
  246. if (!wndclassRegistered)
  247. {
  248. WNDCLASS wndClass =
  249. {
  250. CS_HREDRAW|CS_VREDRAW,
  251. MyWindowProc,
  252. 0,
  253. 0,
  254. appInstance,
  255. NULL,
  256. LoadCursor(NULL, IDC_ARROW),
  257. (HBRUSH) (COLOR_WINDOW+1),
  258. NULL,
  259. MYWNDCLASSNAME
  260. };
  261. RegisterClass(&wndClass);
  262. wndclassRegistered = TRUE;
  263. }
  264. hwndMain = CreateWindow(
  265. MYWNDCLASSNAME,
  266. MYWNDCLASSNAME,
  267. WS_OVERLAPPEDWINDOW | WS_VISIBLE,
  268. CW_USEDEFAULT,
  269. CW_USEDEFAULT,
  270. CW_USEDEFAULT,
  271. CW_USEDEFAULT,
  272. NULL,
  273. NULL,
  274. appInstance,
  275. NULL);
  276. }
  277. //
  278. // Main program entrypoint
  279. //
  280. INT _cdecl
  281. main(
  282. INT argc,
  283. CHAR **argv
  284. )
  285. {
  286. programName = *argv++;
  287. argc--;
  288. appInstance = GetModuleHandle(NULL);
  289. argCount = argc;
  290. argArray = argv;
  291. //
  292. // Create the main application window
  293. //
  294. CreateMainWindow();
  295. //
  296. // Main message loop
  297. //
  298. MSG msg;
  299. while (GetMessage(&msg, NULL, 0, 0))
  300. {
  301. TranslateMessage(&msg);
  302. DispatchMessage(&msg);
  303. }
  304. return msg.wParam;
  305. }