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.

131 lines
3.6 KiB

  1. /****************************************************************************\
  2. *
  3. * passdlg.cpp
  4. *
  5. * Created: William Taylor (wtaylor) 01/22/01
  6. *
  7. * MS Ratings Password Dialog
  8. *
  9. \****************************************************************************/
  10. #include "msrating.h"
  11. #include "mslubase.h"
  12. #include "passdlg.h" // CPasswordDialog
  13. #include "hint.h" // CHint
  14. #include <contxids.h> // Help Context ID's
  15. #include <mluisupp.h> // SHWinHelpOnDemandWrap() and MLLoadStringA()
  16. DWORD CPasswordDialog::aIds[] = {
  17. IDC_STATIC3, IDH_IGNORE,
  18. IDC_STATIC2, IDH_IGNORE,
  19. IDC_OLD_HINT_LABEL, IDH_RATINGS_DISPLAY_PW_HINT,
  20. IDC_OLD_HINT_TEXT, IDH_RATINGS_DISPLAY_PW_HINT,
  21. IDC_STATIC1, IDH_RATINGS_SUPERVISOR_PASSWORD,
  22. IDC_PASSWORD, IDH_RATINGS_SUPERVISOR_PASSWORD,
  23. 0,0
  24. };
  25. CPasswordDialog::CPasswordDialog( int p_idsLabel, bool p_fCheckPassword )
  26. {
  27. m_idsLabel = p_idsLabel;
  28. m_fCheckPassword = p_fCheckPassword;
  29. }
  30. LRESULT CPasswordDialog::OnInitDialog(UINT uMsg, WPARAM wParam, LPARAM lParam, BOOL& bHandled)
  31. {
  32. // Show or Hide the Hint and Password label/edit controls
  33. ShowHideControl( IDC_OLD_HINT_LABEL, m_fCheckPassword );
  34. ShowHideControl( IDC_OLD_HINT_TEXT, m_fCheckPassword );
  35. ShowHideControl( IDC_STATIC1, m_fCheckPassword );
  36. ShowHideControl( IDC_PASSWORD, m_fCheckPassword );
  37. // Reduce the height of the dialog.
  38. if ( ! m_fCheckPassword )
  39. {
  40. ReduceDialogHeight( IDC_STATIC2 );
  41. }
  42. // Set the text label displayed.
  43. if ( GetDlgItem( IDC_STATIC2 ) != NULL )
  44. {
  45. NLS_STR nlsLabel(MAX_RES_STR_LEN);
  46. if ( nlsLabel.LoadString( static_cast<USHORT>(m_idsLabel) ) == ERROR_SUCCESS )
  47. {
  48. ::SetWindowText( GetDlgItem(IDC_STATIC2), nlsLabel.QueryPch() );
  49. }
  50. }
  51. if ( GetDlgItem( IDC_PASSWORD ) != NULL )
  52. {
  53. SendDlgItemMessage(IDC_PASSWORD,EM_SETLIMITTEXT,(WPARAM) RATINGS_MAX_PASSWORD_LENGTH,(LPARAM) 0);
  54. }
  55. // Display previously created hint (if one exists).
  56. {
  57. CHint oldHint( m_hWnd, IDC_OLD_HINT_TEXT );
  58. oldHint.DisplayHint();
  59. }
  60. ::SetFocus(GetDlgItem(IDC_PASSWORD));
  61. bHandled = FALSE;
  62. return 0L; // Let the system set the focus
  63. }
  64. LRESULT CPasswordDialog::OnCancel(WORD wNotifyCode, WORD wID, HWND hWndCtl, BOOL& bHandled)
  65. {
  66. EndDialog(PASSCONFIRM_FAIL);
  67. return 0L;
  68. }
  69. LRESULT CPasswordDialog::OnOK(WORD wNotifyCode, WORD wID, HWND hWndCtl, BOOL& bHandled)
  70. {
  71. if ( m_fCheckPassword )
  72. {
  73. CHAR pszPassword[MAXPATHLEN];
  74. HRESULT hRet;
  75. pszPassword[0] = '\0';
  76. ASSERT( GetDlgItem( IDC_PASSWORD ) != NULL );
  77. GetDlgItemText( IDC_PASSWORD, pszPassword, sizeof(pszPassword) );
  78. hRet = VerifySupervisorPassword(pszPassword);
  79. if (hRet == (NOERROR))
  80. {
  81. EndDialog(PASSCONFIRM_OK);
  82. }
  83. else
  84. {
  85. HWND hDlg = m_hWnd;
  86. MyMessageBox(hDlg, IDS_BADPASSWORD, IDS_GENERIC, MB_OK|MB_ICONERROR);
  87. SetErrorControl( IDC_PASSWORD );
  88. }
  89. }
  90. else
  91. {
  92. EndDialog( PASSCONFIRM_NEW );
  93. }
  94. return 0L;
  95. }
  96. LRESULT CPasswordDialog::OnHelp(UINT uMsg, WPARAM wParam, LPARAM lParam, BOOL& bHandled)
  97. {
  98. SHWinHelpOnDemandWrap((HWND)((LPHELPINFO)lParam)->hItemHandle, ::szHelpFile,
  99. HELP_WM_HELP, (DWORD_PTR)(LPSTR)aIds);
  100. return 0L;
  101. }
  102. LRESULT CPasswordDialog::OnContextMenu(UINT uMsg, WPARAM wParam, LPARAM lParam, BOOL& bHandled)
  103. {
  104. SHWinHelpOnDemandWrap((HWND)wParam, ::szHelpFile, HELP_CONTEXTMENU,
  105. (DWORD_PTR)(LPVOID)aIds);
  106. return 0L;
  107. }