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.

305 lines
10 KiB

  1. //*********************************************************************
  2. //* Microsoft Windows **
  3. //* Copyright(c) Microsoft Corp., 1992 **
  4. //*********************************************************************
  5. #define STRICT // Use strict handle types
  6. //
  7. // NT uses DBG=1 for its debug builds.
  8. // Do the appropriate mapping here.
  9. //
  10. #if DBG
  11. #define DEBUG 1
  12. #endif
  13. #ifndef RC_INVOKED
  14. #include <nt.h>
  15. #include <ntrtl.h>
  16. #include <nturtl.h>
  17. #endif
  18. #include <windows.h> // Windows 3.1 (internal)
  19. #include <commctrl.h>
  20. #include <comctrlp.h>
  21. #include <prsht.h>
  22. #include <commdlg.h>
  23. #include <shellapi.h>
  24. #include <regstr.h>
  25. #include <sec32api.h>
  26. #include <htmlhelp.h>
  27. #include "memory.h"
  28. #include "user.h"
  29. #include "treeview.h"
  30. #include "policy.h"
  31. #include "view.h"
  32. #include "strings.h"
  33. #include "dlgcodes.h"
  34. #include "strids.h"
  35. #include "dlgids.h"
  36. #pragma intrinsic (memset)
  37. #pragma intrinsic (memcpy)
  38. // Defines
  39. #define REGBUFLEN 255
  40. #define MAXSTRLEN 2048
  41. #define SMALLBUF 48
  42. #define USERNAMELEN 260 // big enough for netware
  43. #define MEDIUMBUF 1024 // random buffer size
  44. #define HELPBUFSIZE 4096
  45. #define FILEHISTORY_COUNT 4 // # of last files remembered on file menu
  46. #define WM_FINISHINIT WM_USER + 0x00
  47. extern HINSTANCE ghInst; // app instance
  48. extern HWND hwndMain; // main window
  49. extern HWND hwndUser; // user listbox
  50. extern CLASSLIST gClassList;
  51. extern TCHAR szSmallBuf[SMALLBUF]; // global small buffer for general use
  52. extern TCHAR szDatFilename[MAX_PATH+1]; // name of active .DAT file
  53. extern TCHAR szDlgModeUserName[USERNAMELEN+1]; // user name for dialog mode operation
  54. extern TCHAR *pbufTemplates; //Buffer containing list of all active template files
  55. extern HGLOBAL hBufTemplates;
  56. extern DWORD dwBufTemplates;
  57. extern BOOL fNetworkInstalled;
  58. extern BOOL g_bWinnt;
  59. #define ERROR_ALREADY_DISPLAYED 0xFFFF
  60. #define ARRAYSIZE(a) (sizeof(a)/sizeof(a[0]))
  61. // Functions in POLEDIT.C
  62. BOOL InitApplication(HANDLE);
  63. BOOL InitInstance(HANDLE, int);
  64. LRESULT CALLBACK About (HWND, UINT, WPARAM, LPARAM);
  65. // Functions in MAIN.C
  66. LRESULT CALLBACK WndProc(HWND, UINT, WPARAM, LPARAM);
  67. // Functions in MEMORY.C
  68. BOOL FreeTable(TABLEENTRY * pTableEntry);
  69. BOOL InitializeRootTables(VOID);
  70. VOID FreeRootTables(VOID);
  71. // Functions in PARSE.C
  72. UINT ParseTemplateFile(HWND hWnd,HANDLE hFile,LPTSTR pszFileName);
  73. // Functions in TREEVIEW.C
  74. BOOL RefreshTreeView(POLICYDLGINFO * pdi,HWND hwndTree,TABLEENTRY * pTableEntry,
  75. HGLOBAL hUser);
  76. BOOL InitImageLists(VOID);
  77. VOID FreeImageLists(VOID);
  78. UINT GetImageIndex(DWORD dwType,BOOL fExpanded,BOOL fEnabled);
  79. BOOL SetTreeRootItem(HWND hwndPolicy,USERHDR * pUserHdr);
  80. VOID SetStatusText(TCHAR * pszText);
  81. VOID GetStatusText(TCHAR * pszText,UINT cbText);
  82. BOOL IsSelectedItemChecked(HWND hwndTree);
  83. // Functions in TREECTRL.C
  84. BOOL OnTreeNotify(HWND hwndParent,HWND hwndTree,NM_TREEVIEW *pntv);
  85. // Functions in LISTCTRL.C
  86. BOOL OnListNotify(HWND hwndParent,HWND hwndList,NM_LISTVIEW *pnlv);
  87. HWND CreateListControl(HWND hwndApp);
  88. VOID DestroyListControl(HWND hwndList);
  89. VOID UpdateListControlPlacement(HWND hwndApp,HWND hwndList);
  90. BOOL OnProperties(HWND hwndParent,HWND hwndList);
  91. // Functions in POLICY.C
  92. BOOL DoPolicyDlg(HWND hwndOwner,HGLOBAL hUser);
  93. BOOL SetPolicyState(HWND hDlg,TABLEENTRY * pTableEntry,UINT uState);
  94. // Functions in SETTINGS.c
  95. LRESULT CALLBACK ClipWndProc(HWND hWnd,UINT message,WPARAM wParam,
  96. LPARAM lParam);
  97. BOOL CreateSettingsControls(HWND hwndParent,SETTINGS * pSettings,BOOL fEnabled);
  98. BOOL ProcessSettingsControls(HWND hwndOwner,DWORD dwValidate);
  99. VOID FreeSettingsControls(HWND hwndOwner);
  100. BOOL EnableSettingsControls(HWND hDlg,BOOL fEnable);
  101. BOOL SetVariableLengthData(HGLOBAL hUser,UINT nDataIndex,TCHAR * pchData,
  102. DWORD cbData);
  103. // dwValidate values for ProcessSettingsControls
  104. #define PSC_NOVALIDATE 0
  105. #define PSC_VALIDATESILENT 1
  106. #define PSC_VALIDATENOISY 2
  107. // Functions in USER.C
  108. HGLOBAL AddUser(HWND hwndList,TCHAR * szName,DWORD dwType);
  109. BOOL CloneUser(HGLOBAL hUser);
  110. BOOL CopyUser(HGLOBAL hUserSrc,HGLOBAL hUserDst);
  111. BOOL RemoveUser(HWND hwndList,UINT nIndex,BOOL fMarkDeleted);
  112. BOOL FreeUser(HGLOBAL hUser);
  113. BOOL RemoveAllUsers(HWND hwndList);
  114. BOOL AddDefaultUsers(HWND hwndList);
  115. BOOL GetUserHeader(HGLOBAL hUser,USERHDR * pUserHdr);
  116. UINT GetUserImageIndex(DWORD dwUserType);
  117. BOOL AllocTemplateTable(VOID);
  118. VOID FreeTemplateTable(VOID);
  119. BOOL AddDeletedUser(USERHDR * pUserHdr);
  120. USERHDR * GetDeletedUser(UINT nIndex);
  121. VOID ClearDeletedUserList(VOID);
  122. VOID MapUserName(TCHAR * szUserName,TCHAR * szMappedName);
  123. VOID UnmapUserName(TCHAR * szMappedName,TCHAR * szUserName,BOOL fUser);
  124. // Functions in ADD.C
  125. BOOL DoAddUserDlg(HWND hwndApp,HWND hwndList);
  126. BOOL DoAddGroupDlg(HWND hwndApp,HWND hwndList);
  127. BOOL DoAddComputerDlg(HWND hwndApp,HWND hwndList);
  128. HGLOBAL FindUser(HWND hwndList,TCHAR * pszName,DWORD dwType);
  129. // Functions in REMOVE.C
  130. BOOL OnRemove(HWND hwndApp,HWND hwndList);
  131. // Functions in LOAD.C
  132. BOOL LoadFile(TCHAR * pszFilename,HWND hwndApp,HWND hwndList,BOOL fDisplayErrors);
  133. BOOL LoadFromRegistry(HWND hwndApp,HWND hwndList,BOOL fDisplayErrors);
  134. // Functions in SAVE.C
  135. BOOL SaveFile(TCHAR * pszFilename,HWND hwndApp,HWND hwndList);
  136. BOOL SaveToRegistry(HWND hwndApp,HWND hwndList);
  137. // Functions in FILECMD.C
  138. BOOL OnOpen(HWND hwndApp,HWND hwndList);
  139. BOOL OnOpen_W(HWND hwndApp,HWND hwndList,TCHAR * pszFilename);
  140. BOOL OnNew(HWND hwndApp,HWND hwndList);
  141. BOOL OnSave(HWND hwndApp,HWND hwndList);
  142. BOOL OnSaveAs(HWND hwndApp,HWND hwndList);
  143. BOOL OnClose(HWND hwndApp,HWND hwndList);
  144. BOOL QueryForSave(HWND hwndApp,HWND hwndList);
  145. UINT CreateHiveFile(TCHAR * pszFilename);
  146. BOOL OnOpenTemplate(HWND hwndOwner,HWND hwndApp);
  147. BOOL OnOpenRegistry(HWND hwndApp,HWND hwndList,BOOL fDisplayErrors);
  148. VOID PrependValueName(TCHAR * pszValueName,DWORD dwFlags,TCHAR * pszNewValueName,
  149. UINT cbNewValueName);
  150. // Functions in REGISTRY.C
  151. BOOL RestoreStateFromRegistry(HWND hWnd);
  152. BOOL SaveStateToRegistry(HWND hWnd);
  153. VOID LoadFileMenuShortcuts(HMENU hMenu);
  154. VOID SaveFileMenuShortcuts(HMENU hMenu);
  155. // Functions in INFMGR.C
  156. BOOL GetATemplateFile(HWND hWnd);
  157. UINT LoadTemplates(HWND hWnd);
  158. UINT LoadTemplateFile(HWND hWnd,TCHAR * szFilename);
  159. UINT LoadTemplatesFromDlg(HWND hWnd);
  160. UINT PrepareToLoadTemplates();
  161. VOID UnloadTemplates(VOID);
  162. DWORD GetDefaultTemplateFilename(HWND hWnd,TCHAR * szFilename,UINT cbFilename);
  163. // Functions in VIEW.C
  164. VOID EnableMenuItems(HWND hwndApp,DWORD dwState);
  165. VOID SetTitleBar(HWND hwndApp,TCHAR * szFilename);
  166. BOOL ReplaceMenuItem(HWND hWnd,UINT idOld,UINT idNew,UINT idResourceTxt);
  167. VOID AddFileShortcut(HMENU hMenu,TCHAR * pszNewFilename);
  168. VOID SetStatusItemCount(HWND hwndList);
  169. VOID SetViewType(HWND hwndList,DWORD dwView);
  170. VOID CheckViewItem(HWND hwndApp,DWORD dwView);
  171. VOID SetNewView(HWND hwndApp,HWND hwndList,DWORD dwNewView);
  172. // Functions in REGUTIL.C
  173. UINT WriteRegistryDWordValue(HKEY hkeyRoot,TCHAR * pszKeyName,TCHAR * pszValueName,
  174. DWORD dwValue);
  175. UINT ReadRegistryDWordValue(HKEY hkeyRoot,TCHAR * pszKeyName,TCHAR * pszValueName,
  176. DWORD * pdwValue);
  177. UINT WriteRegistryStringValue(HKEY hkeyRoot,TCHAR * pszKeyName,TCHAR * pszValueName,
  178. TCHAR * pszValue, BOOL bExpandable);
  179. UINT ReadRegistryStringValue(HKEY hkeyRoot,TCHAR * pszKeyName,TCHAR * pszValueName,
  180. TCHAR * pszValue,UINT cbValue);
  181. UINT DeleteRegistryValue(HKEY hkeyRoot,TCHAR * pszKeyName,TCHAR * pszValueName);
  182. LONG MyRegDeleteKey(HKEY hkeyRoot,LPTSTR pszSubkey);
  183. LONG MyRegLoadKey(HKEY hKey, LPCTSTR lpSubKey, LPTSTR lpFile);
  184. LONG MyRegUnLoadKey(HKEY hKey, LPCTSTR lpSubKey);
  185. LONG MyRegSaveKey(HKEY hKey, LPCTSTR lpSubKey);
  186. // Functions in OPTIONS.C
  187. BOOL OnTemplateOptions(HWND hwndApp);
  188. // Functions in COPY.C
  189. BOOL OnCopy(HWND hwndApp,HWND hwndList);
  190. BOOL OnPaste(HWND hwndApp,HWND hwndList);
  191. BOOL CanCopy(HWND hwndList);
  192. BOOL CanPaste(HWND hwndList);
  193. UINT GetClipboardUserType(VOID);
  194. // Functions in CONNECT.C
  195. BOOL OnConnect(HWND hwndOwner,HWND hwndList);
  196. BOOL OnDisconnect(HWND hwndOwner);
  197. BOOL RemoteConnect(HWND hwndOwner,TCHAR * pszComputerName,BOOL fDisplayError);
  198. // Functions in LISTBOX.C
  199. VOID ShowListbox(HWND hParent,HGLOBAL hUser,SETTINGS * pSettings,UINT uDataIndex);
  200. // Functions in GROUPPRI.C
  201. BOOL AddGroupPriEntry(TCHAR * pszGroupName);
  202. BOOL RemoveGroupPriEntry(TCHAR * pszGroupName);
  203. UINT LoadGroupPriorityList(HKEY hKeyPriority,HKEY hkeyGroup);
  204. UINT SaveGroupPriorityList(HKEY hKey);
  205. VOID FreeGroupPriorityList( VOID );
  206. BOOL OnGroupPriority(HWND hWnd);
  207. // Functions in UTIL.C
  208. BOOL EnableDlgItem(HWND hDlg,UINT uID,BOOL fEnable);
  209. BOOL IsDlgItemEnabled(HWND hDlg,UINT uID);
  210. int MsgBox(HWND hWnd,UINT nResource,UINT uIcon,UINT uButtons);
  211. int MsgBoxSz(HWND hWnd,LPTSTR szText,UINT uIcon,UINT uButtons);
  212. int MsgBoxParam(HWND hWnd,UINT nResource,TCHAR * szReplaceText,UINT uIcon,UINT uButtons);
  213. LONG AddListboxItem(HWND hDlg,int idControl,TCHAR * szItem);
  214. LONG GetListboxItemText(HWND hDlg,int idControl,UINT nIndex,TCHAR * szText);
  215. LONG SetListboxItemData(HWND hDlg,int idControl,UINT nIndex,LPARAM dwData);
  216. LONG GetListboxItemData(HWND hDlg,int idControl,UINT nIndex);
  217. LONG SetListboxSelection(HWND hDlg,int idControl,UINT nIndex);
  218. LONG GetListboxSelection(HWND hDlg,int idControl);
  219. TCHAR * ResizeBuffer(TCHAR *pBuf,HGLOBAL hBuf,DWORD dwNeeded,DWORD * pdwCurSize);
  220. LPTSTR LoadSz(UINT idString,LPTSTR lpszBuf,UINT cbBuf);
  221. DWORD RoundToDWord(DWORD dwSize);
  222. DWORD ListView_GetItemParm( HWND hwnd, int i );
  223. BOOL StringToNum(TCHAR *szStr,UINT * pnVal);
  224. VOID DisplayStandardError(HWND hwndOwner,TCHAR * pszParam,UINT uMsgID,UINT uErr);
  225. extern DWORD dwAppState;
  226. extern DWORD dwCmdLineFlags;
  227. extern DWORD dwDlgRetCode;
  228. extern TCHAR szAppName[];
  229. // App state bits in dwAppState
  230. #define AS_FILELOADED 0x0001
  231. #define AS_FILEDIRTY 0x0002
  232. #define AS_FILEHASNAME 0x0004
  233. #define AS_CANREMOVE 0x0008
  234. #define AS_CANOPENTEMPLATE 0x0010
  235. #define AS_CANHAVEDOCUMENT 0x0020
  236. #define AS_POLICYFILE 0x0040
  237. #define AS_LOCALREGISTRY 0x0080
  238. #define AS_REMOTEREGISTRY 0x0100
  239. // command line flags
  240. #define CLF_DIALOGMODE 0x0001
  241. #define CLF_USETEMPLATENAME 0x0002
  242. #define CLF_USEPOLICYFILENAME 0x0004
  243. #define CLF_USEWORKSTATIONNAME 0x0008
  244. #define CLF_USEUSERNAME 0x0010
  245. #define COMPUTERNAMELEN 20 // big enough for 20-digit SPX address
  246. extern HKEY hkeyVirtHLM; // virtual HKEY_LOCAL_MACHINE
  247. extern HKEY hkeyVirtHCU; // virtual HKEY_CURRENT_USER
  248. extern UINT nDeletedUsers;
  249. // Useful macros
  250. #define GETNAMEPTR(x) ((TCHAR *) x + x->uOffsetName)
  251. #define GETKEYNAMEPTR(x) ((TCHAR *) x + x->uOffsetKeyName)
  252. #define GETVALUENAMEPTR(x) ((TCHAR *) x + x->uOffsetValueName)
  253. #define GETOBJECTDATAPTR(x) ((TCHAR *) x + x->uOffsetObjectData)
  254. #ifdef DEBUG
  255. extern CHAR szDebugOut[];
  256. #endif