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.

337 lines
7.4 KiB

  1. /*++
  2. Microsoft Confidential
  3. Copyright (c) 1992-1997 Microsoft Corporation
  4. All rights reserved
  5. Module Name:
  6. sysdm.c
  7. Abstract:
  8. Initialization code for System Control Panel Applet
  9. Author:
  10. Eric Flo (ericflo) 19-Jun-1995
  11. Revision History:
  12. 15-Oct-1997 scotthal
  13. Complete overhaul
  14. --*/
  15. #include "sysdm.h"
  16. #include <shsemip.h>
  17. #include <regstr.h>
  18. //
  19. // Global Variables
  20. //
  21. HINSTANCE hInstance;
  22. TCHAR szShellHelp[] = TEXT("ShellHelp");
  23. TCHAR g_szNull[] = TEXT("");
  24. UINT uiShellHelp;
  25. TCHAR g_szErrMem[ 200 ]; // Low memory message
  26. TCHAR g_szSystemApplet[ 100 ]; // "System Control Panel Applet" title
  27. //
  28. // Function prototypes
  29. //
  30. void
  31. RunApplet(
  32. IN HWND hwnd,
  33. IN LPTSTR lpCmdLine
  34. );
  35. void _GetStartingPage(IN LPTSTR lpCmdLine, IN PROPSHEETHEADER* ppsh, INT* piStartPage, LPTSTR pszStartPage, INT cchStartPage);
  36. BOOL CALLBACK _AddPropSheetPage(HPROPSHEETPAGE hpage, LPARAM lParam);
  37. BOOL
  38. WINAPI
  39. DllInitialize(
  40. IN HINSTANCE hInstDLL,
  41. IN DWORD dwReason,
  42. IN LPVOID lpvReserved
  43. )
  44. /*++
  45. Routine Description:
  46. Main entry point.
  47. Arguments:
  48. hInstDLL -
  49. Supplies DLL instance handle.
  50. dwReason -
  51. Supplies the reason DllInitialize() is being called.
  52. lpvReserved -
  53. Reserved, NULL.
  54. Return Value:
  55. BOOL
  56. --*/
  57. {
  58. if (dwReason == DLL_PROCESS_DETACH)
  59. MEM_EXIT_CHECK();
  60. if (dwReason != DLL_PROCESS_ATTACH) {
  61. return TRUE;
  62. }
  63. hInstance = hInstDLL;
  64. return TRUE;
  65. }
  66. LONG
  67. APIENTRY
  68. CPlApplet(
  69. IN HWND hwnd,
  70. IN WORD wMsg,
  71. IN LPARAM lParam1,
  72. IN LPARAM lParam2
  73. )
  74. /*++
  75. Routine Description:
  76. Control Panel Applet entry point.
  77. Arguments:
  78. hwnd -
  79. Supplies window handle.
  80. wMsg -
  81. Supplies message being sent.
  82. lParam1 -
  83. Supplies parameter to message.
  84. lParam2 -
  85. Supplies parameter to message.
  86. Return Value:
  87. Nonzero if message was handled.
  88. Zero if message was unhandled.
  89. --*/
  90. {
  91. LPCPLINFO lpCPlInfo;
  92. switch (wMsg) {
  93. case CPL_INIT:
  94. uiShellHelp = RegisterWindowMessage (szShellHelp);
  95. LoadString( hInstance, IDS_INSUFFICIENT_MEMORY, g_szErrMem, ARRAYSIZE( g_szErrMem ) );
  96. LoadString( hInstance, IDS_SYSDM_TITLE, g_szSystemApplet, ARRAYSIZE( g_szSystemApplet ) );
  97. return (LONG) TRUE;
  98. case CPL_GETCOUNT:
  99. return 1;
  100. case CPL_INQUIRE:
  101. lpCPlInfo = (LPCPLINFO)lParam2;
  102. lpCPlInfo->idIcon = ID_ICON;
  103. lpCPlInfo->idName = IDS_NAME;
  104. lpCPlInfo->idInfo = IDS_INFO;
  105. return (LONG) TRUE;
  106. case CPL_DBLCLK:
  107. lParam2 = 0L;
  108. // fall through...
  109. case CPL_STARTWPARMS:
  110. RunApplet(hwnd, (LPTSTR)lParam2);
  111. return (LONG) TRUE;
  112. }
  113. return (LONG)0;
  114. }
  115. HPROPSHEETPAGE CreatePage(int idd, DLGPROC pfnDlgProc)
  116. {
  117. PROPSHEETPAGE psp;
  118. psp.dwSize = SIZEOF(psp);
  119. psp.dwFlags = PSP_DEFAULT;
  120. psp.hInstance = hInstance;
  121. psp.pszTemplate = MAKEINTRESOURCE(idd);
  122. psp.pfnDlgProc = pfnDlgProc;
  123. return CreatePropertySheetPage(&psp);
  124. }
  125. static const PSPINFO c_pspCB[] =
  126. {
  127. { CreatePage, IDD_GENERAL, GeneralDlgProc },
  128. { CreateNetIDPage, 0, NULL },
  129. { CreatePage, IDD_HARDWARE, HardwareDlgProc },
  130. { CreatePage, IDD_ADVANCED, AdvancedDlgProc },
  131. { CreateSystemRestorePage, 0, NULL },
  132. };
  133. void
  134. RunApplet(
  135. IN HWND hwnd,
  136. IN LPTSTR lpCmdLine
  137. )
  138. /*++
  139. Routine Description:
  140. CPL_STARTWPARMS message handler. Called when the user
  141. runs the Applet.
  142. PropSheet initialization occurs here.
  143. Arguments:
  144. hwnd -
  145. Supplies window handle.
  146. lpCmdLine -
  147. Supplies the command line used to invoke the applet.
  148. Return Value:
  149. none
  150. --*/
  151. {
  152. HRESULT hrOle = CoInitialize(0);
  153. if (!SHRestricted(REST_MYCOMPNOPROP))
  154. {
  155. if (lpCmdLine && *lpCmdLine && !lstrcmp(lpCmdLine, TEXT("-1")))
  156. {
  157. // -1 means Performance Options cpl
  158. DoPerformancePS(NULL);
  159. }
  160. else
  161. {
  162. HPROPSHEETPAGE hPages[MAX_PAGES];
  163. PROPSHEETHEADER psh;
  164. UINT iPage = 0;
  165. HPSXA hpsxa = NULL;
  166. INT i;
  167. INT iStartPage;
  168. TCHAR szStartPage[MAX_PATH];
  169. ZeroInit(&psh, sizeof(psh));
  170. if (SUCCEEDED(hrOle))
  171. {
  172. HRESULT hr = CoInitializeSecurity(NULL, -1, NULL, NULL, RPC_C_AUTHN_LEVEL_CONNECT, RPC_C_IMP_LEVEL_IMPERSONATE, NULL, EOAC_NONE, 0);
  173. }
  174. LinkWindow_RegisterClass();
  175. psh.dwSize = sizeof(PROPSHEETHEADER);
  176. psh.dwFlags = 0;
  177. psh.hwndParent = hwnd;
  178. psh.hInstance = hInstance;
  179. psh.pszCaption = MAKEINTRESOURCE(IDS_TITLE);
  180. psh.phpage = hPages;
  181. for (i = 0; i < ARRAYSIZE(c_pspCB); i++)
  182. {
  183. hPages[iPage] = c_pspCB[i].pfnCreatePage(c_pspCB[i].idd, c_pspCB[i].pfnDlgProc);
  184. if (hPages[iPage] != NULL)
  185. {
  186. iPage++;
  187. }
  188. }
  189. psh.nPages = iPage;
  190. // add any extra property pages from the shell ext hooks in the registry
  191. // 8 extensions should be enough. Desk.cpl also does the same.
  192. hpsxa = SHCreatePropSheetExtArray( HKEY_LOCAL_MACHINE, REGSTR_PATH_CONTROLSFOLDER TEXT("\\System"), 8 );
  193. if (hpsxa != NULL )
  194. SHAddFromPropSheetExtArray( hpsxa, _AddPropSheetPage, (LPARAM)&psh );
  195. szStartPage[0] = 0;
  196. _GetStartingPage(lpCmdLine, &psh, &iStartPage, szStartPage, ARRAYSIZE(szStartPage));
  197. if (szStartPage[0])
  198. {
  199. psh.dwFlags |= PSH_USEPSTARTPAGE;
  200. psh.pStartPage = szStartPage;
  201. }
  202. else
  203. {
  204. psh.nStartPage = iStartPage;
  205. }
  206. if (PropertySheet (&psh) == ID_PSREBOOTSYSTEM)
  207. {
  208. RestartDialogEx(hwnd, NULL, EWX_REBOOT, SHTDN_REASON_MAJOR_SYSTEM | SHTDN_REASON_MINOR_RECONFIG | SHTDN_REASON_FLAG_PLANNED);
  209. }
  210. if (hpsxa != NULL)
  211. SHDestroyPropSheetExtArray(hpsxa);
  212. LinkWindow_UnregisterClass(hInstance);
  213. }
  214. }
  215. if (SUCCEEDED(hrOle))
  216. {
  217. CoUninitialize();
  218. }
  219. }
  220. BOOL CALLBACK _AddPropSheetPage(HPROPSHEETPAGE hpage, LPARAM lParam)
  221. {
  222. PROPSHEETHEADER FAR * ppsh = (PROPSHEETHEADER FAR *)lParam;
  223. if( hpage && ( ppsh->nPages < MAX_PAGES ) )
  224. {
  225. ppsh->phpage[ppsh->nPages++] = hpage;
  226. return TRUE;
  227. }
  228. return FALSE;
  229. }
  230. void _GetStartingPage(IN LPTSTR lpCmdLine, IN PROPSHEETHEADER* ppsh, INT* piStartPage, LPTSTR pszStartPage, INT cchStartPage)
  231. {
  232. *piStartPage = 0;
  233. if (lpCmdLine && *lpCmdLine)
  234. {
  235. if (!StrToIntEx(lpCmdLine, STIF_DEFAULT, piStartPage) &&
  236. (*lpCmdLine == TEXT('@')))
  237. {
  238. LPTSTR pszComma = StrChr(lpCmdLine, TEXT(','));
  239. if (pszComma)
  240. {
  241. HINSTANCE hInstance;
  242. *pszComma = 0;
  243. hInstance = LoadLibrary(lpCmdLine + 1);
  244. if (hInstance)
  245. {
  246. UINT idResource = StrToInt(++pszComma);
  247. LoadString(hInstance, idResource, pszStartPage, cchStartPage);
  248. FreeLibrary(hInstance);
  249. }
  250. }
  251. }
  252. }
  253. }