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.

262 lines
6.9 KiB

  1. /** FILE: cpl.c ************ Module Header ********************************
  2. *
  3. * Initialization module and UPS Control Panel applet procedure.
  4. * Additionally, this file also contains the "CPlApplet" procedure which
  5. * complies with and services the ".CPL" protocol between the Control
  6. * Panel main window procedure and its' applets.
  7. *
  8. * History:
  9. * 12:30 on Tues 23 Apr 1991 -by- Steve Cathcart [stevecat]
  10. * Took base code from Win 3.1 source
  11. * 10:30 on Tues 04 Feb 1992 -by- Steve Cathcart [stevecat]
  12. * Updated code to latest Win 3.1 sources
  13. * 10:00 on Thur Aug 27 1992 -by- Congpa You [congpay]
  14. * Specialize the code for UPS.
  15. ***************************************************************************/
  16. //==========================================================================
  17. // Include files
  18. //==========================================================================
  19. #include "ups.h"
  20. #include "cpl.h"
  21. //==========================================================================
  22. // Local Definitions
  23. //==========================================================================
  24. typedef struct {
  25. int idIcon;
  26. int idName;
  27. int idInfo;
  28. int idChild;
  29. BOOL bEnabled;
  30. DWORD dwContext;
  31. PSTR pszHelp;
  32. } APPLET_INFO;
  33. //==========================================================================
  34. // External Declarations
  35. //==========================================================================
  36. /* functions */
  37. extern INT_PTR APIENTRY UPSDlg (HWND, UINT, WPARAM, LPARAM);
  38. extern BOOL RegisterArrowClass(HANDLE);
  39. //==========================================================================
  40. // Data Declarations
  41. //==========================================================================
  42. HANDLE hModule = NULL;
  43. char szSetupInfPath[PATHMAX];
  44. char szErrLS[133];
  45. char szErrMem[133];
  46. char szCtlPanel[30];
  47. char szWinCom[PATHMAX]; /* Path to WIN.COM directory */
  48. char szSystemIniPath[PATHMAX]; /* Path to SYSTEM.INI */
  49. char szCtlIni[PATHMAX]; /* Path to CONTROL.INI */
  50. char szCONTROLINI[] = "control.ini";
  51. // REVIEW change to lower case.
  52. char szSYSTEMINI[] = "SYSTEM.INI";
  53. char szSETUPINF[] = "SETUP.INF";
  54. DWORD dwContext = 0L;
  55. char szControlHlp[] = "control.hlp";
  56. UINT wHelpMessage;
  57. char szCplApplet[] = "CPlApplet";
  58. APPLET_INFO applets[] = {
  59. { UPSICON , CHILDREN , INFO , CHILD_UPS , TRUE,
  60. IDH_CHILD_UPS , szControlHlp },
  61. };
  62. #define NUM_APPLETS (sizeof(applets)/sizeof(applets[0]))
  63. //==========================================================================
  64. // Local Function Prototypes
  65. //==========================================================================
  66. void RunApplet(HWND hwnd, int cmd);
  67. //==========================================================================
  68. // Functions
  69. //==========================================================================
  70. // Win32 NT Dll Initialization procedure
  71. BOOL DllInitialize(
  72. IN PVOID hmod,
  73. IN ULONG ulReason,
  74. IN PCONTEXT pctx OPTIONAL)
  75. {
  76. if (ulReason != DLL_PROCESS_ATTACH)
  77. {
  78. return TRUE;
  79. }
  80. else
  81. {
  82. hModule = hmod;
  83. }
  84. return TRUE;
  85. UNREFERENCED_PARAMETER(pctx);
  86. }
  87. //---------------------------------------------------------------------------
  88. BOOL InitControlPanel(HWND hwndParent)
  89. {
  90. OFSTRUCT os;
  91. if (!RegisterArrowClass(hModule))
  92. {
  93. return FALSE;
  94. }
  95. LoadString (hModule, ERRMEM, szErrMem, sizeof (szErrMem));
  96. LoadString (hModule, LSFAIL, szErrLS, sizeof (szErrLS));
  97. LoadString (hModule, CPCAPTION, szCtlPanel, sizeof (szCtlPanel));
  98. wsprintf (szSystemIniPath, "%s%s", (LPSTR)szWinCom, (LPSTR)szSYSTEMINI);
  99. wsprintf (szCtlIni, "%s%s", (LPSTR)szWinCom, (LPSTR)szCONTROLINI);
  100. if (OpenFile (szSETUPINF, &os, OF_EXIST) >= 0)
  101. strcpy (szSetupInfPath, os.szPathName);
  102. else
  103. strcpy (szSetupInfPath, szSETUPINF); // not found, use this anyway?
  104. wHelpMessage = RegisterWindowMessage("ShellHelp");
  105. return TRUE;
  106. UNREFERENCED_PARAMETER(hwndParent);
  107. }
  108. void TermControlPanel()
  109. {
  110. UnRegisterArrowClass (hModule);
  111. return;
  112. }
  113. LONG APIENTRY CPlApplet(HWND hWnd, UINT Msg, LPARAM lParam1, LPARAM lParam2)
  114. {
  115. int i, count;
  116. LPNEWCPLINFO lpCPlInfo;
  117. LPCPLINFO lpOldCPlInfo;
  118. static iInitCount = 0;
  119. switch (Msg)
  120. {
  121. case CPL_INIT:
  122. if (!iInitCount)
  123. {
  124. if (!InitControlPanel(hWnd))
  125. return FALSE;
  126. }
  127. iInitCount++;
  128. return TRUE;
  129. case CPL_GETCOUNT:
  130. for (i = count = 0; i < NUM_APPLETS; i++)
  131. if (applets[i].bEnabled)
  132. count++;
  133. return (LONG)count;
  134. case CPL_INQUIRE:
  135. lpOldCPlInfo = (LPCPLINFO)lParam2;
  136. // find the proper applet not counting those that are disabled
  137. for (i = count = 0; i < NUM_APPLETS; i++)
  138. {
  139. if (applets[i].bEnabled)
  140. {
  141. if (count == (int)lParam1)
  142. break;
  143. count++;
  144. }
  145. }
  146. lpOldCPlInfo->idIcon = applets[i].idIcon;
  147. lpOldCPlInfo->idName = applets[i].idName;
  148. lpOldCPlInfo->idInfo = applets[i].idInfo;
  149. lpOldCPlInfo->lData = (LONG)applets[i].idChild;
  150. return TRUE;
  151. case CPL_NEWINQUIRE:
  152. lpCPlInfo = (LPNEWCPLINFO)lParam2;
  153. // find the proper applet not counting those that are disabled
  154. for (i = count = 0; i < NUM_APPLETS; i++)
  155. {
  156. if (applets[i].bEnabled)
  157. {
  158. if (count == (int)lParam1)
  159. break;
  160. count++;
  161. }
  162. }
  163. lpCPlInfo->hIcon = LoadIcon(hModule, MAKEINTRESOURCE(applets[i].idIcon));
  164. LoadString(hModule, applets[i].idName, lpCPlInfo->szName, sizeof(lpCPlInfo->szName));
  165. if (!LoadString(hModule, applets[i].idInfo, lpCPlInfo->szInfo,
  166. sizeof(lpCPlInfo->szInfo)))
  167. lpCPlInfo->szInfo[0] = 0;
  168. lpCPlInfo->dwSize = sizeof(NEWCPLINFO);
  169. lpCPlInfo->lData = (LONG)applets[i].idChild;
  170. lpCPlInfo->dwHelpContext = applets[i].dwContext;
  171. strcpy(lpCPlInfo->szHelpFile, applets[i].pszHelp);
  172. return TRUE;
  173. case CPL_DBLCLK:
  174. dwContext = applets[(int)lParam1].dwContext;
  175. RunApplet(hWnd, (int)lParam2);
  176. break;
  177. case CPL_EXIT:
  178. iInitCount--;
  179. if (!iInitCount)
  180. TermControlPanel();
  181. break;
  182. default:
  183. break;
  184. }
  185. return 0L;
  186. }
  187. void RunApplet(HWND hwnd, int cmd)
  188. {
  189. switch (cmd)
  190. {
  191. case CHILD_UPS:
  192. DialogBox(hModule, MAKEINTRESOURCE(DLG_UPS), hwnd, UPSDlg);
  193. break;
  194. }
  195. }
  196. void CPHelp (HWND hWnd)
  197. {
  198. WinHelp (hWnd, szControlHlp, HELP_CONTEXT, dwContext);
  199. }