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.

512 lines
13 KiB

  1. /*++
  2. Copyright (c) 2000 Microsoft Corporation
  3. Module Name:
  4. tabletpc.c
  5. Abstract: Tablet PC Control Panel applet main module.
  6. Environment:
  7. User mode
  8. Author:
  9. Michael Tsang (MikeTs) 20-Apr-2000
  10. Revision History:
  11. --*/
  12. #include "pch.h"
  13. HINSTANCE ghInstance = NULL;
  14. RPC_BINDING_HANDLE ghBinding = NULL;
  15. #ifdef SYSACC
  16. HANDLE ghSysAcc = INVALID_HANDLE_VALUE;
  17. HFONT ghFont = NULL;
  18. #endif
  19. TCHAR gtszTitle[64] = {0};
  20. UINT uHelpMessage = 0;
  21. TABLETPC_PROPPAGE TabletPCPropPages[] =
  22. {
  23. #ifdef PENPAGE
  24. MAKEINTRESOURCE(IDD_MUTOHPEN), MutohPenDlgProc, 0,
  25. #endif
  26. #ifdef BUTTONPAGE
  27. MAKEINTRESOURCE(IDD_BUTTONS), ButtonsDlgProc, 0,
  28. #endif
  29. MAKEINTRESOURCE(IDD_DISPLAY), DisplayDlgProc, 0,
  30. MAKEINTRESOURCE(IDD_GESTURE), GestureDlgProc, 0,
  31. #ifdef DEBUG
  32. MAKEINTRESOURCE(IDD_TUNING), TuningDlgProc, 0,
  33. #endif
  34. #ifdef BATTINFO
  35. MAKEINTRESOURCE(IDD_BATTERY), BatteryDlgProc, 0,
  36. #endif
  37. #ifdef CHGRINFO
  38. MAKEINTRESOURCE(IDD_CHARGER), ChargerDlgProc, 0,
  39. #endif
  40. #ifdef TMPINFO
  41. MAKEINTRESOURCE(IDD_TEMPERATURE), TemperatureDlgProc, 0,
  42. #endif
  43. 0, NULL, 0
  44. };
  45. #define MAX_PAGES (sizeof(TabletPCPropPages)/sizeof(TABLETPC_PROPPAGE))
  46. /*++
  47. @doc EXTERNAL
  48. @func BOOL | DllInitialize |
  49. Library entry point.
  50. @parm IN HINSTANCE | hDLLInstance | Instance handle.
  51. @parm IN DWORD | dwReason | Reason being called.
  52. @parm IN LPVOID | lpvReserved | Reserved (Unused).
  53. @rvalue SUCCESS | always returns TRUE
  54. --*/
  55. BOOL WINAPI
  56. DllInitialize(
  57. IN HINSTANCE hDLLInstance,
  58. IN DWORD dwReason,
  59. IN LPVOID lpvReserved OPTIONAL
  60. )
  61. {
  62. UNREFERENCED_PARAMETER(lpvReserved);
  63. switch (dwReason)
  64. {
  65. case DLL_PROCESS_ATTACH:
  66. ghInstance = hDLLInstance;
  67. LoadString(ghInstance,
  68. IDS_TITLE,
  69. gtszTitle,
  70. sizeof(gtszTitle)/sizeof(TCHAR));
  71. DisableThreadLibraryCalls(ghInstance);
  72. break;
  73. case DLL_PROCESS_DETACH:
  74. break;
  75. }
  76. return TRUE;
  77. } //DllInitialize
  78. /*++
  79. @doc EXTERNAL
  80. @func LONG | CPlApplet |
  81. Library-defined callback function that serves as the entry point
  82. for a Control Panel application.
  83. @parm IN HHWN | hwnd | Main window handle.
  84. @parm IN UINT | uMsg | Message.
  85. @parm IN LONG | lParam1 | Message specific parameter 1.
  86. @parm IN LONG | lParam2 | Message specific parameter 2.
  87. @rvalue Return value depends on the message.
  88. --*/
  89. LONG APIENTRY
  90. CPlApplet(
  91. IN HWND hwnd,
  92. IN UINT uMsg,
  93. IN LONG lParam1,
  94. IN LONG lParam2
  95. )
  96. {
  97. TRACEPROC("CPlApplet", 1)
  98. LONG rc = 0;
  99. TRACEENTER(("(hwnd=%p,Msg=%s,Param1=%x,Param2=%x)\n",
  100. hwnd, LookupName(uMsg, CPLMsgNames), lParam1, lParam2));
  101. switch (uMsg)
  102. {
  103. case CPL_INIT:
  104. TRACEINIT(MODNAME, 0, 0);
  105. uHelpMessage = RegisterWindowMessage(TEXT("ShellHelp"));
  106. rc = (LONG)TRUE;
  107. break;
  108. case CPL_GETCOUNT:
  109. rc = 1;
  110. break;
  111. case CPL_INQUIRE:
  112. {
  113. LPCPLINFO CPLInfo = (LPCPLINFO)lParam2;
  114. CPLInfo->idIcon = IDI_TABLETPC;
  115. CPLInfo->idName = IDS_NAME;
  116. CPLInfo->idInfo = IDS_INFO;
  117. CPLInfo->lData = 0;
  118. rc = (LONG)TRUE;
  119. break;
  120. }
  121. case CPL_NEWINQUIRE:
  122. {
  123. LPNEWCPLINFO NewCPLInfo = (LPNEWCPLINFO)lParam2;
  124. memset(NewCPLInfo, 0, sizeof(NEWCPLINFO));
  125. NewCPLInfo->dwSize = sizeof(NEWCPLINFO);
  126. NewCPLInfo->hIcon = LoadIcon(ghInstance,
  127. MAKEINTRESOURCE(IDI_TABLETPC));
  128. LoadString(ghInstance,
  129. IDS_NAME,
  130. NewCPLInfo->szName,
  131. sizeof(NewCPLInfo->szName)/sizeof(TCHAR));
  132. LoadString(ghInstance,
  133. IDS_INFO,
  134. NewCPLInfo->szInfo,
  135. sizeof(NewCPLInfo->szInfo)/sizeof(TCHAR));
  136. lstrcpy(NewCPLInfo->szHelpFile, TEXT(""));
  137. rc = (LONG)TRUE;
  138. break;
  139. }
  140. case CPL_DBLCLK:
  141. lParam2 = 0L;
  142. //
  143. // Fall through ...
  144. //
  145. case CPL_STARTWPARMS:
  146. {
  147. HWND hwndMe;
  148. if (!(gtszTitle[0]))
  149. {
  150. LoadString(ghInstance,
  151. IDS_TITLE,
  152. gtszTitle,
  153. sizeof(gtszTitle)/sizeof(TCHAR));
  154. }
  155. hwndMe = FindWindow(TEXT("#32770"), gtszTitle);
  156. if (hwndMe != NULL)
  157. {
  158. //
  159. // We found another copy running, let's just switch focus to it.
  160. //
  161. SetForegroundWindow(hwndMe);
  162. }
  163. else
  164. {
  165. rc = RunApplet(hwnd, (LPTSTR)lParam2);
  166. }
  167. break;
  168. }
  169. case CPL_STOP:
  170. break;
  171. case CPL_EXIT:
  172. #ifdef SYSACC
  173. if (ghSysAcc != INVALID_HANDLE_VALUE)
  174. {
  175. CloseHandle(ghSysAcc);
  176. ghSysAcc = INVALID_HANDLE_VALUE;
  177. }
  178. #endif
  179. TRACETERMINATE();
  180. break;
  181. }
  182. TRACEEXIT(("=%d\n", rc));
  183. return rc;
  184. } //CPlApplet
  185. /*++
  186. @doc INTERNAL
  187. @func VOID | RunApplet |
  188. The applet has been invoked.
  189. @parm IN HHWN | hwnd | Main window handle.
  190. @parm IN LPTSTR | CmdLine | Supplies the command line used to
  191. invoke the applet.
  192. @rvalue SUCCESS | Returns TRUE.
  193. @rvalue FAILURE | Returns FALSE.
  194. --*/
  195. BOOL
  196. RunApplet(
  197. IN HWND hwnd,
  198. IN LPTSTR CmdLine OPTIONAL
  199. )
  200. {
  201. TRACEPROC("RunApplet", 1)
  202. BOOL rc = FALSE;
  203. RPC_STATUS status;
  204. unsigned char *StringBinding;
  205. TRACEENTER(("(hwnd=%p,CmdLine=%s)\n", hwnd, CmdLine? CmdLine: "NULL"));
  206. if ((status = RpcStringBindingCompose(NULL,
  207. TEXT("ncalrpc"),
  208. NULL,
  209. NULL,
  210. NULL,
  211. &StringBinding)) != RPC_S_OK)
  212. {
  213. ErrorMsg(IDSERR_STRING_BINDING, status);
  214. }
  215. else if ((status = RpcBindingFromStringBinding(StringBinding, &ghBinding))
  216. != RPC_S_OK)
  217. {
  218. ErrorMsg(IDSERR_BINDING_HANDLE, status);
  219. }
  220. else if ((status = RpcBindingSetAuthInfo(ghBinding,
  221. NULL,
  222. RPC_C_AUTHN_LEVEL_NONE,
  223. RPC_C_AUTHN_WINNT,
  224. NULL,
  225. 0)) != RPC_S_OK)
  226. {
  227. ErrorMsg(IDSERR_SETAUTHO_INFO, status);
  228. }
  229. else
  230. {
  231. INITCOMMONCONTROLSEX ComCtrl;
  232. #ifdef SYSACC
  233. ghSysAcc = CreateFile(SMBLITE_IOCTL_DEVNAME,
  234. GENERIC_READ | GENERIC_WRITE,
  235. FILE_SHARE_READ | FILE_SHARE_WRITE,
  236. NULL,
  237. OPEN_EXISTING,
  238. FILE_ATTRIBUTE_NORMAL,
  239. NULL);
  240. if (ghSysAcc == INVALID_HANDLE_VALUE)
  241. {
  242. ErrorMsg(IDSERR_SYSACC_OPENDEV, GetLastError());
  243. }
  244. ghFont = GetStockObject(SYSTEM_FIXED_FONT);
  245. #endif
  246. ComCtrl.dwSize = sizeof(ComCtrl);
  247. ComCtrl.dwICC = ICC_BAR_CLASSES | ICC_USEREX_CLASSES;
  248. if (InitCommonControlsEx(&ComCtrl))
  249. {
  250. HPROPSHEETPAGE hPages[MAX_PAGES];
  251. PROPSHEETHEADER psh;
  252. psh.dwSize = sizeof(psh);
  253. psh.dwFlags = 0;
  254. psh.hwndParent = hwnd;
  255. psh.hInstance = ghInstance;
  256. psh.pszCaption = MAKEINTRESOURCE(IDS_TITLE);
  257. psh.phpage = hPages;
  258. psh.nStartPage = 0;
  259. psh.nPages = CreatePropertyPages(TabletPCPropPages, hPages);
  260. if (PropertySheet(&psh) >= 0)
  261. {
  262. rc = TRUE;
  263. }
  264. else
  265. {
  266. ErrorMsg(IDSERR_PROP_SHEET, GetLastError());
  267. }
  268. }
  269. else
  270. {
  271. ErrorMsg(IDSERR_COMMCTRL);
  272. }
  273. }
  274. TRACEEXIT(("=%x\n", rc));
  275. return rc;
  276. } //RunApplet
  277. /*++
  278. @doc INTERNAL
  279. @func VOID | CreatePropertyPages |
  280. Create all the property sheet pages according to the property
  281. page table.
  282. @parm IN PTABLETPC_PROPPAGE | TabletPCPages | Points to the property page
  283. table.
  284. @parm OUT HPROPSHEETPAGE * | hPages | Points to the array to hold all
  285. the created property sheet handles.
  286. @rvalue Returns number of property page handles created.
  287. --*/
  288. UINT
  289. CreatePropertyPages(
  290. IN PTABLETPC_PROPPAGE TabletPCPages,
  291. OUT HPROPSHEETPAGE *hPages
  292. )
  293. {
  294. TRACEPROC("CreatePropertyPages", 3)
  295. UINT nPages = 0;
  296. PROPSHEETPAGE psp;
  297. TRACEENTER(("(TabletPCPages=%p,hPages=%p)\n", TabletPCPages, hPages));
  298. psp.dwSize = sizeof(psp);
  299. psp.dwFlags = 0;
  300. psp.hInstance = ghInstance;
  301. psp.pszTitle = NULL;
  302. psp.lParam = 0;
  303. while (TabletPCPages->DlgTemplate != NULL)
  304. {
  305. psp.pszTemplate = TabletPCPages->DlgTemplate;
  306. psp.pfnDlgProc = TabletPCPages->DlgProc;
  307. TabletPCPages->hPropSheetPage = CreatePropertySheetPage(&psp);
  308. if (TabletPCPages->hPropSheetPage != NULL)
  309. {
  310. hPages[nPages] = TabletPCPages->hPropSheetPage;
  311. nPages++;
  312. }
  313. TabletPCPages++;
  314. }
  315. TRACEEXIT(("=%d\n", nPages));
  316. return nPages;
  317. } //CreatePropertyPages
  318. /*++
  319. @doc INTERNAL
  320. @func VOID | InsertComboBoxStrings |
  321. Insert the strings into the given combo box.
  322. @parm IN HWND | hwnd | Dialog handle.
  323. @parm IN UINT | ComboBoxID | The ID of the combo box.
  324. @parm IN PCOMBOBOX_STRING | ComboString | Points to the combo box
  325. string table.
  326. @rvalue None.
  327. --*/
  328. VOID
  329. InsertComboBoxStrings(
  330. IN HWND hwnd,
  331. IN UINT ComboBoxID,
  332. IN PCOMBOBOX_STRING ComboString
  333. )
  334. {
  335. TRACEPROC("InsertComboBoxStrings", 3)
  336. TCHAR tszStringText[64];
  337. TRACEENTER(("(hwnd=%x,ComboBoxID=%x,ComboStringTable=%p)\n",
  338. hwnd, ComboBoxID, ComboString));
  339. SendDlgItemMessage(hwnd, ComboBoxID, CB_RESETCONTENT, 0, 0);
  340. while (ComboString->StringID != 0)
  341. {
  342. LoadString(ghInstance,
  343. ComboString->StringID,
  344. tszStringText,
  345. sizeof(tszStringText)/sizeof(TCHAR));
  346. SendDlgItemMessage(hwnd,
  347. ComboBoxID,
  348. CB_INSERTSTRING,
  349. ComboString->StringIndex,
  350. (LPARAM)tszStringText);
  351. ComboString++;
  352. }
  353. TRACEEXIT(("!\n"));
  354. return;
  355. } //InsertComboBoxStrings
  356. /*****************************************************************************
  357. *
  358. * @doc INTERNAL
  359. *
  360. * @func VOID | EnableDlgControls | Enable dialog controls.
  361. *
  362. * @parm IN HWND | hwnd | Window handle.
  363. * @parm IN int * | piControls | Points to the dialog control array.
  364. * @parm IN BOOL | fEnable | TRUE if enable.
  365. *
  366. * @rvalue None.
  367. *
  368. *****************************************************************************/
  369. VOID
  370. EnableDlgControls(
  371. IN HWND hwnd,
  372. IN int *piControls,
  373. IN BOOL fEnable
  374. )
  375. {
  376. TRACEPROC("EnableDlgControls", 2)
  377. TRACEENTER(("(hwnd=%x,piControls=%p,fEnable=%x)\n",
  378. hwnd, piControls, fEnable));
  379. while (*piControls != 0)
  380. {
  381. EnableWindow(GetDlgItem(hwnd, *piControls), fEnable);
  382. piControls++;
  383. }
  384. TRACEEXIT(("!\n"));
  385. return;
  386. } //EnableDlgControls
  387. /*++
  388. @doc EXTERNAL
  389. @func void __RPC_FAR * | MIDL_user_allocate | MIDL allocate.
  390. @parm IN size_t | len | size of allocation.
  391. @rvalue SUCCESS | Returns the pointer to the memory allocated.
  392. @rvalue FAILURE | Returns NULL.
  393. --*/
  394. void __RPC_FAR * __RPC_USER
  395. MIDL_user_allocate(
  396. IN size_t len
  397. )
  398. {
  399. TRACEPROC("MIDL_user_allocate", 5)
  400. void __RPC_FAR *ptr;
  401. TRACEENTER(("(len=%d)\n", len));
  402. ptr = malloc(len);
  403. TRACEEXIT(("=%p\n", ptr));
  404. return ptr;
  405. } //MIDL_user_allocate
  406. /*++
  407. @doc EXTERNAL
  408. @func void | MIDL_user_free | MIDL free.
  409. @parm IN void __PRC_FAR * | ptr | Points to the memory to be freed.
  410. @rvalue None.
  411. --*/
  412. void __RPC_USER
  413. MIDL_user_free(
  414. IN void __RPC_FAR *ptr
  415. )
  416. {
  417. TRACEPROC("MIDL_user_free", 5)
  418. TRACEENTER(("(ptr=%p)\n", ptr));
  419. free(ptr);
  420. TRACEEXIT(("!\n"));
  421. return;
  422. } //MIDL_user_free