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.

132 lines
2.5 KiB

  1. // Copyright (c) 2000 Microsoft Corporation
  2. //
  3. // password edit control wrapper
  4. //
  5. // 6 Nov 2000 sburns
  6. //
  7. // added to fix NTRAID#NTBUG9-202238-2000/11/06-sburns
  8. //
  9. // most of this is stolen from johnstep's common cred ui
  10. // ds/win32/credui
  11. #include "pch.h"
  12. #include "PasswordEditBox.hpp"
  13. PasswordEditBox::PasswordEditBox()
  14. {
  15. LOG_CTOR(PasswordEditBox);
  16. }
  17. PasswordEditBox::~PasswordEditBox()
  18. {
  19. LOG_DTOR(PasswordEditBox);
  20. }
  21. HRESULT
  22. PasswordEditBox::Init(HWND editControl)
  23. {
  24. LOG_FUNCTION(PasswordEditBox::Init);
  25. ASSERT(Win::GetClassName(editControl) == L"Edit");
  26. // By commenting out this code, we disable the subclassing and therefore
  27. // the caps lock warning bubble. We do this because it appears that the
  28. // edit box common control now offers that same functionality.
  29. // NTRAID#NTBUG9-255537-2000/12/12-sburns to disable the code
  30. // NTRAID#NTBUG9-255568-2000/12/12-sburns to remove the code from the source
  31. // tree entirely.
  32. //
  33. // HRESULT hr = ControlSubclasser::Init(editControl);
  34. // if (SUCCEEDED(hr))
  35. // {
  36. // // set the options on the edit control
  37. //
  38. // Win::Edit_LimitText(hwnd, DS::MAX_PASSWORD_LENGTH);
  39. //
  40. // // (could also set the password style bit here, if we wanted.)
  41. //
  42. // balloonTip.Init(hwnd);
  43. // }
  44. //
  45. // return hr;
  46. return S_OK;
  47. }
  48. bool
  49. IsCapsLockOn()
  50. {
  51. // LOG_FUNCTION(IsCapsLockOn);
  52. return (::GetKeyState(VK_CAPITAL) & 1) ? true : false;
  53. }
  54. LRESULT
  55. PasswordEditBox::OnMessage(UINT message, WPARAM wparam, LPARAM lparam)
  56. {
  57. // LOG_FUNCTION(PasswordEditBox::OnMessage);
  58. switch (message)
  59. {
  60. case WM_KEYDOWN:
  61. {
  62. if (wparam == VK_CAPITAL)
  63. {
  64. // user pressed caps lock key
  65. balloonTip.Show(IsCapsLockOn());
  66. }
  67. else
  68. {
  69. // they hit some other key, so get rid of the tool tip
  70. balloonTip.Show(false);
  71. }
  72. break;
  73. }
  74. case WM_SETFOCUS:
  75. {
  76. // Make sure no one can steal the focus while a user is entering their
  77. // password
  78. ::LockSetForegroundWindow(LSFW_LOCK);
  79. balloonTip.Show(IsCapsLockOn());
  80. break;
  81. }
  82. case WM_PASTE:
  83. {
  84. balloonTip.Show(false);
  85. break;
  86. }
  87. case WM_KILLFOCUS:
  88. {
  89. balloonTip.Show(false);
  90. // Make sure other processes can set foreground window once again.
  91. ::LockSetForegroundWindow(LSFW_UNLOCK);
  92. break;
  93. }
  94. }
  95. return ControlSubclasser::OnMessage(message, wparam, lparam);
  96. }