Source code of Windows XP (NT5)
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.

437 lines
9.6 KiB

  1. //*********************************************************************
  2. //* Microsoft Windows **
  3. //* Copyright(c) Microsoft Corp., 1993 **
  4. //*********************************************************************
  5. #include "admincfg.h"
  6. HWND hwndMain=NULL;
  7. HWND hwndUser=NULL;
  8. BOOL OnCreate(HWND hWnd);
  9. BOOL OnInit(HWND hWnd);
  10. VOID OnDestroy(HWND hWnd);
  11. VOID ProcessMouseDown(HWND hwndParent,HWND hwndTree);
  12. VOID ProcessMouseUp(HWND hwndParent,HWND hwndTree);
  13. VOID ProcessMouseMove(HWND hwndParent,HWND hwndTree);
  14. VOID CheckMenuItems(HWND hwndApp);
  15. DWORD dwAppState = 0;
  16. BOOL fNetworkInstalled = 0;
  17. TCHAR szDatFilename[MAX_PATH+1]=TEXT("");
  18. TCHAR szDlgModeUserName[USERNAMELEN+1];
  19. extern HGLOBAL hClipboardUser;
  20. /*******************************************************************
  21. NAME: WndProc
  22. SYNOPSIS: Window proc for main window
  23. ********************************************************************/
  24. LRESULT CALLBACK WndProc(HWND hWnd,UINT message,WPARAM wParam,LPARAM lParam)
  25. {
  26. int wmId, wmEvent;
  27. switch (message) {
  28. case WM_COMMAND: // message: command from application menu
  29. wmId = LOWORD(wParam);
  30. wmEvent = HIWORD(wParam);
  31. if (wmId >= IDM_FILEHISTORY && wmId < IDM_FILEHISTORY +
  32. FILEHISTORY_COUNT) {
  33. MENUITEMINFO mii;
  34. TCHAR szFilename[MAX_PATH+1];
  35. mii.dwTypeData = szFilename;
  36. mii.cch = ARRAYSIZE(szFilename);
  37. // this is a file menu shortcut with a filename, try
  38. // to open
  39. if (!(dwAppState & AS_CANHAVEDOCUMENT))
  40. return FALSE;
  41. mii.cbSize = sizeof(mii);
  42. mii.fMask = MIIM_TYPE;
  43. mii.wID = wmId;
  44. if (GetMenuItemInfo(GetSubMenu(GetMenu(hWnd),0),
  45. wmId,FALSE,&mii)) {
  46. if (!lstrlen(szFilename))
  47. return FALSE;
  48. if (dwAppState & AS_FILEDIRTY) {
  49. if (!QueryForSave(hWnd,hwndUser))
  50. return TRUE; // user cancelled
  51. }
  52. // open the file
  53. OnOpen_W(hWnd,hwndUser,szFilename);
  54. return TRUE;
  55. }
  56. }
  57. switch (wmId) {
  58. case IDM_ABOUT:
  59. ShellAboutA ( hWnd, szAppName, szNull,
  60. LoadIcon( ghInst, MAKEINTRESOURCE(IDI_APPICON)) );
  61. break;
  62. case IDM_EXIT:
  63. if (dwAppState & AS_FILEDIRTY) {
  64. if (!QueryForSave(hWnd,hwndUser)) return TRUE; // user cancelled
  65. }
  66. DestroyWindow(hWnd);
  67. break;
  68. case IDM_NEW:
  69. OnNew(hWnd,hwndUser);
  70. break;
  71. case IDM_OPEN:
  72. OnOpen(hWnd,hwndUser);
  73. break;
  74. case IDM_OPENREGISTRY:
  75. OnOpenRegistry(hWnd,hwndUser,TRUE);
  76. break;
  77. case IDM_TEMPLATEOPT:
  78. OnTemplateOptions(hWnd);
  79. break;
  80. #ifdef INCL_GROUP_SUPPORT
  81. case IDM_GROUPPRIORITY:
  82. OnGroupPriority(hWnd);
  83. break;
  84. #endif
  85. case IDM_SAVE:
  86. OnSave(hWnd,hwndUser);
  87. break;
  88. case IDM_SAVEAS:
  89. OnSaveAs(hWnd,hwndUser);
  90. break;
  91. case IDM_CLOSE:
  92. OnClose(hWnd,hwndUser);
  93. break;
  94. case IDM_COPY:
  95. OnCopy(hWnd,hwndUser);
  96. break;
  97. case IDM_PASTE:
  98. OnPaste(hWnd,hwndUser);
  99. break;
  100. case IDM_CONNECT:
  101. OnConnect(hWnd,hwndUser);
  102. break;
  103. case IDM_DISCONNECT:
  104. OnClose(hWnd,hwndUser);
  105. break;
  106. case IDM_ADDUSER:
  107. DoAddUserDlg(hWnd,hwndUser);
  108. break;
  109. #ifdef INCL_GROUP_SUPPORT
  110. case IDM_ADDGROUP:
  111. DoAddGroupDlg(hWnd,hwndUser);
  112. break;
  113. #endif
  114. case IDM_REMOVE:
  115. OnRemove(hWnd,hwndUser);
  116. break;
  117. case IDM_ADDWORKSTATION:
  118. DoAddComputerDlg(hWnd,hwndUser);
  119. break;
  120. case IDM_PROPERTIES:
  121. OnProperties(hWnd,hwndUser);
  122. break;
  123. case IDM_SMALLICONS:
  124. SetNewView(hWnd,hwndUser,VT_SMALLICONS);
  125. break;
  126. case IDM_LARGEICONS:
  127. SetNewView(hWnd,hwndUser,VT_LARGEICONS);
  128. break;
  129. case IDM_LIST:
  130. SetNewView(hWnd,hwndUser,VT_LIST);
  131. break;
  132. case IDM_DETAILS:
  133. SetNewView(hWnd,hwndUser,VT_REPORT);
  134. break;
  135. case IDM_TOOLBAR:
  136. ViewInfo.fToolbar = !ViewInfo.fToolbar;
  137. ShowWindow(hwndToolbar,(ViewInfo.fToolbar ? SW_SHOW : SW_HIDE));
  138. UpdateListControlPlacement(hWnd,hwndUser);
  139. CheckMenuItems(hWnd);
  140. break;
  141. case IDM_STATUSBAR:
  142. ViewInfo.fStatusBar = !ViewInfo.fStatusBar;
  143. ShowWindow(hwndStatusBar,(ViewInfo.fStatusBar ? SW_SHOW : SW_HIDE));
  144. UpdateListControlPlacement(hWnd,hwndUser);
  145. CheckMenuItems(hWnd);
  146. break;
  147. case IDM_HELPCONTENTS:
  148. HtmlHelp(hWnd,LoadSz(IDS_HELPFILE,szSmallBuf,ARRAYSIZE(szSmallBuf)),
  149. HH_HELP_FINDER,0);
  150. break;
  151. default:
  152. return (DefWindowProc(hWnd, message, wParam, lParam));
  153. }
  154. break;
  155. case WM_CREATE:
  156. if (!OnCreate(hWnd)) {
  157. return (-1); // fail creation
  158. }
  159. return 0;
  160. break;
  161. case WM_FINISHINIT:
  162. OnInit(hWnd); // finish doing init stuff
  163. break;
  164. case WM_SETFOCUS:
  165. if (hwndUser) SetFocus(hwndUser);
  166. break;
  167. case WM_PAINT:
  168. {
  169. PAINTSTRUCT ps;
  170. BeginPaint(hWnd,&ps);
  171. EndPaint(hWnd,&ps);
  172. }
  173. break;
  174. case WM_QUERYENDSESSION:
  175. case WM_CLOSE:
  176. if (dwAppState & AS_FILEDIRTY) {
  177. if (!QueryForSave(hWnd,hwndUser)) return TRUE; // user cancelled
  178. }
  179. goto defproc;
  180. break;
  181. case WM_DESTROY:
  182. OnDestroy(hWnd);
  183. break;
  184. case WM_SIZE:
  185. if (hwndStatusBar)
  186. SendMessage( hwndStatusBar, WM_SIZE, wParam, lParam );
  187. if (hwndToolbar)
  188. SendMessage( hwndToolbar, WM_SIZE, wParam, lParam );
  189. UpdateListControlPlacement(hWnd,hwndUser);
  190. break;
  191. case WM_NOTIFY:
  192. if (((NMHDR *) lParam)->hwndFrom == hwndUser) {
  193. return OnListNotify(hWnd,hwndUser,(NM_LISTVIEW *) lParam);
  194. }
  195. {
  196. NMHDR * pnmhdr = (NMHDR *) lParam;
  197. if (pnmhdr->code == TTN_NEEDTEXT &&
  198. pnmhdr->hwndFrom == (HWND)
  199. SendMessage(hwndToolbar,TB_GETTOOLTIPS,0,0L))
  200. return (ProcessTooltips((TOOLTIPTEXT *) lParam));
  201. }
  202. break;
  203. default: // Passes it on if unproccessed
  204. defproc:
  205. return (DefWindowProc(hWnd, message, wParam, lParam));
  206. }
  207. return (0);
  208. }
  209. BOOL OnCreate(HWND hWnd)
  210. {
  211. hwndMain=hWnd;
  212. InitCommonControls();
  213. RestoreStateFromRegistry(hWnd);
  214. dwAppState = AS_CANOPENTEMPLATE;
  215. if (!InitImageLists() || !(hwndUser=CreateListControl(hWnd)) ||
  216. (!InitToolbar(hWnd))) {
  217. MsgBox(hWnd,IDS_ErrOUTOFMEMORY,MB_ICONEXCLAMATION,MB_OK);
  218. FreeImageLists();
  219. DestroyListControl(hwndUser);
  220. hwndUser=NULL;
  221. DeInitToolbar();
  222. return FALSE;
  223. }
  224. EnableWindow(hwndUser, FALSE);
  225. LoadFileMenuShortcuts(GetSubMenu(GetMenu(hWnd),0));
  226. SetNewView(hWnd,hwndUser,ViewInfo.dwView);
  227. UpdateListControlPlacement(hWnd,hwndUser);
  228. SetFocus(hwndUser);
  229. // send a WM_FINISHINIT message to ourselves to load template file
  230. // and data file. Do this after WM_CREATE returns so that status
  231. // bar can display text, etc
  232. PostMessage(hWnd,WM_FINISHINIT,0,0L);
  233. return TRUE;
  234. }
  235. BOOL OnInit(HWND hWnd)
  236. {
  237. HKEY hKey;
  238. // check to see if we have a network installed
  239. if (GetSystemMetrics(SM_NETWORK) & 0x1) {
  240. fNetworkInstalled = TRUE;
  241. }
  242. if (fNetworkInstalled) {
  243. // add a "connect" menu item
  244. MENUITEMINFO mii;
  245. HMENU hMenu = GetSubMenu(GetMenu(hWnd),0);
  246. mii.cbSize = sizeof(mii);
  247. mii.fMask = MIIM_TYPE;
  248. mii.fType = MFT_SEPARATOR;
  249. InsertMenuItem(hMenu,6,TRUE,&mii);
  250. mii.fMask = MIIM_TYPE | MIIM_ID;
  251. mii.wID = IDM_CONNECT;
  252. mii.fType = MFT_STRING;
  253. mii.dwTypeData = szSmallBuf;
  254. LoadSz(IDS_CONNECT,szSmallBuf,ARRAYSIZE(szSmallBuf));
  255. InsertMenuItem(hMenu,7,TRUE,&mii);
  256. }
  257. if (!(dwCmdLineFlags & CLF_DIALOGMODE)) {
  258. if ((LoadTemplates(hWnd) == ERROR_SUCCESS)
  259. || (GetATemplateFile(hWnd) && (LoadTemplates(hWnd) == ERROR_SUCCESS))) {
  260. dwAppState |= AS_CANHAVEDOCUMENT;
  261. }
  262. }
  263. // if filename specified on command line, try to load it
  264. if (!(dwCmdLineFlags & CLF_DIALOGMODE) && szDatFilename[0]) {
  265. OnOpen_W(hWnd,hwndUser,szDatFilename);
  266. }
  267. EnableMenuItems(hWnd,dwAppState);
  268. CheckMenuItems(hWnd);
  269. return TRUE;
  270. }
  271. VOID RunDialogMode(HWND hWnd,HWND hwndUser)
  272. {
  273. int iStart = 0;
  274. HGLOBAL hUser=NULL;
  275. UINT uRet;
  276. extern DWORD dwDlgRetCode;
  277. // load the template file
  278. if (uRet = LoadTemplates(hWnd) != ERROR_SUCCESS) {
  279. switch (uRet) {
  280. case ERROR_FILE_NOT_FOUND:
  281. dwDlgRetCode = AD_ADMNOTFOUND;
  282. break;
  283. case ERROR_NOT_ENOUGH_MEMORY:
  284. dwDlgRetCode = AD_OUTOFMEMORY;
  285. break;
  286. default:
  287. dwDlgRetCode = AD_ADMLOADERR;
  288. break;
  289. }
  290. return;
  291. }
  292. // try to load the data file
  293. if (!LoadFile(szDatFilename,hWnd,hwndUser,FALSE)) {
  294. // if we can't load it, try creating it
  295. if (CreateHiveFile(szDatFilename) != ERROR_SUCCESS ||
  296. !LoadFile(szDatFilename,hWnd,hwndUser,TRUE)) {
  297. dwDlgRetCode = AD_POLLOADERR;
  298. return;
  299. }
  300. }
  301. dwAppState = AS_FILELOADED | AS_FILEHASNAME | AS_LOCALREGISTRY;
  302. hUser = FindUser(hwndUser,szDlgModeUserName,(dwCmdLineFlags & CLF_USEWORKSTATIONNAME
  303. ? UT_MACHINE : UT_USER));
  304. // if user is not in policy file, create a new one
  305. if (!hUser) {
  306. hUser = AddUser(hwndUser,szDlgModeUserName,(dwCmdLineFlags &
  307. CLF_USEWORKSTATIONNAME ? UT_MACHINE : UT_USER));
  308. }
  309. if (!hUser) {
  310. MsgBox(hWnd,IDS_ErrOUTOFMEMORY,MB_ICONEXCLAMATION,MB_OK);
  311. dwDlgRetCode = AD_OUTOFMEMORY;
  312. return;
  313. }
  314. // run properties dialog
  315. if (DoPolicyDlg(hWnd,hUser)) {
  316. // save changes if user OK's the dialog
  317. dwAppState = AS_FILELOADED | AS_FILEHASNAME | AS_POLICYFILE | AS_FILEDIRTY;
  318. if (!SaveFile(szDatFilename,hWnd,hwndUser))
  319. dwDlgRetCode = AD_POLSAVEERR;
  320. }
  321. }
  322. VOID OnDestroy(HWND hWnd)
  323. {
  324. UnloadTemplates();
  325. #ifdef INCL_GROUP_SUPPORT
  326. FreeGroupPriorityList();
  327. #endif
  328. SaveStateToRegistry(hWnd);
  329. SaveFileMenuShortcuts(GetSubMenu(GetMenu(hWnd),0));
  330. if (hwndUser)
  331. RemoveAllUsers(hwndUser);
  332. if (hClipboardUser)
  333. GlobalFree(hClipboardUser);
  334. DestroyListControl(hwndUser);
  335. hwndUser=NULL;
  336. DeInitToolbar();
  337. FreeImageLists();
  338. if (pbufTemplates)
  339. {
  340. GlobalUnlock(hBufTemplates);
  341. GlobalFree(hBufTemplates);
  342. }
  343. PostQuitMessage(0);
  344. }