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.

137 lines
2.8 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. // NTRAID#NTBUG9-503798-2001/12/06-sburns
  40. Win::Edit_LimitText(editControl, DS::MAX_PASSWORD_LENGTH);
  41. //
  42. // // (could also set the password style bit here, if we wanted.)
  43. //
  44. // balloonTip.Init(hwnd);
  45. // }
  46. //
  47. // return hr;
  48. return S_OK;
  49. }
  50. bool
  51. IsCapsLockOn()
  52. {
  53. // LOG_FUNCTION(IsCapsLockOn);
  54. return (::GetKeyState(VK_CAPITAL) & 1) ? true : false;
  55. }
  56. LRESULT
  57. PasswordEditBox::OnMessage(UINT message, WPARAM wparam, LPARAM lparam)
  58. {
  59. // LOG_FUNCTION(PasswordEditBox::OnMessage);
  60. switch (message)
  61. {
  62. case WM_KEYDOWN:
  63. {
  64. if (wparam == VK_CAPITAL)
  65. {
  66. // user pressed caps lock key
  67. balloonTip.Show(IsCapsLockOn());
  68. }
  69. else
  70. {
  71. // they hit some other key, so get rid of the tool tip
  72. balloonTip.Show(false);
  73. }
  74. break;
  75. }
  76. case WM_SETFOCUS:
  77. {
  78. // Make sure no one can steal the focus while a user is entering their
  79. // password
  80. ::LockSetForegroundWindow(LSFW_LOCK);
  81. balloonTip.Show(IsCapsLockOn());
  82. break;
  83. }
  84. case WM_PASTE:
  85. {
  86. balloonTip.Show(false);
  87. break;
  88. }
  89. case WM_KILLFOCUS:
  90. {
  91. balloonTip.Show(false);
  92. // Make sure other processes can set foreground window once again.
  93. ::LockSetForegroundWindow(LSFW_UNLOCK);
  94. break;
  95. }
  96. }
  97. return ControlSubclasser::OnMessage(message, wparam, lparam);
  98. }