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.

202 lines
4.7 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. CThemeContextActivator activator;
  106. // verify we have different servers
  107. if (m_szFsmoOwnerServerName.CompareNoCase(m_pInfo->GetServerName()) == 0)
  108. {
  109. AfxMessageBox(IDS_WARNING_CHANGE_FOCUS, MB_OK);
  110. return;
  111. }
  112. // make sure the user wants to do it
  113. if (AfxMessageBox(IDS_CHANGE_FSMO_CONFIRMATION, MB_YESNO|MB_DEFBUTTON2) != IDYES)
  114. return;
  115. HRESULT hr = S_OK;
  116. // try a graceful transfer
  117. {
  118. CWaitCursor wait;
  119. hr = GracefulFsmoOwnerTransfer(m_pInfo, DOMAIN_NAMING_FSMO);
  120. }
  121. if (FAILED(hr))
  122. {
  123. CString szFmt, szMsg;
  124. PWSTR pszError = 0;
  125. StringErrorFromHr(hr, &pszError);
  126. szFmt.LoadString(IDS_ERROR_CHANGE_FSMO_OWNER);
  127. szMsg.Format(szFmt, pszError);
  128. CMoreInfoMessageBox dlg(m_hWnd, m_spIDisplayHelp);
  129. dlg.SetMessage(szMsg);
  130. dlg.SetURL(L"ADconcepts.chm::/FSMO_DOMAIN_NAMING_ForcefulSeizure.htm");
  131. dlg.DoModal();
  132. }
  133. else
  134. {
  135. m_szFsmoOwnerServerName = m_pInfo->GetServerName();
  136. _SetFsmoServerStatus(TRUE);
  137. AfxMessageBox(IDS_CHANGE_FSMO_SUCCESS, MB_OK);
  138. }
  139. }
  140. void CEditFsmoDialog::_SetFsmoServerStatus(BOOL bOnLine)
  141. {
  142. // set the FSMO owner server name
  143. if (m_szFsmoOwnerServerName.IsEmpty())
  144. {
  145. CString szError;
  146. szError.LoadString(IDS_FSMO_SERVER_ERROR);
  147. SetDlgItemText(IDC_EDIT_CURRENT_FSMO_DC, szError);
  148. }
  149. else
  150. {
  151. SetDlgItemText(IDC_EDIT_CURRENT_FSMO_DC, m_szFsmoOwnerServerName);
  152. }
  153. // set the status of the FSMO owner server
  154. m_fsmoServerState.SetToggleState(bOnLine);
  155. // enable disable the change button
  156. GetDlgItem(IDC_CHANGE_FSMO)->EnableWindow(bOnLine);
  157. }
  158. BOOL CEditFsmoDialog::OnHelpInfo(HELPINFO* pHelpInfo)
  159. {
  160. DialogContextHelp((DWORD*)&g_aHelpIDs_TREE_IDD_EDIT_FSMO, pHelpInfo);
  161. return TRUE;
  162. }