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.

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