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.

169 lines
3.9 KiB

  1. // Copyright (c) 2000 Microsoft Corporation
  2. //
  3. // Caps lock warning Balloon tip window
  4. //
  5. // 7 Nov 2000 sburns (that would be election day)
  6. //
  7. // added to fix NTRAID#NTBUG9-202238-2000/11/06-sburns
  8. //
  9. // most of this is stolen and cleaned up from johnstep's common cred ui
  10. // ds/win32/credui
  11. #include "headers.hxx"
  12. #include "CapsLockBalloonTip.hpp"
  13. #include "resource.h"
  14. CapsLockBalloonTip::CapsLockBalloonTip()
  15. :
  16. title(String::load(IDS_CAPS_LOCK_TIP_TITLE)),
  17. text(String::load(IDS_CAPS_LOCK_TIP_TEXT)),
  18. tipWindow(0),
  19. parentWindow(0),
  20. visible(false)
  21. {
  22. LOG_CTOR(CapsLockBalloonTip);
  23. ASSERT(!title.empty());
  24. ASSERT(!text.empty());
  25. }
  26. CapsLockBalloonTip::~CapsLockBalloonTip()
  27. {
  28. LOG_DTOR(CapsLockBalloonTip);
  29. if (Win::IsWindow(tipWindow))
  30. {
  31. Win::DestroyWindow(tipWindow);
  32. tipWindow = 0;
  33. }
  34. }
  35. HRESULT
  36. CapsLockBalloonTip::Init(HWND parentWindow_)
  37. {
  38. LOG_FUNCTION(CapsLockBalloonTip::Init);
  39. ASSERT(Win::IsWindow(parentWindow_));
  40. // should not call init on the same instance twice
  41. ASSERT(!parentWindow);
  42. ASSERT(!tipWindow);
  43. if (Win::IsWindow(tipWindow))
  44. {
  45. Win::DestroyWindow(tipWindow);
  46. }
  47. HRESULT hr = S_OK;
  48. do
  49. {
  50. hr = Win::CreateWindowEx(
  51. WS_EX_TOPMOST,
  52. TOOLTIPS_CLASS,
  53. L"",
  54. WS_POPUP | TTS_NOPREFIX | TTS_BALLOON,
  55. CW_USEDEFAULT,
  56. CW_USEDEFAULT,
  57. CW_USEDEFAULT,
  58. CW_USEDEFAULT,
  59. parentWindow_,
  60. 0,
  61. 0,
  62. tipWindow);
  63. BREAK_ON_FAILED_HRESULT(hr);
  64. ASSERT(tipWindow);
  65. parentWindow = parentWindow_;
  66. TOOLINFO info;
  67. // REVIEWED-2002/02/22-sburns call correctly passes byte count.
  68. ::ZeroMemory(&info, sizeof info);
  69. // we want to specify the stem position, so we set TTF_TRACK. We use
  70. // the HWND of the parent window as the tool id, because that is what
  71. // v.5 of comctl32 requires (or the balloon never appears). This is
  72. // a bug that has been fixed in v.6, but until fusion manifests are
  73. // working properly, you can't get v.6
  74. //
  75. // (when manifests are working, then we could remove TTF_IDISHWND and
  76. // set uId to be some fixed integer)
  77. info.uFlags = TTF_IDISHWND | TTF_TRACK;
  78. info.hwnd = parentWindow;
  79. info.uId = reinterpret_cast<UINT_PTR>(parentWindow);
  80. info.lpszText = const_cast<PWCHAR>(text.c_str());
  81. Win::ToolTip_AddTool(tipWindow, info);
  82. Win::ToolTip_SetTitle(tipWindow, TTI_WARNING, title);
  83. }
  84. while (0);
  85. return hr;
  86. }
  87. void
  88. CapsLockBalloonTip::Show(bool notHidden)
  89. {
  90. // LOG_FUNCTION(CapsLockBalloonTip::Show);
  91. TOOLINFO info;
  92. // REVIEWED-2002/02/22-sburns call correctly passes byte count.
  93. ::ZeroMemory(&info, sizeof info);
  94. // set these members the same as in the Init method, in order to
  95. // identify the proper tool.
  96. info.hwnd = parentWindow;
  97. info.uId = reinterpret_cast<UINT_PTR>(parentWindow);
  98. if (notHidden)
  99. {
  100. if (!visible && Win::IsWindowEnabled(parentWindow))
  101. {
  102. Win::SetFocus(parentWindow);
  103. RECT rect;
  104. Win::GetWindowRect(parentWindow, rect);
  105. Win::ToolTip_TrackPosition(
  106. tipWindow,
  107. // put the stem at the point 90% along the x axis
  108. rect.left + 90 * (rect.right - rect.left) / 100,
  109. // and 76% along the y axis of the edit control
  110. rect.top + 76 * (rect.bottom - rect.top) / 100);
  111. Win::ToolTip_TrackActivate(tipWindow, true, info);
  112. visible = true;
  113. }
  114. }
  115. else
  116. {
  117. // hide the tip window
  118. if (visible)
  119. {
  120. Win::ToolTip_TrackActivate(tipWindow, false, info);
  121. visible = false;
  122. }
  123. }
  124. }