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.

238 lines
5.0 KiB

  1. /*++
  2. Copyright (c) 1994-1998, Microsoft Corporation All rights reserved.
  3. Module Name:
  4. util.c
  5. Abstract:
  6. This module contains the utility routines for this project.
  7. Revision History:
  8. --*/
  9. //
  10. // Include Files.
  11. //
  12. #include "main.h"
  13. #include "util.h"
  14. #include "rc.h"
  15. //
  16. // From shell\inc\shsemip.h
  17. //
  18. #define ARRAYSIZE(a) (sizeof(a)/sizeof(a[0]))
  19. //
  20. // Global Variables.
  21. //
  22. extern HINSTANCE g_hInst;
  23. ////////////////////////////////////////////////////////////////////////////
  24. //
  25. // HourGlass
  26. //
  27. ////////////////////////////////////////////////////////////////////////////
  28. void HourGlass(
  29. BOOL fOn)
  30. {
  31. if (!GetSystemMetrics(SM_MOUSEPRESENT))
  32. {
  33. ShowCursor(fOn);
  34. }
  35. SetCursor(LoadCursor(NULL, (fOn ? IDC_WAIT : IDC_ARROW)));
  36. }
  37. ////////////////////////////////////////////////////////////////////////////
  38. //
  39. // MyMessageBox
  40. //
  41. ////////////////////////////////////////////////////////////////////////////
  42. #ifdef WINNT
  43. int MyMessageBox(
  44. HWND hWnd,
  45. UINT uText,
  46. UINT uCaption,
  47. UINT uType,
  48. ...)
  49. {
  50. TCHAR szText[4 * PATHMAX], szCaption[2 * PATHMAX];
  51. int result;
  52. va_list parg;
  53. va_start(parg, uType);
  54. LoadString(g_hInst, uText, szCaption, ARRAYSIZE(szCaption));
  55. wvsprintf(szText, szCaption, parg);
  56. LoadString(g_hInst, uCaption, szCaption, ARRAYSIZE(szCaption));
  57. result = MessageBox(hWnd, szText, szCaption, uType);
  58. va_end(parg);
  59. return (result);
  60. }
  61. #else
  62. int MyMessageBox(
  63. HWND hWnd,
  64. UINT uText,
  65. UINT uCaption,
  66. UINT uType,
  67. ...)
  68. {
  69. TCHAR szText[256 + PATHMAX], szCaption[256];
  70. int result;
  71. LoadString(g_hInst, uText, szCaption, ARRAYSIZE(szCaption));
  72. wvsprintf(szText, szCaption, (LPTSTR)(&uType + 1));
  73. LoadString(g_hInst, uCaption, szCaption, ARRAYSIZE(szCaption));
  74. result = MessageBox(hWnd, szText, szCaption, uType);
  75. return (result);
  76. }
  77. #endif
  78. ////////////////////////////////////////////////////////////////////////////
  79. //
  80. // TrackInit
  81. //
  82. ////////////////////////////////////////////////////////////////////////////
  83. void TrackInit(
  84. HWND hwndScroll,
  85. int nCurrent,
  86. PARROWVSCROLL pAVS)
  87. {
  88. SendMessage(hwndScroll, TBM_SETRANGE, 0, MAKELONG(pAVS->bottom, pAVS->top));
  89. SendMessage(hwndScroll, TBM_SETPOS, TRUE, (LONG)nCurrent);
  90. }
  91. ////////////////////////////////////////////////////////////////////////////
  92. //
  93. // TrackMessage
  94. //
  95. ////////////////////////////////////////////////////////////////////////////
  96. int TrackMessage(
  97. WPARAM wParam,
  98. LPARAM lParam,
  99. PARROWVSCROLL pAVS)
  100. {
  101. return ((int)SendMessage((HWND)lParam, TBM_GETPOS, 0, 0L));
  102. }
  103. ////////////////////////////////////////////////////////////////////////////
  104. //
  105. // HardwareDlg_OnInitDialog
  106. //
  107. // Load the real hardware tab out of devmgr.dll.
  108. //
  109. // DWLP_USER - HWND of inner page
  110. //
  111. ////////////////////////////////////////////////////////////////////////////
  112. // There is no devmgr.h (go figure) so we must declare it ourselves.
  113. EXTERN_C DECLSPEC_IMPORT HWND STDAPICALLTYPE
  114. DeviceCreateHardwarePage(HWND hwndParent, const GUID *pguid);
  115. void
  116. HardwareDlg_OnInitDialog(HWND hdlg, LPARAM lp)
  117. {
  118. PCHWPAGEINFO phpi = (PCHWPAGEINFO)((LPPROPSHEETPAGE)lp)->lParam;
  119. HWND hwndHW = DeviceCreateHardwarePage(hdlg, &phpi->guidClass);
  120. if (hwndHW) {
  121. TCHAR tszTshoot[MAX_PATH];
  122. SetWindowLongPtr(hdlg, DWLP_USER, (LONG_PTR)hwndHW);
  123. if (LoadString(g_hInst, phpi->idsTshoot, tszTshoot, ARRAYSIZE(tszTshoot))) {
  124. SetWindowText(hwndHW, tszTshoot);
  125. }
  126. } else {
  127. DestroyWindow(hdlg); // catastrophic failure
  128. }
  129. }
  130. ////////////////////////////////////////////////////////////////////////////
  131. //
  132. // HardwareDlg
  133. //
  134. // The dialog procedure for generic hardware tabs.
  135. //
  136. // GWLP_USERDATA - HINSTANCE of devmgr.dll
  137. // DWLP_USER - HWND of inner page
  138. //
  139. //
  140. ////////////////////////////////////////////////////////////////////////////
  141. typedef HWND (WINAPI *DEVICECREATEHARDWAREPAGE)
  142. (HWND hwndParent, const GUID *pguid);
  143. INT_PTR CALLBACK HardwareDlg(HWND hdlg, UINT uMsg, WPARAM wp, LPARAM lp)
  144. {
  145. switch (uMsg) {
  146. case WM_INITDIALOG:
  147. HardwareDlg_OnInitDialog(hdlg, lp);
  148. return TRUE;
  149. }
  150. return FALSE;
  151. }
  152. ////////////////////////////////////////////////////////////////////////////
  153. //
  154. // CreateHardwarePage
  155. //
  156. ////////////////////////////////////////////////////////////////////////////
  157. HPROPSHEETPAGE
  158. CreateHardwarePage(PCHWPAGEINFO phpi)
  159. {
  160. PROPSHEETPAGE psp;
  161. // No hardware tab if we are a remote TS session, since we would end
  162. // up showing the properties of the server, not the client, and that
  163. // would be too confusing.
  164. if (GetSystemMetrics(SM_REMOTESESSION))
  165. return NULL;
  166. // No hardware tab if it's been disabled via policy.
  167. if (SHRestricted(REST_NOHARDWARETAB))
  168. return NULL;
  169. psp.dwSize = sizeof(psp);
  170. psp.dwFlags = PSP_DEFAULT;
  171. psp.hInstance = g_hInst;
  172. psp.pszTemplate = MAKEINTRESOURCE(DLG_HARDWARE);
  173. psp.pfnDlgProc = HardwareDlg;
  174. psp.lParam = (LPARAM)phpi;
  175. return CreatePropertySheetPage(&psp);
  176. }