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.

189 lines
6.0 KiB

  1. // Copyright (c) 1999 Microsoft Corporation. All Rights Reserved.
  2. // AdminDlg.cpp : implementation file
  3. //
  4. #include "stdafx.h"
  5. #include "coptdlg.h"
  6. #include "password.h"
  7. extern DWORD g_helpIDArray[][2];
  8. extern int g_helpIDArraySize;
  9. /////////////////////////////////////////////////////////////////////////////
  10. // CPasswordDlg dialog
  11. CPasswordDlg::CPasswordDlg(IMSDVDAdm* pDvdAdm)
  12. {
  13. m_pDvdAdm = pDvdAdm;
  14. m_reason = PASSWORDDLG_CHANGE;
  15. m_bVerified = FALSE;
  16. m_szPassword[0] = TEXT('\0');
  17. }
  18. /*************************************************************/
  19. /* Name: OnInitDialog
  20. /* Description:
  21. /*************************************************************/
  22. LRESULT CPasswordDlg::OnInitDialog(UINT uMsg, WPARAM wParam, LPARAM lParam, BOOL& bHandled)
  23. {
  24. HWND ctlNewPassword = GetDlgItem(IDC_EDIT_NEW_PASSWORD);
  25. HWND ctlConfirmNew = GetDlgItem(IDC_EDIT_CONFIRM_NEW);
  26. HWND ctlPassword = GetDlgItem(IDC_EDIT_PASSWORD);
  27. HWND staticNewPassword = GetDlgItem(IDC_STATIC_NEW_PASSWORD);
  28. HWND staticConfirmNew = GetDlgItem(IDC_STATIC_CONFIRM_NEW);
  29. HWND staticPassword = GetDlgItem(IDC_STATIC_PASSWORD);
  30. if (!ctlNewPassword || !ctlConfirmNew || !ctlPassword)
  31. return S_FALSE;
  32. if (!staticNewPassword || !staticConfirmNew || !staticPassword)
  33. return S_FALSE;
  34. ::SendMessage(ctlNewPassword, EM_LIMITTEXT, MAX_PASSWD, 0);
  35. ::SendMessage(ctlConfirmNew, EM_LIMITTEXT, MAX_PASSWD, 0);
  36. ::SendMessage(ctlPassword, EM_LIMITTEXT, MAX_PASSWD, 0);
  37. ::SetWindowText(ctlNewPassword, _T(""));
  38. ::SetWindowText(ctlConfirmNew, _T(""));
  39. ::SetWindowText(ctlPassword, _T(""));
  40. if (m_reason == PASSWORDDLG_VERIFY) {
  41. ::ShowWindow(ctlNewPassword, SW_HIDE);
  42. ::ShowWindow(staticNewPassword, SW_HIDE);
  43. ::ShowWindow(ctlConfirmNew, SW_HIDE);
  44. ::ShowWindow(staticConfirmNew, SW_HIDE);
  45. }
  46. else if (m_reason == PASSWORDDLG_CHANGE) {
  47. ::ShowWindow(ctlNewPassword, SW_SHOW);
  48. ::ShowWindow(staticNewPassword, SW_SHOW);
  49. ::ShowWindow(ctlConfirmNew, SW_SHOW);
  50. ::ShowWindow(staticConfirmNew, SW_SHOW);
  51. if(COptionsDlg::IsNewAdmin()) { //New Admin people
  52. ::ShowWindow(ctlPassword, SW_HIDE);
  53. ::ShowWindow(staticPassword, SW_HIDE);
  54. }
  55. else {
  56. ::ShowWindow(ctlPassword, SW_SHOW);
  57. ::ShowWindow(staticPassword, SW_SHOW);
  58. }
  59. }
  60. return TRUE;
  61. }
  62. /*************************************************************/
  63. /* Name: OnContextMenu
  64. /* Description: Display help message for a control
  65. /*************************************************************/
  66. LRESULT CPasswordDlg::OnContextMenu(UINT uMsg, WPARAM wParam, LPARAM lParam, BOOL& bHandled)
  67. {
  68. HWND hwnd = (HWND) wParam;
  69. DWORD controlId = ::GetDlgCtrlID(hwnd);
  70. POINT pt;
  71. pt.x = GET_X_LPARAM(lParam);
  72. pt.y = GET_Y_LPARAM(lParam);
  73. if (controlId == 0) {
  74. ::ScreenToClient(hwnd, &pt);
  75. hwnd = ::ChildWindowFromPoint(hwnd, pt);
  76. controlId = ::GetDlgCtrlID(hwnd);
  77. }
  78. for (int i=0; i<g_helpIDArraySize; i++) {
  79. if (controlId && controlId == g_helpIDArray[i][0]) {
  80. if (controlId <= IDC_APPLY)
  81. ::WinHelp(hwnd, TEXT("windows.hlp"), HELP_CONTEXTMENU, (DWORD_PTR)g_helpIDArray);
  82. else
  83. ::WinHelp(hwnd, TEXT("dvdplay.hlp"), HELP_CONTEXTMENU, (DWORD_PTR)g_helpIDArray);
  84. }
  85. }
  86. return 0;
  87. }
  88. /*************************************************************/
  89. /* Name: OnOK
  90. /* Description: password change requested
  91. /*************************************************************/
  92. LRESULT CPasswordDlg::OnOK(WORD wNotifyCode, WORD wID, HWND hWndCtl, BOOL& bHandled)
  93. {
  94. USES_CONVERSION;
  95. HWND ctlPassword = GetDlgItem(IDC_EDIT_PASSWORD);
  96. TCHAR szPassword[MAX_PASSWD];
  97. ::GetWindowText(ctlPassword, szPassword, MAX_PASSWD);
  98. HWND ctlNewPassword = GetDlgItem(IDC_EDIT_NEW_PASSWORD);
  99. TCHAR szNewPassword[MAX_PASSWD];
  100. ::GetWindowText(ctlNewPassword, szNewPassword, MAX_PASSWD);
  101. HWND ctlConfirmNew = GetDlgItem(IDC_EDIT_CONFIRM_NEW);
  102. TCHAR szConfirmNew[MAX_PASSWD];
  103. ::GetWindowText(ctlConfirmNew, szConfirmNew, MAX_PASSWD);
  104. HRESULT hr = S_OK;
  105. if (m_reason == PASSWORDDLG_CHANGE) {
  106. if(lstrcmp(szNewPassword, szConfirmNew) != 0)
  107. {
  108. DVDMessageBox(hWndCtl, IDS_PASSOWRD_CONFIRM_WRONG);
  109. ::SetWindowText(ctlConfirmNew, _T(""));
  110. ::SetFocus(ctlConfirmNew);
  111. return FALSE;
  112. }
  113. if(COptionsDlg::IsNewAdmin()) //New Admin people
  114. {
  115. hr = m_pDvdAdm->ChangePassword(L"", L"", T2OLE(szNewPassword));
  116. }
  117. else //Old Admin people
  118. {
  119. hr = m_pDvdAdm->ChangePassword(L"", T2OLE(szPassword), T2OLE(szNewPassword));
  120. if (hr == E_ACCESSDENIED) {
  121. DVDMessageBox(hWndCtl, IDS_PASSWORD_INCORRECT);
  122. ::SetWindowText(ctlPassword, _T(""));
  123. ::SetFocus(ctlPassword);
  124. return FALSE;
  125. }
  126. }
  127. if (FAILED(hr)) {
  128. DVDMessageBox(hWndCtl, IDS_PASSWORD_CHANGE_FAIL);
  129. ::SetWindowText(ctlPassword, _T(""));
  130. ::SetFocus(ctlPassword);
  131. return FALSE;
  132. }
  133. }
  134. else if (m_reason == PASSWORDDLG_VERIFY) {
  135. VARIANT_BOOL fRight;
  136. hr = m_pDvdAdm->ConfirmPassword(L"", T2OLE(szPassword), &fRight);
  137. if (fRight == VARIANT_FALSE) {
  138. DVDMessageBox(hWndCtl, IDS_PASSWORD_INCORRECT);
  139. ::SetFocus(ctlPassword);
  140. lstrcpy(m_szPassword, szPassword);
  141. m_bVerified = FALSE;
  142. return FALSE;
  143. }
  144. else {
  145. lstrcpy(m_szPassword, szPassword);
  146. m_bVerified = TRUE;
  147. }
  148. }
  149. EndDialog(wID);
  150. return 0;
  151. }
  152. /*************************************************************/
  153. /* Name: OnCancel
  154. /* Description:
  155. /*************************************************************/
  156. LRESULT CPasswordDlg::OnCancel(WORD wNotifyCode, WORD wID, HWND hWndCtl, BOOL& bHandled)
  157. {
  158. m_bVerified = FALSE;
  159. EndDialog(wID);
  160. return 0;
  161. }