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.

372 lines
8.4 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 <gdiplus.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. /***************************************************************************\
  30. * lMainWindowProc(hwnd, message, wParam, lParam)
  31. *
  32. * Processes all messages for the main window.
  33. *
  34. * History:
  35. * 04-07-91 -by- KentD
  36. * Wrote it.
  37. \***************************************************************************/
  38. LONG_PTR
  39. lMainWindowProc(
  40. HWND hwnd,
  41. UINT message,
  42. WPARAM wParam,
  43. LPARAM lParam
  44. )
  45. {
  46. PAINTSTRUCT ps;
  47. switch (message)
  48. {
  49. case WM_CREATE:
  50. /* if (!InitializeEngine())
  51. {
  52. MessageBox(0, _T("Engine didn't initialize"), _T("Uh oh"), MB_OK);
  53. }
  54. */
  55. break;
  56. case WM_COMMAND:
  57. switch(LOWORD(wParam))
  58. {
  59. case MM_TEST:
  60. Test(hwnd);
  61. break;
  62. default:
  63. break;
  64. }
  65. break;
  66. case WM_DESTROY:
  67. // UninitializeEngine();
  68. DeleteObject(ghbrWhite);
  69. PostQuitMessage(0);
  70. return(DefWindowProc(hwnd, message, wParam, lParam));
  71. default:
  72. return(DefWindowProc(hwnd, message, wParam, lParam));
  73. }
  74. return(0);
  75. }
  76. /******************************Public*Routine******************************\
  77. * DebugWndProc
  78. *
  79. * List box is maintained here.
  80. *
  81. \**************************************************************************/
  82. LONG_PTR FAR PASCAL DebugWndProc(HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam)
  83. {
  84. RECT rcl;
  85. HDC hdc;
  86. LONG_PTR lRet = 0;
  87. // Process window message.
  88. switch (message)
  89. {
  90. case WM_SIZE:
  91. lRet = DefWindowProc(ghwndList, message, wParam, lParam);
  92. GetClientRect(ghwndMain, &rcl);
  93. MoveWindow(
  94. ghwndList,
  95. rcl.left, rcl.top,
  96. (rcl.right - rcl.left), (rcl.bottom - rcl.top),
  97. TRUE
  98. );
  99. UpdateWindow(ghwndList);
  100. break;
  101. case WM_DESTROY:
  102. PostQuitMessage(0);
  103. break;
  104. default:
  105. lRet = DefWindowProc(hwnd, message, wParam, lParam);
  106. break;
  107. }
  108. return lRet;
  109. }
  110. /******************************Public*Routine******************************\
  111. * LBprintf
  112. *
  113. * ListBox printf implementation.
  114. *
  115. * History:
  116. * 15-Dec-1994 -by- Gilman Wong [gilmanw]
  117. * Wrote it.
  118. \**************************************************************************/
  119. void LBprintf(PCH msg, ...)
  120. {
  121. if (ghwndList)
  122. {
  123. va_list ap;
  124. char buffer[256];
  125. va_start(ap, msg);
  126. vsprintf(buffer, msg, ap);
  127. SendMessage(ghwndList, LB_ADDSTRING, (WPARAM) 0, (LPARAM) buffer);
  128. SendMessage(ghwndList, WM_SETREDRAW, (WPARAM) TRUE, (LPARAM) 0);
  129. InvalidateRect(ghwndList, NULL, TRUE);
  130. UpdateWindow(ghwndList);
  131. va_end(ap);
  132. }
  133. }
  134. /******************************Public*Routine******************************\
  135. * LBreset
  136. *
  137. * Reset ListBox state (clear).
  138. *
  139. * History:
  140. * 15-Dec-1994 -by- Gilman Wong [gilmanw]
  141. * Wrote it.
  142. \**************************************************************************/
  143. void LBreset()
  144. {
  145. if (ghwndList)
  146. SendMessage(ghwndList, LB_RESETCONTENT, (WPARAM) FALSE, (LPARAM) 0);
  147. }
  148. /***************************************************************************\
  149. * bInitApp()
  150. *
  151. * Initializes app.
  152. *
  153. * History:
  154. * 04-07-91 -by- KentD
  155. * Wrote it.
  156. \***************************************************************************/
  157. BOOL bInitApp(BOOL debug)
  158. {
  159. WNDCLASS wc;
  160. ghbrWhite = CreateSolidBrush(RGB(0xFF,0xFF,0xFF));
  161. wc.style = 0;
  162. wc.lpfnWndProc = lMainWindowProc;
  163. wc.cbClsExtra = 0;
  164. wc.cbWndExtra = 0;
  165. wc.hInstance = ghInstance;
  166. wc.hIcon = LoadIcon(NULL, IDI_APPLICATION);
  167. wc.hCursor = LoadCursor(NULL, IDC_ARROW);
  168. wc.hbrBackground = ghbrWhite;
  169. wc.lpszMenuName = _T("MainMenu");
  170. wc.lpszClassName = _T("TestClass");
  171. if (!RegisterClass(&wc))
  172. {
  173. return(FALSE);
  174. }
  175. ghwndMain =
  176. CreateWindowEx(
  177. 0,
  178. _T("TestClass"),
  179. _T("Win32 Test"),
  180. WS_OVERLAPPED |
  181. WS_CAPTION |
  182. WS_BORDER |
  183. WS_THICKFRAME |
  184. WS_MAXIMIZEBOX |
  185. WS_MINIMIZEBOX |
  186. WS_CLIPCHILDREN |
  187. WS_VISIBLE |
  188. WS_SYSMENU,
  189. 80,
  190. 70,
  191. 500,
  192. 500,
  193. NULL,
  194. NULL,
  195. ghInstance,
  196. NULL);
  197. if (ghwndMain == NULL)
  198. {
  199. return(FALSE);
  200. }
  201. if (debug)
  202. {
  203. RECT rcl;
  204. memset(&wc, 0, sizeof(wc));
  205. wc.style = 0;
  206. wc.lpfnWndProc = DebugWndProc;
  207. wc.cbClsExtra = 0;
  208. wc.cbWndExtra = 0;
  209. wc.hInstance = ghInstance;
  210. wc.hIcon = LoadIcon(NULL, IDI_APPLICATION);
  211. wc.hCursor = LoadCursor(NULL, IDC_ARROW);
  212. wc.hbrBackground = ghbrWhite;
  213. wc.lpszClassName = "DebugWClass";
  214. RegisterClass(&wc);
  215. ghwndDebug = CreateWindow(
  216. "DebugWClass",
  217. "Debug output",
  218. WS_OVERLAPPEDWINDOW|WS_MAXIMIZE,
  219. 600,
  220. 70,
  221. 300,
  222. 500,
  223. NULL,
  224. NULL,
  225. ghInstance,
  226. NULL
  227. );
  228. if (ghwndDebug)
  229. {
  230. ShowWindow(ghwndDebug, SW_NORMAL);
  231. UpdateWindow(ghwndDebug);
  232. // Create the list box to fill the main window.
  233. GetClientRect(ghwndDebug, &rcl);
  234. ghwndList = CreateWindow(
  235. "LISTBOX",
  236. "Debug output",
  237. WS_CHILD | WS_VISIBLE | WS_VSCROLL
  238. | WS_HSCROLL | LBS_NOINTEGRALHEIGHT,
  239. rcl.left, rcl.top,
  240. (rcl.right - rcl.left), (rcl.bottom - rcl.top),
  241. ghwndDebug,
  242. NULL,
  243. ghInstance,
  244. NULL
  245. );
  246. if (ghwndList)
  247. {
  248. SendMessage(
  249. ghwndList,
  250. WM_SETFONT,
  251. (WPARAM) GetStockObject(ANSI_FIXED_FONT),
  252. (LPARAM) FALSE
  253. );
  254. LBreset();
  255. ShowWindow(ghwndList, SW_NORMAL);
  256. UpdateWindow(ghwndList);
  257. }
  258. }
  259. }
  260. SetFocus(ghwndMain);
  261. return(TRUE);
  262. }
  263. /***************************************************************************\
  264. * main(argc, argv[])
  265. *
  266. * Sets up the message loop.
  267. *
  268. * History:
  269. * 04-07-91 -by- KentD
  270. * Wrote it.
  271. \***************************************************************************/
  272. _cdecl
  273. main(
  274. INT argc,
  275. PCHAR argv[])
  276. {
  277. MSG msg;
  278. HACCEL haccel;
  279. CHAR* pSrc;
  280. CHAR* pDst;
  281. if (!gGdiplusInitHelper.IsValid())
  282. {
  283. return 0;
  284. }
  285. BOOL wantDebugWindow = FALSE;
  286. CoInitialize(NULL);
  287. // Parse arguments
  288. for (argc--, argv++ ; argc && '-' == **argv ; argc--, argv++ )
  289. {
  290. switch ( *(++(*argv)) )
  291. {
  292. case 'd':
  293. case 'D':
  294. wantDebugWindow = TRUE;
  295. break;
  296. }
  297. }
  298. ghInstance = GetModuleHandle(NULL);
  299. if (!bInitApp(wantDebugWindow))
  300. {
  301. return(0);
  302. }
  303. haccel = LoadAccelerators(ghInstance, MAKEINTRESOURCE(1));
  304. while (GetMessage(&msg, NULL, 0, 0))
  305. {
  306. if (!TranslateAccelerator(msg.hwnd, haccel, &msg))
  307. {
  308. TranslateMessage(&msg);
  309. DispatchMessage(&msg);
  310. }
  311. }
  312. CoUninitialize();
  313. return(1);
  314. }