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.

201 lines
4.5 KiB

  1. //+-------------------------------------------------------------------------
  2. //
  3. // Microsoft Windows
  4. //
  5. // Copyright (C) Microsoft Corporation, 1998 - 1999
  6. //
  7. // File: domobjui.cpp
  8. //
  9. //--------------------------------------------------------------------------
  10. #include "stdafx.h"
  11. #include "domobj.h"
  12. #include "cdomain.h"
  13. #include "domain.h"
  14. #include "cdomain.h"
  15. #include "domobjui.h"
  16. #include "helparr.h"
  17. #ifdef _DEBUG
  18. #define new DEBUG_NEW
  19. #undef THIS_FILE
  20. static char THIS_FILE[] = __FILE__;
  21. #endif
  22. ///////////////////////////////////////////////////////////////////////
  23. //////////////////////////////////////////////////////////////////
  24. // CMoreInfoMessageBox
  25. class CMoreInfoMessageBox : public CDialog
  26. {
  27. public:
  28. CMoreInfoMessageBox(HWND hWndParent, IDisplayHelp* pIDisplayHelp)
  29. : CDialog(IDD_MSGBOX_OK_MOREINFO, CWnd::FromHandle(hWndParent)),
  30. m_spIDisplayHelp(pIDisplayHelp)
  31. {
  32. }
  33. void SetURL(LPCWSTR lpszURL) { m_szURL = lpszURL;}
  34. void SetMessage(LPCWSTR lpsz)
  35. {
  36. m_szMessage = lpsz;
  37. }
  38. // message handlers and MFC overrides
  39. virtual BOOL OnInitDialog()
  40. {
  41. SetDlgItemText(IDC_STATIC_MESSAGE, m_szMessage);
  42. return TRUE;
  43. }
  44. afx_msg void OnMoreInfo()
  45. {
  46. TRACE(L"ShowTopic(%s)\n", (LPCWSTR)m_szURL);
  47. m_spIDisplayHelp->ShowTopic((LPWSTR)(LPCWSTR)m_szURL);
  48. }
  49. DECLARE_MESSAGE_MAP()
  50. private:
  51. CComPtr<IDisplayHelp> m_spIDisplayHelp;
  52. CString m_szMessage;
  53. CString m_szURL;
  54. };
  55. BEGIN_MESSAGE_MAP(CMoreInfoMessageBox, CDialog)
  56. ON_BN_CLICKED(ID_BUTTON_MORE_INFO, OnMoreInfo)
  57. END_MESSAGE_MAP()
  58. ///////////////////////////////////////////////////////////////////////
  59. // CEditFsmoDialog
  60. BEGIN_MESSAGE_MAP(CEditFsmoDialog, CDialog)
  61. ON_BN_CLICKED(IDC_CHANGE_FSMO, OnChange)
  62. ON_WM_HELPINFO()
  63. END_MESSAGE_MAP()
  64. CEditFsmoDialog::CEditFsmoDialog(MyBasePathsInfo* pInfo, HWND hWndParent, IDisplayHelp* pIDisplayHelp) :
  65. CDialog(IDD_EDIT_FSMO, CWnd::FromHandle(hWndParent))
  66. {
  67. m_pInfo = pInfo;
  68. m_spIDisplayHelp = pIDisplayHelp;
  69. }
  70. BOOL CEditFsmoDialog::OnInitDialog()
  71. {
  72. CDialog::OnInitDialog();
  73. // init the status (online/offline) control)
  74. m_fsmoServerState.Init(::GetDlgItem(m_hWnd, IDC_STATIC_FSMO_STATUS));
  75. SetDlgItemText(IDC_EDIT_CURRENT_DC, m_pInfo->GetServerName());
  76. HRESULT hr;
  77. MyBasePathsInfo fsmoOwnerInfo;
  78. {
  79. CWaitCursor wait;
  80. PWSTR pszFsmoOwner = 0;
  81. hr = FindFsmoOwner(m_pInfo, DOMAIN_NAMING_FSMO, &fsmoOwnerInfo, &pszFsmoOwner);
  82. if (pszFsmoOwner)
  83. {
  84. m_szFsmoOwnerServerName = pszFsmoOwner;
  85. delete[] pszFsmoOwner;
  86. pszFsmoOwner = 0;
  87. }
  88. }
  89. BOOL bOnLine = SUCCEEDED(hr);
  90. _SetFsmoServerStatus(bOnLine);
  91. if (bOnLine)
  92. {
  93. // set the focus on change button
  94. GetDlgItem(IDC_CHANGE_FSMO)->SetFocus();
  95. }
  96. else
  97. {
  98. // set the focus on close button
  99. GetDlgItem(IDCANCEL)->SetFocus();
  100. }
  101. return FALSE; // we set the focus
  102. }
  103. void CEditFsmoDialog::OnChange()
  104. {
  105. // verify we have different servers
  106. if (m_szFsmoOwnerServerName.CompareNoCase(m_pInfo->GetServerName()) == 0)
  107. {
  108. AfxMessageBox(IDS_WARNING_CHANGE_FOCUS, MB_OK);
  109. return;
  110. }
  111. // make sure the user wants to do it
  112. if (AfxMessageBox(IDS_CHANGE_FSMO_CONFIRMATION, MB_OKCANCEL) != IDOK)
  113. return;
  114. HRESULT hr = S_OK;
  115. // try a graceful transfer
  116. {
  117. CWaitCursor wait;
  118. hr = GracefulFsmoOwnerTransfer(m_pInfo, DOMAIN_NAMING_FSMO);
  119. }
  120. if (FAILED(hr))
  121. {
  122. CString szFmt, szMsg;
  123. PWSTR pszError = 0;
  124. StringErrorFromHr(hr, &pszError);
  125. szFmt.LoadString(IDS_ERROR_CHANGE_FSMO_OWNER);
  126. szMsg.Format(szFmt, pszError);
  127. CMoreInfoMessageBox dlg(m_hWnd, m_spIDisplayHelp);
  128. dlg.SetMessage(szMsg);
  129. dlg.SetURL(L"ADconcepts.chm::/FSMO_DOMAIN_NAMING_ForcefulSeizure.htm");
  130. dlg.DoModal();
  131. }
  132. else
  133. {
  134. m_szFsmoOwnerServerName = m_pInfo->GetServerName();
  135. _SetFsmoServerStatus(TRUE);
  136. AfxMessageBox(IDS_CHANGE_FSMO_SUCCESS, MB_OK);
  137. }
  138. }
  139. void CEditFsmoDialog::_SetFsmoServerStatus(BOOL bOnLine)
  140. {
  141. // set the FSMO owner server name
  142. if (m_szFsmoOwnerServerName.IsEmpty())
  143. {
  144. CString szError;
  145. szError.LoadString(IDS_FSMO_SERVER_ERROR);
  146. SetDlgItemText(IDC_EDIT_CURRENT_FSMO_DC, szError);
  147. }
  148. else
  149. {
  150. SetDlgItemText(IDC_EDIT_CURRENT_FSMO_DC, m_szFsmoOwnerServerName);
  151. }
  152. // set the status of the FSMO owner server
  153. m_fsmoServerState.SetToggleState(bOnLine);
  154. // enable disable the change button
  155. GetDlgItem(IDC_CHANGE_FSMO)->EnableWindow(bOnLine);
  156. }
  157. BOOL CEditFsmoDialog::OnHelpInfo(HELPINFO* pHelpInfo)
  158. {
  159. DialogContextHelp((DWORD*)&g_aHelpIDs_TREE_IDD_EDIT_FSMO, pHelpInfo);
  160. return TRUE;
  161. }