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.

232 lines
4.9 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 "wndstuff.h"
  20. HINSTANCE ghInstance;
  21. HWND ghwndMain;
  22. HBRUSH ghbrWhite;
  23. AnsiToUnicodeStr(
  24. const CHAR* ansiStr,
  25. WCHAR* unicodeStr,
  26. INT unicodeSize
  27. )
  28. {
  29. return (
  30. MultiByteToWideChar(
  31. CP_ACP,
  32. 0,
  33. ansiStr,
  34. -1,
  35. unicodeStr,
  36. unicodeSize
  37. ) > 0
  38. );
  39. }
  40. void OpenFileProc(HWND hwnd)
  41. {
  42. char locFileName[MAX_PATH];
  43. OPENFILENAME ofn;
  44. ZeroMemory(&ofn, sizeof(ofn));
  45. ofn.lStructSize = sizeof(ofn);
  46. ofn.hwndOwner = hwnd;
  47. ofn.hInstance = ghInstance;
  48. ofn.lpstrFile = locFileName;
  49. ofn.nMaxFile = MAX_PATH;
  50. ofn.lpstrTitle = "Open Image";
  51. ofn.lpstrInitialDir = ".";
  52. ofn.Flags = OFN_FILEMUSTEXIST;
  53. locFileName[0] = '\0';
  54. // Present the file/open dialog
  55. if(GetOpenFileName(&ofn))
  56. {
  57. //AnsiToUnicodeStr(locFileName, FileName, MAX_PATH);
  58. }
  59. }
  60. /***************************************************************************\
  61. * lMainWindowProc(hwnd, message, wParam, lParam)
  62. *
  63. * Processes all messages for the main window.
  64. \***************************************************************************/
  65. LONG_PTR
  66. lMainWindowProc(
  67. HWND hwnd,
  68. UINT message,
  69. WPARAM wParam,
  70. LPARAM lParam
  71. )
  72. {
  73. PAINTSTRUCT ps;
  74. HDC hdc;
  75. switch (message)
  76. {
  77. case WM_CREATE:
  78. break;
  79. case WM_SIZE:
  80. InvalidateRect(hwnd, NULL, FALSE);
  81. break;
  82. case WM_PAINT:
  83. hdc = BeginPaint(hwnd, &ps);
  84. PaintWindow(hdc);
  85. ReleaseDC(hwnd, hdc);
  86. break;
  87. case WM_COMMAND:
  88. switch(LOWORD(wParam))
  89. {
  90. case IDM_OPENFILE:
  91. OpenFileProc(hwnd);
  92. InvalidateRect(hwnd, NULL, TRUE);
  93. break;
  94. case IDM_QUIT:
  95. exit(0);
  96. break;
  97. default:
  98. // The user selected an unimplemented menu item.
  99. MessageBox(hwnd,
  100. _T("This is an unimplemented feature."),
  101. _T(""),
  102. MB_OK
  103. );
  104. break;
  105. }
  106. break;
  107. case WM_DESTROY:
  108. DeleteObject(ghbrWhite);
  109. PostQuitMessage(0);
  110. return(DefWindowProc(hwnd, message, wParam, lParam));
  111. default:
  112. return(DefWindowProc(hwnd, message, wParam, lParam));
  113. }
  114. return(0);
  115. }
  116. /***************************************************************************\
  117. * bInitApp()
  118. *
  119. * Initializes the app.
  120. \***************************************************************************/
  121. BOOL bInitApp(VOID)
  122. {
  123. WNDCLASS wc;
  124. // not quite so white background brush.
  125. ghbrWhite = CreateSolidBrush(RGB(0xFF,0xFF,0xFF));
  126. wc.style = 0;
  127. wc.lpfnWndProc = lMainWindowProc;
  128. wc.cbClsExtra = 0;
  129. wc.cbWndExtra = 0;
  130. wc.hInstance = ghInstance;
  131. wc.hIcon = LoadIcon(NULL, IDI_APPLICATION);
  132. wc.hCursor = LoadCursor(NULL, IDC_ARROW);
  133. wc.hbrBackground = ghbrWhite;
  134. wc.lpszMenuName = _T("MainMenu");
  135. wc.lpszClassName = _T("TestClass");
  136. if(!RegisterClass(&wc)) { return FALSE; }
  137. ghwndMain = CreateWindowEx(
  138. 0,
  139. _T("TestClass"),
  140. _T("Win32 Test"),
  141. WS_OVERLAPPED |
  142. WS_CAPTION |
  143. WS_BORDER |
  144. WS_THICKFRAME |
  145. WS_MAXIMIZEBOX |
  146. WS_MINIMIZEBOX |
  147. WS_CLIPCHILDREN |
  148. WS_VISIBLE |
  149. WS_SYSMENU,
  150. 80,
  151. 70,
  152. 500,
  153. 500,
  154. NULL,
  155. NULL,
  156. ghInstance,
  157. NULL
  158. );
  159. if (ghwndMain == NULL)
  160. {
  161. return(FALSE);
  162. }
  163. SetFocus(ghwndMain);
  164. return TRUE;
  165. }
  166. /***************************************************************************\
  167. * main(argc, argv[])
  168. *
  169. * Sets up the message loop.
  170. \***************************************************************************/
  171. _cdecl
  172. main(
  173. INT argc,
  174. PCHAR argv[]
  175. )
  176. {
  177. MSG msg;
  178. HACCEL haccel;
  179. CHAR* pSrc;
  180. CHAR* pDst;
  181. ghInstance = GetModuleHandle(NULL);
  182. if(!bInitApp()) { return 0; }
  183. while(GetMessage (&msg, NULL, 0, 0))
  184. {
  185. if((ghwndMain == 0) || !IsDialogMessage(ghwndMain, &msg)) {
  186. TranslateMessage(&msg) ;
  187. DispatchMessage(&msg) ;
  188. }
  189. }
  190. return 1;
  191. }