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.

445 lines
11 KiB

  1. /******************************Module*Header*******************************\
  2. * Module Name: wndstuff.cpp
  3. *
  4. * Menu driven test environment.
  5. *
  6. * Created: 23 December 1999
  7. * Author: Adrian Secchia [asecchia]
  8. *
  9. * Copyright (c) 1999 Microsoft Corporation
  10. *
  11. \**************************************************************************/
  12. // for Win95 compile
  13. #undef UNICODE
  14. #undef _UNICODE
  15. #include <windows.h>
  16. #include <tchar.h>
  17. #include <stdio.h>
  18. #include <stdlib.h>
  19. #include <objbase.h>
  20. #include "wndstuff.h"
  21. HINSTANCE ghInstance;
  22. HWND ghwndMain;
  23. HBRUSH ghbrWhite;
  24. WCHAR FileName[MAX_PATH]=L"winnt256.bmp";
  25. #include <gdiplus.h>
  26. #include "../gpinit.inc"
  27. // Store the user requested state for the DrawImage test.
  28. UINT uCategory;
  29. UINT uResample;
  30. UINT uRotation;
  31. UINT uICM;
  32. UINT uICMBack;
  33. BOOL bPixelMode = FALSE;
  34. UINT uWrapMode = 0;
  35. ULONG _cdecl
  36. DbgPrint(
  37. CHAR* format,
  38. ...
  39. )
  40. {
  41. va_list arglist;
  42. va_start(arglist, format);
  43. char buf[1024];
  44. _vsnprintf(buf, 1024, format, arglist);
  45. buf[1024-1]=0;
  46. OutputDebugStringA(buf);
  47. va_end(arglist);
  48. return 0;
  49. }
  50. /***************************************************************************\
  51. * SetXXXX
  52. *
  53. * These routines set the state for the test. When the user selects
  54. * an option from the menu, we store the state and mark the selection
  55. * in the menu text.
  56. * The DoTest routine queries the global variables (above) to determine
  57. * which test to run and set the environment for the test.
  58. \***************************************************************************/
  59. VOID SetCategory(HWND hwnd, UINT uNewCategory)
  60. {
  61. HMENU hmenu = GetMenu(hwnd);
  62. HMENU hmenu2 = GetSubMenu(hmenu, 2);
  63. CheckMenuItem(hmenu2, uCategory, MF_BYCOMMAND | MF_UNCHECKED);
  64. CheckMenuItem(hmenu2, uNewCategory, MF_BYCOMMAND | MF_CHECKED);
  65. uCategory = uNewCategory;
  66. }
  67. VOID SetResample(HWND hwnd, UINT uNewResample)
  68. {
  69. HMENU hmenu = GetMenu(hwnd);
  70. HMENU hmenu2 = GetSubMenu(hmenu, 3);
  71. CheckMenuItem(hmenu2, uResample, MF_BYCOMMAND | MF_UNCHECKED);
  72. CheckMenuItem(hmenu2, uNewResample, MF_BYCOMMAND | MF_CHECKED);
  73. uResample = uNewResample;
  74. }
  75. VOID SetICM(HWND hwnd, UINT uNewICM)
  76. {
  77. HMENU hmenu = GetMenu(hwnd);
  78. HMENU hmenu2 = GetSubMenu(hmenu, 5);
  79. CheckMenuItem(hmenu2, uICM, MF_BYCOMMAND | MF_UNCHECKED);
  80. CheckMenuItem(hmenu2, uNewICM, MF_BYCOMMAND | MF_CHECKED);
  81. uICM = uNewICM;
  82. }
  83. VOID SetICMBack(HWND hwnd, UINT uNewICM)
  84. {
  85. HMENU hmenu = GetMenu(hwnd);
  86. HMENU hmenu2 = GetSubMenu(hmenu, 5);
  87. CheckMenuItem(hmenu2, uICMBack, MF_BYCOMMAND | MF_UNCHECKED);
  88. CheckMenuItem(hmenu2, uNewICM, MF_BYCOMMAND | MF_CHECKED);
  89. uICMBack = uNewICM;
  90. }
  91. VOID SetRotation(HWND hwnd, UINT uNewRotation)
  92. {
  93. HMENU hmenu = GetMenu(hwnd);
  94. HMENU hmenu2 = GetSubMenu(hmenu, 6);
  95. CheckMenuItem(hmenu2, uRotation, MF_BYCOMMAND | MF_UNCHECKED);
  96. CheckMenuItem(hmenu2, uNewRotation, MF_BYCOMMAND | MF_CHECKED);
  97. uRotation = uNewRotation;
  98. }
  99. VOID SetPixelOffsetMode(HWND hwnd, UINT uPixelMode)
  100. {
  101. HMENU hmenu = GetMenu(hwnd);
  102. HMENU hmenu2 = GetSubMenu(hmenu, 4);
  103. bPixelMode = !bPixelMode;
  104. CheckMenuItem(hmenu2, uPixelMode, MF_BYCOMMAND | (bPixelMode?MF_CHECKED:MF_UNCHECKED));
  105. }
  106. VOID SetWrapMode(HWND hwnd, UINT uNewWrapMode)
  107. {
  108. HMENU hmenu = GetMenu(hwnd);
  109. HMENU hmenu2 = GetSubMenu(hmenu, 4);
  110. CheckMenuItem(hmenu2, uNewWrapMode, MF_BYCOMMAND | MF_CHECKED);
  111. CheckMenuItem(hmenu2, uWrapMode, MF_BYCOMMAND | MF_UNCHECKED);
  112. uWrapMode = uNewWrapMode;
  113. }
  114. inline BOOL
  115. AnsiToUnicodeStr(
  116. const CHAR* ansiStr,
  117. WCHAR* unicodeStr,
  118. INT unicodeSize
  119. )
  120. {
  121. return MultiByteToWideChar(CP_ACP,
  122. 0,
  123. ansiStr,
  124. -1,
  125. unicodeStr,
  126. unicodeSize) > 0;
  127. }
  128. void OpenFileProc(HWND hwnd)
  129. {
  130. char locFileName[MAX_PATH];
  131. OPENFILENAME ofn;
  132. ZeroMemory(&ofn, sizeof(ofn));
  133. ofn.lStructSize = sizeof(ofn);
  134. ofn.hwndOwner = hwnd;
  135. ofn.hInstance = ghInstance;
  136. ofn.lpstrFile = locFileName;
  137. ofn.nMaxFile = MAX_PATH;
  138. ofn.lpstrTitle = "Open Image";
  139. ofn.lpstrInitialDir = ".";
  140. ofn.Flags = OFN_FILEMUSTEXIST;
  141. locFileName[0] = '\0';
  142. // Present the file/open dialog
  143. if(GetOpenFileName(&ofn))
  144. {
  145. AnsiToUnicodeStr(locFileName, FileName, MAX_PATH);
  146. }
  147. }
  148. /***************************************************************************\
  149. * lMainWindowProc(hwnd, message, wParam, lParam)
  150. *
  151. * Processes all messages for the main window.
  152. \***************************************************************************/
  153. LONG_PTR
  154. lMainWindowProc(
  155. HWND hwnd,
  156. UINT message,
  157. WPARAM wParam,
  158. LPARAM lParam
  159. )
  160. {
  161. PAINTSTRUCT ps;
  162. switch (message)
  163. {
  164. case WM_DEVMODECHANGE:
  165. DbgPrint("Devmode change\n");
  166. break;
  167. case WM_DEVICECHANGE:
  168. DbgPrint("Device change\n");
  169. break;
  170. case WM_DISPLAYCHANGE:
  171. DbgPrint("Display change\n");
  172. break;
  173. case WM_CREATE:
  174. break;
  175. case WM_SIZE:
  176. InvalidateRect(hwnd, NULL, FALSE);
  177. break;
  178. case WM_PAINT:
  179. BeginPaint(hwnd, &ps);
  180. DoTest(hwnd);
  181. EndPaint(hwnd, &ps);
  182. break;
  183. case WM_COMMAND:
  184. switch(LOWORD(wParam))
  185. {
  186. case IDM_OPENFILE:
  187. OpenFileProc(hwnd);
  188. InvalidateRect(hwnd, NULL, TRUE);
  189. break;
  190. case IDM_TEST:
  191. InvalidateRect(hwnd, NULL, TRUE);
  192. break;
  193. // Choose the test.
  194. case IDM_ALL:
  195. case IDM_OUTCROP:
  196. case IDM_OUTCROPR:
  197. case IDM_SIMPLE:
  198. case IDM_STRETCHROTATION:
  199. case IDM_SHRINKROTATION:
  200. case IDM_CROPROTATION:
  201. case IDM_COPYCROP:
  202. case IDM_DRAWICM:
  203. case IDM_DRAWPALETTE:
  204. case IDM_DRAWIMAGE2:
  205. case IDM_STRETCHB:
  206. case IDM_STRETCHS:
  207. case IDM_PIXELCENTER:
  208. case IDM_CACHEDBITMAP:
  209. case IDM_CROPWT:
  210. case IDM_HFLIP:
  211. case IDM_VFLIP:
  212. case IDM_SPECIALROTATE:
  213. SetCategory(hwnd, LOWORD(wParam));
  214. InvalidateRect(hwnd, NULL, TRUE);
  215. break;
  216. // Choose the world to device transformation
  217. case IDM_ROT0:
  218. case IDM_ROT10:
  219. case IDM_ROT30:
  220. case IDM_ROT45:
  221. case IDM_ROT60:
  222. case IDM_ROT90:
  223. SetRotation(hwnd, LOWORD(wParam));
  224. InvalidateRect(hwnd, NULL, TRUE);
  225. break;
  226. case IDM_ICM:
  227. case IDM_NOICM:
  228. SetICM(hwnd, LOWORD(wParam));
  229. InvalidateRect(hwnd, NULL, TRUE);
  230. break;
  231. case IDM_ICM_BACK:
  232. case IDM_ICM_NOBACK:
  233. SetICMBack(hwnd, LOWORD(wParam));
  234. InvalidateRect(hwnd, NULL, TRUE);
  235. break;
  236. // Choose the resample mode
  237. case IDM_BILINEAR:
  238. case IDM_BICUBIC:
  239. case IDM_NEARESTNEIGHBOR:
  240. case IDM_HIGHBILINEAR:
  241. case IDM_HIGHBICUBIC:
  242. SetResample(hwnd, LOWORD(wParam));
  243. InvalidateRect(hwnd, NULL, TRUE);
  244. break;
  245. // Set the PixelOffsetMode
  246. case IDM_PIXELMODE:
  247. SetPixelOffsetMode(hwnd, LOWORD(wParam));
  248. InvalidateRect(hwnd, NULL, TRUE);
  249. break;
  250. // Set the WrapMode
  251. case IDM_WRAPMODETILE:
  252. case IDM_WRAPMODEFLIPX:
  253. case IDM_WRAPMODEFLIPY:
  254. case IDM_WRAPMODEFLIPXY:
  255. case IDM_WRAPMODECLAMP0:
  256. case IDM_WRAPMODECLAMPFF:
  257. SetWrapMode(hwnd, LOWORD(wParam));
  258. InvalidateRect(hwnd, NULL, TRUE);
  259. break;
  260. case IDM_QUIT:
  261. exit(0);
  262. break;
  263. default:
  264. // The user selected an unimplemented menu item.
  265. MessageBox(hwnd,
  266. _T("Help me! - I've fallen and I can't get up!!!"),
  267. _T(""),
  268. MB_OK
  269. );
  270. break;
  271. }
  272. break;
  273. case WM_DESTROY:
  274. DeleteObject(ghbrWhite);
  275. PostQuitMessage(0);
  276. return(DefWindowProc(hwnd, message, wParam, lParam));
  277. default:
  278. return(DefWindowProc(hwnd, message, wParam, lParam));
  279. }
  280. return(0);
  281. }
  282. /***************************************************************************\
  283. * bInitApp()
  284. *
  285. * Initializes the app.
  286. \***************************************************************************/
  287. BOOL bInitApp(VOID)
  288. {
  289. WNDCLASS wc;
  290. // not quite so white background brush.
  291. ghbrWhite = CreateSolidBrush(RGB(0xFF,0xFF,0xFF));
  292. wc.style = 0;
  293. wc.lpfnWndProc = lMainWindowProc;
  294. wc.cbClsExtra = 0;
  295. wc.cbWndExtra = 0;
  296. wc.hInstance = ghInstance;
  297. wc.hIcon = LoadIcon(NULL, IDI_APPLICATION);
  298. wc.hCursor = LoadCursor(NULL, IDC_ARROW);
  299. wc.hbrBackground = ghbrWhite;
  300. wc.lpszMenuName = _T("MainMenu");
  301. wc.lpszClassName = _T("TestClass");
  302. if(!RegisterClass(&wc)) { return FALSE; }
  303. ghwndMain = CreateWindowEx(
  304. 0,
  305. _T("TestClass"),
  306. _T("Win32 Test"),
  307. WS_OVERLAPPED |
  308. WS_CAPTION |
  309. WS_BORDER |
  310. WS_THICKFRAME |
  311. WS_MAXIMIZEBOX |
  312. WS_MINIMIZEBOX |
  313. WS_CLIPCHILDREN |
  314. WS_VISIBLE |
  315. WS_SYSMENU,
  316. 80,
  317. 70,
  318. 500,
  319. 500,
  320. NULL,
  321. NULL,
  322. ghInstance,
  323. NULL
  324. );
  325. if (ghwndMain == NULL)
  326. {
  327. return(FALSE);
  328. }
  329. SetFocus(ghwndMain);
  330. return TRUE;
  331. }
  332. /***************************************************************************\
  333. * main(argc, argv[])
  334. *
  335. * Sets up the message loop.
  336. \***************************************************************************/
  337. _cdecl
  338. main(
  339. INT argc,
  340. PCHAR argv[])
  341. {
  342. MSG msg;
  343. HACCEL haccel;
  344. CHAR* pSrc;
  345. CHAR* pDst;
  346. if (!gGdiplusInitHelper.IsValid())
  347. {
  348. return 0;
  349. }
  350. ghInstance = GetModuleHandle(NULL);
  351. if(!bInitApp()) { return 0; }
  352. // Initialize the default menu selection.
  353. SetCategory(ghwndMain, IDM_DRAWICM);
  354. SetRotation(ghwndMain, IDM_ROT0);
  355. SetResample(ghwndMain, IDM_BICUBIC);
  356. SetICM(ghwndMain, IDM_NOICM);
  357. SetPixelOffsetMode(ghwndMain, IDM_PIXELMODE);
  358. SetICMBack(ghwndMain, IDM_ICM_NOBACK);
  359. SetWrapMode(ghwndMain, IDM_WRAPMODETILE);
  360. while(GetMessage (&msg, NULL, 0, 0))
  361. {
  362. if((ghwndMain == 0) || !IsDialogMessage(ghwndMain, &msg)) {
  363. TranslateMessage(&msg) ;
  364. DispatchMessage(&msg) ;
  365. }
  366. }
  367. return 1;
  368. }