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.

163 lines
3.6 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 "pch.h"
  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. ::ZeroMemory(&info, sizeof(info));
  68. // we want to specify the stem position, so we set TTF_TRACK. We use
  69. // the HWND of the parent window as the tool id, because that if what
  70. // v.5 of comctl32 requires (or the balloon never appears). This is
  71. // a bug that has been fixed in v.6, but until fusion manifests are
  72. // working properly, you can't get v.6
  73. //
  74. // (when manifests are working, then we could remove TTF_IDISHWND and
  75. // set uId to be some fixed integer)
  76. info.uFlags = TTF_IDISHWND | TTF_TRACK;
  77. info.hwnd = parentWindow;
  78. info.uId = reinterpret_cast<UINT_PTR>(parentWindow);
  79. info.lpszText = const_cast<PWCHAR>(text.c_str());
  80. Win::ToolTip_AddTool(tipWindow, info);
  81. Win::ToolTip_SetTitle(tipWindow, TTI_WARNING, title);
  82. }
  83. while (0);
  84. return hr;
  85. }
  86. void
  87. CapsLockBalloonTip::Show(bool notHidden)
  88. {
  89. // LOG_FUNCTION(CapsLockBalloonTip::Show);
  90. TOOLINFO info;
  91. ::ZeroMemory(&info, sizeof info);
  92. // set these members the same as in the Init method, in order to
  93. // identify the proper tool.
  94. info.hwnd = parentWindow;
  95. info.uId = reinterpret_cast<UINT_PTR>(parentWindow);
  96. if (notHidden)
  97. {
  98. if (!visible && Win::IsWindowEnabled(parentWindow))
  99. {
  100. Win::SetFocus(parentWindow);
  101. RECT rect;
  102. Win::GetWindowRect(parentWindow, rect);
  103. Win::ToolTip_TrackPosition(
  104. tipWindow,
  105. // put the stem at the point 90% along the x axis
  106. rect.left + 90 * (rect.right - rect.left) / 100,
  107. // and 76% along the y axis of the edit control
  108. rect.top + 76 * (rect.bottom - rect.top) / 100);
  109. Win::ToolTip_TrackActivate(tipWindow, true, info);
  110. visible = true;
  111. }
  112. }
  113. else
  114. {
  115. // hide the tip window
  116. if (visible)
  117. {
  118. Win::ToolTip_TrackActivate(tipWindow, false, info);
  119. visible = false;
  120. }
  121. }
  122. }