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.

335 lines
7.8 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_ATTACH) {
  59. return TRUE;
  60. }
  61. hInstance = hInstDLL;
  62. return TRUE;
  63. }
  64. LONG
  65. APIENTRY
  66. CPlApplet(
  67. IN HWND hwnd,
  68. IN WORD wMsg,
  69. IN LPARAM lParam1,
  70. IN LPARAM lParam2
  71. )
  72. /*++
  73. Routine Description:
  74. Control Panel Applet entry point.
  75. Arguments:
  76. hwnd -
  77. Supplies window handle.
  78. wMsg -
  79. Supplies message being sent.
  80. lParam1 -
  81. Supplies parameter to message.
  82. lParam2 -
  83. Supplies parameter to message.
  84. Return Value:
  85. Nonzero if message was handled.
  86. Zero if message was unhandled.
  87. --*/
  88. {
  89. LPCPLINFO lpCPlInfo;
  90. switch (wMsg) {
  91. case CPL_INIT:
  92. uiShellHelp = RegisterWindowMessage (szShellHelp);
  93. LoadString( hInstance, IDS_INSUFFICIENT_MEMORY, g_szErrMem, ARRAYSIZE( g_szErrMem ) );
  94. LoadString( hInstance, IDS_SYSDM_TITLE, g_szSystemApplet, ARRAYSIZE( g_szSystemApplet ) );
  95. return (LONG) TRUE;
  96. case CPL_GETCOUNT:
  97. return 1;
  98. case CPL_INQUIRE:
  99. lpCPlInfo = (LPCPLINFO)lParam2;
  100. lpCPlInfo->idIcon = ID_ICON;
  101. lpCPlInfo->idName = IDS_NAME;
  102. lpCPlInfo->idInfo = IDS_INFO;
  103. return (LONG) TRUE;
  104. case CPL_DBLCLK:
  105. lParam2 = 0L;
  106. // fall through...
  107. case CPL_STARTWPARMS:
  108. RunApplet(hwnd, (LPTSTR)lParam2);
  109. return (LONG) TRUE;
  110. }
  111. return (LONG)0;
  112. }
  113. HPROPSHEETPAGE CreatePage(int idd, DLGPROC pfnDlgProc)
  114. {
  115. PROPSHEETPAGE psp;
  116. psp.dwSize = sizeof(psp);
  117. psp.dwFlags = PSP_DEFAULT;
  118. psp.hInstance = hInstance;
  119. psp.pszTemplate = MAKEINTRESOURCE(idd);
  120. psp.pfnDlgProc = pfnDlgProc;
  121. return CreatePropertySheetPage(&psp);
  122. }
  123. static const PSPINFO c_pspCB[] =
  124. {
  125. { CreatePage, IDD_GENERAL, GeneralDlgProc },
  126. { CreateNetIDPage, 0, NULL },
  127. { CreatePage, IDD_HARDWARE, HardwareDlgProc },
  128. { CreatePage, IDD_ADVANCED, AdvancedDlgProc },
  129. { CreateSystemRestorePage, 0, NULL },
  130. };
  131. void
  132. RunApplet(
  133. IN HWND hwnd,
  134. IN LPTSTR lpCmdLine
  135. )
  136. /*++
  137. Routine Description:
  138. CPL_STARTWPARMS message handler. Called when the user
  139. runs the Applet.
  140. PropSheet initialization occurs here.
  141. Arguments:
  142. hwnd -
  143. Supplies window handle.
  144. lpCmdLine -
  145. Supplies the command line used to invoke the applet.
  146. Return Value:
  147. none
  148. --*/
  149. {
  150. HRESULT hrOle = CoInitialize(0);
  151. if (!SHRestricted(REST_MYCOMPNOPROP))
  152. {
  153. if (lpCmdLine && *lpCmdLine && !lstrcmp(lpCmdLine, TEXT("-1")))
  154. {
  155. // -1 means Performance Options cpl
  156. DoPerformancePS(NULL);
  157. }
  158. else
  159. {
  160. HPROPSHEETPAGE hPages[MAX_PAGES];
  161. PROPSHEETHEADER psh;
  162. UINT iPage = 0;
  163. HPSXA hpsxa = NULL;
  164. INT i;
  165. INT iStartPage;
  166. TCHAR szStartPage[MAX_PATH];
  167. ZeroMemory(&psh, sizeof(psh));
  168. if (SUCCEEDED(hrOle))
  169. {
  170. // this call is needed to allow the WMI calls to get the processor information
  171. CoInitializeSecurity(NULL, -1, NULL, NULL, RPC_C_AUTHN_LEVEL_CONNECT, RPC_C_IMP_LEVEL_IMPERSONATE,
  172. 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 hInstanceDLL;
  242. *pszComma = 0;
  243. hInstanceDLL = LoadLibrary(lpCmdLine + 1);
  244. if (hInstanceDLL)
  245. {
  246. UINT idResource = StrToInt(++pszComma);
  247. LoadString(hInstanceDLL, idResource, pszStartPage, cchStartPage);
  248. FreeLibrary(hInstanceDLL);
  249. }
  250. }
  251. }
  252. }
  253. }