Leaked source code of windows server 2003
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.

225 lines
5.7 KiB

  1. /*******************************************************************************
  2. *
  3. * (C) COPYRIGHT MICROSOFT CORP., 1996
  4. *
  5. * TITLE: PRSHTHLP.C
  6. *
  7. * VERSION: 2.0
  8. *
  9. * AUTHOR: ReedB
  10. *
  11. * DATE: 6 May, 1997
  12. *
  13. * DESCRIPTION:
  14. * Property sheet helper functions.
  15. *
  16. *******************************************************************************/
  17. #include <nt.h>
  18. #include <ntrtl.h>
  19. #include <nturtl.h>
  20. #include <windows.h>
  21. #include <commctrl.h>
  22. #include <shlobj.h>
  23. #include <shlobjp.h>
  24. #include <shlwapi.h>
  25. #include <help.h>
  26. #include "powercfg.h"
  27. /*******************************************************************************
  28. *
  29. * G L O B A L D A T A
  30. *
  31. *******************************************************************************/
  32. extern HINSTANCE g_hInstance; // Global instance handle of this DLL.
  33. /*******************************************************************************
  34. *
  35. * P U B L I C E N T R Y P O I N T S
  36. *
  37. *******************************************************************************/
  38. /*******************************************************************************
  39. *
  40. * AppendPropSheetPage
  41. *
  42. * DESCRIPTION:
  43. * Append a power page entry to an array of power pages.
  44. *
  45. * PARAMETERS:
  46. *
  47. *******************************************************************************/
  48. BOOL AppendPropSheetPage(
  49. PPOWER_PAGES pppArray,
  50. UINT uiDlgId,
  51. DLGPROC pfnDlgProc
  52. )
  53. {
  54. UINT i = 0;
  55. // Find the end.
  56. while (pppArray[++i].pfnDlgProc);
  57. pppArray[i].pfnDlgProc = pfnDlgProc;
  58. pppArray[i].pDlgTemplate = MAKEINTRESOURCE(uiDlgId);
  59. return TRUE;
  60. }
  61. /*******************************************************************************
  62. *
  63. * GetNumPropSheetPages
  64. *
  65. * DESCRIPTION:
  66. *
  67. * PARAMETERS:
  68. *
  69. *******************************************************************************/
  70. UINT GetNumPropSheetPages(
  71. PPOWER_PAGES pppArray
  72. )
  73. {
  74. UINT i = START_OF_PAGES;
  75. // Find the end.
  76. while (pppArray[i++].pfnDlgProc);
  77. return i - 1;
  78. }
  79. /*******************************************************************************
  80. *
  81. * _AddPowerPropSheetPage
  82. *
  83. * DESCRIPTION:
  84. * Adds optional pages for outside callers.
  85. * PARAMETERS:
  86. *
  87. *******************************************************************************/
  88. BOOL CALLBACK _AddPowerPropSheetPage(HPROPSHEETPAGE hpage, LPARAM lParam)
  89. {
  90. PROPSHEETHEADER FAR * ppsh = (PROPSHEETHEADER FAR *)lParam;
  91. if (hpage && (ppsh->nPages < MAX_PAGES )) {
  92. ppsh->phpage[ppsh->nPages++] = hpage;
  93. return TRUE;
  94. }
  95. return FALSE;
  96. }
  97. /*******************************************************************************
  98. *
  99. * DoPropSheetPages
  100. *
  101. * DESCRIPTION:
  102. * Bring up the specified property sheet pages. Return FALSE if no pages
  103. * were displayed.
  104. *
  105. * PARAMETERS:
  106. *
  107. *******************************************************************************/
  108. BOOL PASCAL DoPropSheetPages(
  109. HWND hwnd,
  110. POWER_PAGES PowerPages[],
  111. LPTSTR lpszOptionalPages
  112. )
  113. {
  114. HPROPSHEETPAGE rPages[MAX_PAGES];
  115. PROPSHEETHEADER psh;
  116. PROPSHEETPAGE psp;
  117. HPSXA hpsxa = NULL;
  118. ULONG uPage;
  119. BOOLEAN bRet = TRUE;
  120. // Fill in the sheet header
  121. psh.dwSize = sizeof(psh);
  122. psh.dwFlags = PSH_PROPTITLE;
  123. psh.hwndParent = hwnd;
  124. psh.hInstance = g_hInstance;
  125. psh.pszCaption = PowerPages[CAPTION_INDEX].pDlgTemplate;
  126. psh.nStartPage = 0;
  127. psh.nPages = 0;
  128. psh.phpage = rPages;
  129. // Fill in the page constants
  130. psp.dwSize = sizeof(PROPSHEETPAGE);
  131. psp.dwFlags = PSP_DEFAULT;
  132. psp.hInstance = g_hInstance;
  133. for (uPage = START_OF_PAGES; uPage < MAX_PAGES; uPage++) {
  134. if (PowerPages[uPage].pDlgTemplate == NULL) {
  135. break;
  136. }
  137. (PPOWER_PAGES)psp.lParam = &(PowerPages[uPage]);
  138. psp.pszTemplate = PowerPages[uPage].pDlgTemplate;
  139. psp.pfnDlgProc = PowerPages[uPage].pfnDlgProc;
  140. rPages[psh.nPages] = CreatePropertySheetPage(&psp);
  141. PowerPages[uPage].hPropSheetPage = rPages[psh.nPages];
  142. if (rPages[psh.nPages] != NULL) {
  143. psh.nPages++;
  144. }
  145. }
  146. // Add any optional pages specified in the registry.
  147. if (lpszOptionalPages) {
  148. hpsxa = SHCreatePropSheetExtArray(HKEY_LOCAL_MACHINE,
  149. lpszOptionalPages, MAX_PAGES);
  150. if (hpsxa) {
  151. SHAddFromPropSheetExtArray(hpsxa, _AddPowerPropSheetPage, (LPARAM)&psh);
  152. }
  153. }
  154. // Did we come up with any pages to show ?
  155. if (psh.nPages == 0) {
  156. return FALSE;
  157. }
  158. // Bring up the pages.
  159. if (PropertySheet(&psh) < 0) {
  160. MYDBGPRINT(( "DoPropSheetPages, PropertySheet failed, LastError: 0x%08X", GetLastError()));
  161. bRet = FALSE;
  162. }
  163. // Free any optional pages if we loaded them.
  164. if (hpsxa) {
  165. SHDestroyPropSheetExtArray(hpsxa);
  166. }
  167. return bRet;
  168. }
  169. /*******************************************************************************
  170. *
  171. * MarkSheetDirty
  172. *
  173. * DESCRIPTION:
  174. *
  175. * PARAMETERS:
  176. *
  177. *******************************************************************************/
  178. VOID MarkSheetDirty(HWND hWnd, PBOOL pb)
  179. {
  180. SendMessage(GetParent(hWnd), PSM_CHANGED, (WPARAM)hWnd, 0L);
  181. *pb = TRUE;
  182. }
  183. /*******************************************************************************
  184. *
  185. * P R I V A T E F U N C T I O N S
  186. *
  187. *******************************************************************************/