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.

217 lines
4.0 KiB

  1. /*++
  2. Copyright (c) 1994-1998, Microsoft Corporation All rights reserved.
  3. Module Name:
  4. keybd.c
  5. Abstract:
  6. This module contains the main routines for the Keyboard applet.
  7. Revision History:
  8. --*/
  9. //
  10. // Include Files.
  11. //
  12. #include "main.h"
  13. #include "rc.h"
  14. #include "applet.h"
  15. #include <regstr.h>
  16. #include <cplext.h>
  17. #include "util.h"
  18. #include <intlid.h>
  19. //
  20. // Constant Declarations.
  21. //
  22. #define MAX_PAGES 32 // limit on number of pages
  23. const HWPAGEINFO c_hpiKeybd = {
  24. // Keyboard device class
  25. { 0x4d36e96bL, 0xe325, 0x11ce, { 0xbf, 0xc1, 0x08, 0x00, 0x2b, 0xe1, 0x03, 0x18 } },
  26. // Keyboard troubleshooter command line
  27. IDS_KEYBD_TSHOOT,
  28. };
  29. //
  30. // Global Variables.
  31. //
  32. //
  33. // Location of prop sheet hooks in the registry.
  34. //
  35. static const TCHAR sc_szRegKeybd[] = REGSTR_PATH_CONTROLSFOLDER TEXT("\\Keyboard");
  36. //
  37. // Function Prototypes.
  38. //
  39. INT_PTR CALLBACK
  40. KeyboardSpdDlg(
  41. HWND hDlg,
  42. UINT message,
  43. WPARAM wParam,
  44. LPARAM lParam);
  45. ////////////////////////////////////////////////////////////////////////////
  46. //
  47. // _AddKeybdPropSheetPage
  48. //
  49. // Adds a property sheet page.
  50. //
  51. ////////////////////////////////////////////////////////////////////////////
  52. BOOL CALLBACK _AddKeybdPropSheetPage(
  53. HPROPSHEETPAGE hpage,
  54. LPARAM lParam)
  55. {
  56. PROPSHEETHEADER *ppsh = (PROPSHEETHEADER *)lParam;
  57. if (hpage && ppsh->nPages < MAX_PAGES)
  58. {
  59. ppsh->phpage[ppsh->nPages++] = hpage;
  60. return (TRUE);
  61. }
  62. return (FALSE);
  63. }
  64. ////////////////////////////////////////////////////////////////////////////
  65. //
  66. // KeybdApplet
  67. //
  68. ////////////////////////////////////////////////////////////////////////////
  69. int KeybdApplet(
  70. HINSTANCE instance,
  71. HWND parent,
  72. LPCTSTR cmdline)
  73. {
  74. HPROPSHEETPAGE rPages[MAX_PAGES];
  75. PROPSHEETPAGE psp;
  76. PROPSHEETHEADER psh;
  77. HPSXA hpsxa;
  78. int Result;
  79. HINSTANCE hInst;
  80. //
  81. // Make the initial page.
  82. //
  83. psh.dwSize = sizeof(psh);
  84. psh.dwFlags = PSH_PROPTITLE;
  85. psh.hwndParent = parent;
  86. psh.hInstance = instance;
  87. psh.pszCaption = MAKEINTRESOURCE(IDS_KEYBD_TITLE);
  88. psh.nPages = 0;
  89. if (cmdline)
  90. {
  91. psh.nStartPage = lstrlen(cmdline) ? StrToLong(cmdline) : 0;
  92. }
  93. else
  94. {
  95. psh.nStartPage = 0;
  96. }
  97. psh.phpage = rPages;
  98. //
  99. // Load any installed extensions.
  100. //
  101. hpsxa = SHCreatePropSheetExtArray(HKEY_LOCAL_MACHINE, sc_szRegKeybd, 8);
  102. //
  103. // Add the Speed page.
  104. //
  105. psp.dwSize = sizeof(psp);
  106. psp.dwFlags = PSP_DEFAULT;
  107. psp.hInstance = instance;
  108. psp.pszTemplate = MAKEINTRESOURCE(DLG_KEYBD_SPEED);
  109. psp.pfnDlgProc = KeyboardSpdDlg;
  110. psp.lParam = 0;
  111. _AddKeybdPropSheetPage(CreatePropertySheetPage(&psp), (LPARAM)&psh);
  112. //
  113. // Add the Hardware page (not replaceable).
  114. //
  115. _AddKeybdPropSheetPage(CreateHardwarePage(&c_hpiKeybd), (LPARAM)&psh);
  116. //
  117. // Add any extra pages that the extensions want in there.
  118. //
  119. if (hpsxa)
  120. {
  121. UINT cutoff = psh.nPages;
  122. UINT added = SHAddFromPropSheetExtArray( hpsxa,
  123. _AddKeybdPropSheetPage,
  124. (LPARAM)&psh );
  125. if (psh.nStartPage >= cutoff)
  126. {
  127. psh.nStartPage += added;
  128. }
  129. }
  130. //
  131. // Invoke the Property Sheets.
  132. //
  133. switch (PropertySheet(&psh))
  134. {
  135. case ( ID_PSRESTARTWINDOWS ) :
  136. {
  137. Result = APPLET_RESTART;
  138. break;
  139. }
  140. case ( ID_PSREBOOTSYSTEM ) :
  141. {
  142. Result = APPLET_REBOOT;
  143. break;
  144. }
  145. default :
  146. {
  147. Result = 0;
  148. break;
  149. }
  150. }
  151. //
  152. // Free any loaded extensions.
  153. //
  154. if (hpsxa)
  155. {
  156. SHDestroyPropSheetExtArray(hpsxa);
  157. }
  158. //
  159. // Free the library loaded for the external page.
  160. //
  161. if (hInst)
  162. {
  163. FreeLibrary(hInst);
  164. }
  165. return (Result);
  166. }