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.

366 lines
7.3 KiB

  1. /*++
  2. Copyright (c) 1994-1998, Microsoft Corporation All rights reserved.
  3. Module Name:
  4. main.c
  5. Abstract:
  6. This module contains the main routines for the Control Panel
  7. interface of the 32bit MAIN.CPL.
  8. Revision History:
  9. --*/
  10. //
  11. // Include Files.
  12. //
  13. #include "main.h"
  14. #include "rc.h"
  15. #include "applet.h"
  16. #include "mousectl.h"
  17. #include "drvaplet.h"
  18. #define SZ_DEBUGINI "maincpl.ini"
  19. #define SZ_MODULE "main"
  20. #define SZ_DEBUGSECTION "debug"
  21. #define DECLARE_DEBUG
  22. #include <ccstock.h>
  23. #include <debug.h>
  24. //
  25. // Global Variables.
  26. //
  27. #ifdef WINNT
  28. HINSTANCE g_hInst = NULL;
  29. #else
  30. #pragma data_seg(".idata")
  31. HINSTANCE g_hInst = NULL;
  32. #pragma data_seg()
  33. #endif
  34. //
  35. // Externally Defined Applets.
  36. //
  37. int MouseApplet(HINSTANCE, HWND, LPCTSTR); // mouse.c
  38. int KeybdApplet(HINSTANCE, HWND, LPCTSTR); // keybd.c
  39. BOOL RegisterPointerStuff(HINSTANCE); // from mouseptr.c
  40. //
  41. // Typedef Declarations.
  42. //
  43. typedef struct
  44. {
  45. int idIcon;
  46. int idTitle;
  47. int idExplanation;
  48. PFNAPPLETQUERY pfnAppletQuery;
  49. PFNAPPLET pfnApplet;
  50. LPCTSTR szDriver;
  51. } APPLET;
  52. APPLET Applets[] =
  53. {
  54. { IDI_MOUSE, IDS_MOUSE_TITLE, IDS_MOUSE_EXPLAIN, NULL, MouseApplet, TEXT("MOUSE") },
  55. { IDI_KEYBD, IDS_KEYBD_TITLE, IDS_KEYBD_EXPLAIN, NULL, KeybdApplet, NULL },
  56. };
  57. #define NUM_APPLETS (sizeof(Applets) / sizeof(Applets[0]))
  58. int cApplets = NUM_APPLETS;
  59. ////////////////////////////////////////////////////////////////////////////
  60. //
  61. // LibMain
  62. //
  63. ////////////////////////////////////////////////////////////////////////////
  64. BOOL APIENTRY LibMain(
  65. HINSTANCE hDll,
  66. DWORD dwReason,
  67. LPVOID lpReserved)
  68. {
  69. switch (dwReason)
  70. {
  71. case ( DLL_PROCESS_ATTACH ) :
  72. {
  73. g_hInst = hDll;
  74. DisableThreadLibraryCalls(hDll);
  75. SHFusionInitializeFromModuleID(hDll, 124);
  76. break;
  77. }
  78. case ( DLL_PROCESS_DETACH ) :
  79. {
  80. SHFusionUninitialize();
  81. break;
  82. }
  83. case ( DLL_THREAD_ATTACH ) :
  84. case ( DLL_THREAD_DETACH ) :
  85. {
  86. break;
  87. }
  88. }
  89. return (TRUE);
  90. }
  91. ////////////////////////////////////////////////////////////////////////////
  92. //
  93. // CplInit
  94. //
  95. // Called when a CPL consumer initializes a CPL.
  96. //
  97. ////////////////////////////////////////////////////////////////////////////
  98. LRESULT CplInit(
  99. HWND hParent)
  100. {
  101. int i;
  102. InitCommonControls();
  103. RegisterPointerStuff(g_hInst);
  104. RegisterMouseControlStuff(g_hInst);
  105. for (i = 0; i < cApplets; i++)
  106. {
  107. if ((Applets[i].pfnAppletQuery != NULL) &&
  108. ((*Applets[i].pfnAppletQuery)(hParent, APPLET_QUERY_EXISTS) == FALSE))
  109. {
  110. cApplets--;
  111. if (i != cApplets)
  112. {
  113. Applets[i] = Applets[cApplets];
  114. }
  115. i--;
  116. }
  117. }
  118. return (TRUE);
  119. }
  120. ////////////////////////////////////////////////////////////////////////////
  121. //
  122. // CplExit
  123. //
  124. // Called when a CPL consumer is done with a CPL.
  125. //
  126. ////////////////////////////////////////////////////////////////////////////
  127. void CplExit(void)
  128. {
  129. }
  130. ////////////////////////////////////////////////////////////////////////////
  131. //
  132. // CplInquire
  133. //
  134. // Called when a CPL consumer wants info about an applet.
  135. //
  136. ////////////////////////////////////////////////////////////////////////////
  137. LRESULT CplInquire(
  138. LPCPLINFO info,
  139. int iApplet)
  140. {
  141. APPLET *applet = Applets + iApplet;
  142. HMODULE hDriverApplet = NULL;
  143. info->idIcon = applet->idIcon;
  144. if (applet->szDriver) {
  145. if (hDriverApplet = GetDriverModule(applet->szDriver)) {
  146. info->idIcon = CPL_DYNAMIC_RES;
  147. ReleaseDriverModule(hDriverApplet);
  148. } // if (hDriverApplet = ...
  149. } // if (applet->szDriver)
  150. info->idName = applet->idTitle;
  151. info->idInfo = applet->idExplanation;
  152. info->lData = 0L;
  153. return (1L);
  154. }
  155. ////////////////////////////////////////////////////////////////////////////
  156. //
  157. // CplNewInquire
  158. //
  159. // Called when a CPL consumer wants info about an applet.
  160. //
  161. ////////////////////////////////////////////////////////////////////////////
  162. LRESULT CplNewInquire(
  163. HWND parent,
  164. LPNEWCPLINFO info,
  165. int iApplet)
  166. {
  167. APPLET *applet = Applets + iApplet;
  168. HDAP hdap;
  169. info->dwSize = sizeof(NEWCPLINFO);
  170. info->hIcon = NULL;
  171. //
  172. // See if the applet is associated with a driver which can provide us
  173. // an icon.
  174. //
  175. if ((applet->szDriver) &&
  176. ((hdap = OpenDriverApplet(applet->szDriver)) != NULL))
  177. {
  178. info->hIcon = GetDriverAppletIcon(hdap);
  179. CloseDriverApplet(hdap);
  180. }
  181. if ((!info->hIcon) && (applet->pfnAppletQuery != NULL))
  182. {
  183. info->hIcon = (HICON)(*(applet->pfnAppletQuery))( parent,
  184. APPLET_QUERY_GETICON );
  185. }
  186. if (!info->hIcon)
  187. {
  188. info->hIcon = LoadIcon(g_hInst, MAKEINTRESOURCE(applet->idIcon));
  189. }
  190. LoadString(g_hInst, applet->idTitle, info->szName, sizeof(info->szName));
  191. LoadString(g_hInst, applet->idExplanation, info->szInfo, sizeof(info->szInfo));
  192. info->lData = 0L;
  193. *info->szHelpFile = 0;
  194. info->dwHelpContext = 0UL;
  195. return (1L);
  196. }
  197. ////////////////////////////////////////////////////////////////////////////
  198. //
  199. // CplInvoke
  200. //
  201. // Called to invoke an applet. It checks the applet's return value to see
  202. // if we need to restart.
  203. //
  204. ////////////////////////////////////////////////////////////////////////////
  205. LRESULT CplInvoke(
  206. HWND parent,
  207. int iApplet,
  208. LPCTSTR cmdline)
  209. {
  210. DWORD exitparam = 0UL;
  211. DWORD dwExitReason = SHTDN_REASON_FLAG_PLANNED |
  212. SHTDN_REASON_MAJOR_OPERATINGSYSTEM |
  213. SHTDN_REASON_MINOR_RECONFIG;
  214. switch (Applets[iApplet].pfnApplet(g_hInst, parent, cmdline))
  215. {
  216. case ( APPLET_RESTART ) :
  217. {
  218. exitparam = EW_RESTARTWINDOWS;
  219. break;
  220. }
  221. case ( APPLET_REBOOT ) :
  222. {
  223. exitparam = EW_REBOOTSYSTEM;
  224. break;
  225. }
  226. default :
  227. {
  228. return (1L);
  229. }
  230. }
  231. RestartDialogEx(parent, NULL, exitparam, dwExitReason);
  232. return (1L);
  233. }
  234. ////////////////////////////////////////////////////////////////////////////
  235. //
  236. // CplApplet
  237. //
  238. // A CPL consumer calls this to request stuff from us.
  239. //
  240. ////////////////////////////////////////////////////////////////////////////
  241. LRESULT APIENTRY CPlApplet(
  242. HWND parent,
  243. UINT msg,
  244. LPARAM lparam1,
  245. LPARAM lparam2)
  246. {
  247. switch (msg)
  248. {
  249. case ( CPL_INIT ) :
  250. {
  251. return (CplInit(parent));
  252. }
  253. case ( CPL_EXIT ) :
  254. {
  255. CplExit();
  256. break;
  257. }
  258. case ( CPL_GETCOUNT ) :
  259. {
  260. return (cApplets);
  261. }
  262. case ( CPL_INQUIRE ) :
  263. {
  264. return (CplInquire((LPCPLINFO)lparam2, (int)lparam1));
  265. }
  266. case ( CPL_NEWINQUIRE ) :
  267. {
  268. return (CplNewInquire(parent, (LPNEWCPLINFO)lparam2, (int)lparam1));
  269. }
  270. case ( CPL_DBLCLK ) :
  271. {
  272. lparam2 = 0L;
  273. // fall through...
  274. }
  275. case ( CPL_STARTWPARMS ) :
  276. {
  277. return (CplInvoke(parent, (int)lparam1, (LPTSTR)lparam2));
  278. }
  279. }
  280. return (0L);
  281. }