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.

210 lines
4.8 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. int MyMessageBox(
  43. HWND hWnd,
  44. UINT uText,
  45. UINT uCaption,
  46. UINT uType,
  47. ...)
  48. {
  49. TCHAR szText[4 * PATHMAX], szCaption[2 * PATHMAX];
  50. int result;
  51. va_list parg;
  52. va_start(parg, uType);
  53. LoadString(g_hInst, uText, szCaption, ARRAYSIZE(szCaption));
  54. StringCchVPrintf(szText, ARRAYSIZE(szText), szCaption, parg);
  55. LoadString(g_hInst, uCaption, szCaption, ARRAYSIZE(szCaption));
  56. result = MessageBox(hWnd, szText, szCaption, uType);
  57. va_end(parg);
  58. return (result);
  59. }
  60. ////////////////////////////////////////////////////////////////////////////
  61. //
  62. // TrackInit
  63. //
  64. ////////////////////////////////////////////////////////////////////////////
  65. void TrackInit(
  66. HWND hwndScroll,
  67. int nCurrent,
  68. PARROWVSCROLL pAVS)
  69. {
  70. SendMessage(hwndScroll, TBM_SETRANGE, 0, MAKELONG(pAVS->bottom, pAVS->top));
  71. SendMessage(hwndScroll, TBM_SETPOS, TRUE, (LONG)nCurrent);
  72. }
  73. ////////////////////////////////////////////////////////////////////////////
  74. //
  75. // TrackMessage
  76. //
  77. ////////////////////////////////////////////////////////////////////////////
  78. int TrackMessage(
  79. WPARAM wParam,
  80. LPARAM lParam,
  81. PARROWVSCROLL pAVS)
  82. {
  83. return ((int)SendMessage((HWND)lParam, TBM_GETPOS, 0, 0L));
  84. }
  85. ////////////////////////////////////////////////////////////////////////////
  86. //
  87. // HardwareDlg_OnInitDialog
  88. //
  89. // Load the real hardware tab out of devmgr.dll.
  90. //
  91. // DWLP_USER - HWND of inner page
  92. //
  93. ////////////////////////////////////////////////////////////////////////////
  94. // There is no devmgr.h (go figure) so we must declare it ourselves.
  95. EXTERN_C DECLSPEC_IMPORT HWND STDAPICALLTYPE
  96. DeviceCreateHardwarePage(HWND hwndParent, const GUID *pguid);
  97. void
  98. HardwareDlg_OnInitDialog(HWND hdlg, LPARAM lp)
  99. {
  100. PCHWPAGEINFO phpi = (PCHWPAGEINFO)((LPPROPSHEETPAGE)lp)->lParam;
  101. HWND hwndHW = DeviceCreateHardwarePage(hdlg, &phpi->guidClass);
  102. if (hwndHW) {
  103. TCHAR tszTshoot[MAX_PATH];
  104. SetWindowLongPtr(hdlg, DWLP_USER, (LONG_PTR)hwndHW);
  105. if (LoadString(g_hInst, phpi->idsTshoot, tszTshoot, ARRAYSIZE(tszTshoot))) {
  106. SetWindowText(hwndHW, tszTshoot);
  107. }
  108. } else {
  109. DestroyWindow(hdlg); // catastrophic failure
  110. }
  111. }
  112. ////////////////////////////////////////////////////////////////////////////
  113. //
  114. // HardwareDlg
  115. //
  116. // The dialog procedure for generic hardware tabs.
  117. //
  118. // GWLP_USERDATA - HINSTANCE of devmgr.dll
  119. // DWLP_USER - HWND of inner page
  120. //
  121. //
  122. ////////////////////////////////////////////////////////////////////////////
  123. typedef HWND (WINAPI *DEVICECREATEHARDWAREPAGE)
  124. (HWND hwndParent, const GUID *pguid);
  125. INT_PTR CALLBACK HardwareDlg(HWND hdlg, UINT uMsg, WPARAM wp, LPARAM lp)
  126. {
  127. switch (uMsg) {
  128. case WM_INITDIALOG:
  129. HardwareDlg_OnInitDialog(hdlg, lp);
  130. return TRUE;
  131. }
  132. return FALSE;
  133. }
  134. ////////////////////////////////////////////////////////////////////////////
  135. //
  136. // CreateHardwarePage
  137. //
  138. ////////////////////////////////////////////////////////////////////////////
  139. HPROPSHEETPAGE
  140. CreateHardwarePage(PCHWPAGEINFO phpi)
  141. {
  142. PROPSHEETPAGE psp;
  143. // No hardware tab if we are a remote TS session, since we would end
  144. // up showing the properties of the server, not the client, and that
  145. // would be too confusing.
  146. if (GetSystemMetrics(SM_REMOTESESSION))
  147. return NULL;
  148. // No hardware tab if it's been disabled via policy.
  149. if (SHRestricted(REST_NOHARDWARETAB))
  150. return NULL;
  151. psp.dwSize = sizeof(psp);
  152. psp.dwFlags = PSP_DEFAULT;
  153. psp.hInstance = g_hInst;
  154. psp.pszTemplate = MAKEINTRESOURCE(DLG_HARDWARE);
  155. psp.pfnDlgProc = HardwareDlg;
  156. psp.lParam = (LPARAM)phpi;
  157. return CreatePropertySheetPage(&psp);
  158. }