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.

317 lines
6.6 KiB

  1. /*++
  2. Copyright (c) 1998 Microsoft Corporation
  3. Module Name:
  4. memdbe.c
  5. Abstract:
  6. main file for memdbe.exe, containing winmain().
  7. this creates the application framework, and then
  8. the child window dialog which has the controls and
  9. displays.
  10. Author:
  11. Matthew Vanderzee (mvander) 13-Aug-1999
  12. Revision History:
  13. --*/
  14. #include "pch.h"
  15. #include "dbeditp.h"
  16. #include "dialogs.h"
  17. #define MAX_LOADSTRING 100
  18. HWND g_hChildWindow = NULL;
  19. HMENU g_hMenuMain;
  20. #define DEFAULT_WINDOW_TITLE "MemDb Editor"
  21. #define DEFAULT_FILENAME "ntsetup.dat"
  22. LRESULT CALLBACK WndProc(HWND, UINT, WPARAM, LPARAM);
  23. VOID
  24. HelpAndExit (
  25. VOID
  26. )
  27. {
  28. MessageBox (
  29. NULL,
  30. "Command Line Syntax:\n\n"
  31. "\tmemdbe [database file]\n"
  32. "\n"
  33. "If no database file is specified, \"ntsetup.dat\" is opened if it exists.",
  34. "MemDb Editor",
  35. MB_OK|MB_ICONINFORMATION
  36. );
  37. exit(1);
  38. }
  39. int WINAPI WinMain (
  40. HINSTANCE hInstance,
  41. HINSTANCE hPrevInstance,
  42. LPSTR lpPtr,
  43. int nCmdShow
  44. )
  45. {
  46. HACCEL hAccel;
  47. static char AppName[] = "MemDbEdit";
  48. MSG msg;
  49. HWND hwnd;
  50. WNDCLASSEX wndclass;
  51. RECT DialogRect;
  52. g_hInst = hInstance;
  53. wndclass.cbSize = sizeof(wndclass);
  54. wndclass.style = CS_HREDRAW|CS_VREDRAW;
  55. wndclass.lpfnWndProc = WndProc;
  56. wndclass.cbClsExtra = 0;
  57. wndclass.cbWndExtra = 0;
  58. wndclass.hInstance = hInstance;
  59. wndclass.hIcon = LoadIcon (NULL, MAKEINTRESOURCE(IDI_ICON_SPHERE));
  60. wndclass.hCursor = LoadCursor (NULL, IDC_ARROW);
  61. wndclass.hbrBackground = (HBRUSH) GetStockObject (WHITE_BRUSH);
  62. wndclass.lpszMenuName = NULL;
  63. wndclass.lpszClassName = AppName;
  64. wndclass.hIconSm = NULL;
  65. //LoadIcon (NULL, MAKEINTRESOURCE(IDI_ICON1));
  66. RegisterClassEx (&wndclass);
  67. hwnd = CreateWindow (
  68. AppName,
  69. DEFAULT_WINDOW_TITLE,
  70. WS_OVERLAPPEDWINDOW & (~WS_MAXIMIZEBOX) & (~WS_THICKFRAME),
  71. CW_USEDEFAULT,
  72. CW_USEDEFAULT,
  73. CW_USEDEFAULT,
  74. CW_USEDEFAULT,
  75. NULL,
  76. NULL,
  77. hInstance,
  78. lpPtr
  79. );
  80. ShowWindow (hwnd, nCmdShow);
  81. UpdateWindow (hwnd);
  82. hAccel = LoadAccelerators (hInstance, MAKEINTRESOURCE(IDR_ACCELERATOR));
  83. // Main message loop:
  84. while (GetMessage(&msg, NULL, 0, 0)) {
  85. if (!TranslateAccelerator (hwnd, hAccel, &msg)) {
  86. TranslateMessage(&msg);
  87. DispatchMessage(&msg);
  88. }
  89. }
  90. return msg.wParam;
  91. }
  92. VOID
  93. pInitializeSystemMenu (
  94. HWND hwnd
  95. )
  96. {
  97. HMENU hMenu;
  98. hMenu = GetSystemMenu (hwnd, FALSE);
  99. RemoveMenu (hMenu, SC_MAXIMIZE, MF_BYCOMMAND);
  100. RemoveMenu (hMenu, SC_SIZE, MF_BYCOMMAND);
  101. }
  102. BOOL
  103. pInitializeWindows (
  104. HWND hwnd
  105. )
  106. {
  107. RECT rect, rect2;
  108. g_hMenuMain = LoadMenu (g_hInst, MAKEINTRESOURCE(IDR_MENU_MAIN));
  109. SetMenu (hwnd, g_hMenuMain);
  110. g_hChildWindow = CreateDialog (
  111. g_hInst,
  112. MAKEINTRESOURCE(IDD_DIALOG_CHILD),
  113. hwnd,
  114. MainDlgProc
  115. );
  116. if (!g_hChildWindow) {
  117. DEBUGMSG ((DBG_ERROR, "Could not create child window!"));
  118. }
  119. GetWindowRect(hwnd, &rect);
  120. GetWindowRect(g_hChildWindow, &rect2);
  121. MoveWindow (
  122. hwnd,
  123. rect.left,
  124. rect.top,
  125. (rect2.right-rect2.left) + 2*GetSystemMetrics(SM_CXDLGFRAME),
  126. (rect2.bottom-rect2.top) + 2*GetSystemMetrics(SM_CYDLGFRAME) + GetSystemMetrics(SM_CYCAPTION) + GetSystemMetrics(SM_CYMENU),
  127. FALSE
  128. );
  129. ShowWindow (g_hChildWindow, SW_SHOWNORMAL);
  130. return TRUE;
  131. }
  132. BOOL
  133. pDestroyWindows (
  134. HWND hwnd
  135. )
  136. {
  137. DestroyWindow (g_hChildWindow);
  138. DestroyMenu (GetMenu(hwnd));
  139. return TRUE;
  140. }
  141. BOOL
  142. pUpdateWindowTitle (
  143. HWND hwnd,
  144. LPSTR OpenFile,
  145. BOOL IsFileModified
  146. )
  147. {
  148. char TempString[512];
  149. if (OpenFile && (OpenFile[0] != '\0')) {
  150. StringCopyA (TempString, OpenFile);
  151. StringCatA (TempString, " - ");
  152. } else {
  153. TempString[0] = '\0';
  154. }
  155. StringCatA (TempString, DEFAULT_WINDOW_TITLE);
  156. if (IsFileModified) {
  157. StringCatA (TempString, " *");
  158. }
  159. SetWindowText (hwnd, TempString);
  160. return TRUE;
  161. }
  162. LRESULT CALLBACK WndProc(HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam)
  163. {
  164. BOOL b;
  165. LPSTR Ptr;
  166. POINT pt;
  167. HWND hChildWnd;
  168. static LPCREATESTRUCT pCS;
  169. if (WantProcess (message, wParam, lParam)) {
  170. //
  171. // if the dialog window message handler wants to process the message
  172. // send it to it (in MemdbInt.c)
  173. //
  174. return SendMessage (g_hChildWindow, message, wParam, lParam);
  175. }
  176. switch (message)
  177. {
  178. case WM_CREATE:
  179. pInitializeSystemMenu (hwnd);
  180. InitializeMemDb (hwnd);
  181. pInitializeWindows (hwnd);
  182. pUpdateWindowTitle (hwnd, "", FALSE);
  183. pCS = (LPCREATESTRUCT)lParam;
  184. Ptr = (LPSTR)pCS->lpCreateParams;
  185. if (_mbschr (Ptr, '?')) {
  186. HelpAndExit ();
  187. }
  188. if (Ptr[0]!='\0') {
  189. SendMessage (g_hChildWindow, WM_FILE_LOAD, (WPARAM)Ptr, 0);
  190. } else if (DoesFileExistA (DEFAULT_FILENAME)) {
  191. SendMessage (g_hChildWindow, WM_FILE_LOAD, (WPARAM)(DEFAULT_FILENAME), 0);
  192. }
  193. break;
  194. case WM_COMMAND:
  195. switch (LOWORD(wParam))
  196. {
  197. case ID_HELP_ABOUT:
  198. AboutDialog (hwnd);
  199. break;
  200. case ID_FILE_QUIT:
  201. SendMessage (g_hChildWindow, WM_QUIT_CHECK, (WPARAM)&b, 0);
  202. if (b) {
  203. DestroyWindow(hwnd);
  204. }
  205. break;
  206. default:
  207. return DefWindowProc(hwnd, message, wParam, lParam);
  208. }
  209. break;
  210. case WM_SYSCOMMAND:
  211. switch (wParam) {
  212. case SC_CLOSE:
  213. SendMessage (g_hChildWindow, WM_QUIT_CHECK, (WPARAM)&b, 0);
  214. if (b) {
  215. DestroyWindow(hwnd);
  216. }
  217. break;
  218. default:
  219. return DefWindowProc(hwnd, message, wParam, lParam);
  220. }
  221. break;
  222. case WM_FILE_UPDATE:
  223. pUpdateWindowTitle (hwnd, (LPSTR)wParam, (BOOL)lParam);
  224. break;
  225. case WM_DESTROY:
  226. pDestroyWindows (hwnd);
  227. DestroyMemDb ();
  228. PostQuitMessage (0);
  229. break;
  230. default:
  231. return DefWindowProc(hwnd, message, wParam, lParam);
  232. }
  233. return 0;
  234. }