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.

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