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.

274 lines
6.5 KiB

  1. /****
  2. AdvUi.Cpp
  3. CoryWest@Microsoft.Com
  4. The UI code for the Advanced dialog box and its associated dialogs.
  5. Copyright September 1997, Microsoft Corporation
  6. ****/
  7. #include "stdafx.h"
  8. //#include "macros.h"
  9. //USE_HANDLE_MACROS("SCHMMGMT(advui.cpp)")
  10. #include "schmutil.h"
  11. #include "resource.h"
  12. #include "advui.h"
  13. //////////////////////////////////////////////////////////////////
  14. // CMoreInfoMessageBox
  15. class CMoreInfoMessageBox : public CDialog
  16. {
  17. public:
  18. CMoreInfoMessageBox(HWND hWndParent, IDisplayHelp* pIDisplayHelp)
  19. : CDialog(IDD_MSGBOX_OK_MOREINFO, CWnd::FromHandle(hWndParent)),
  20. m_spIDisplayHelp(pIDisplayHelp)
  21. {
  22. }
  23. void SetURL(LPCWSTR lpszURL) { m_szURL = lpszURL;}
  24. void SetMessage(LPCWSTR lpsz)
  25. {
  26. m_szMessage = lpsz;
  27. }
  28. // message handlers and MFC overrides
  29. virtual BOOL OnInitDialog()
  30. {
  31. SetDlgItemText(IDC_STATIC_MESSAGE, m_szMessage);
  32. return TRUE;
  33. }
  34. afx_msg void OnMoreInfo()
  35. {
  36. TRACE(L"ShowTopic(%s)\n", (LPCWSTR)m_szURL);
  37. m_spIDisplayHelp->ShowTopic((LPWSTR)(LPCWSTR)m_szURL);
  38. }
  39. DECLARE_MESSAGE_MAP()
  40. private:
  41. CComPtr<IDisplayHelp> m_spIDisplayHelp;
  42. CString m_szMessage;
  43. CString m_szURL;
  44. };
  45. BEGIN_MESSAGE_MAP(CMoreInfoMessageBox, CDialog)
  46. ON_BN_CLICKED(ID_BUTTON_MORE_INFO, OnMoreInfo)
  47. END_MESSAGE_MAP()
  48. ///////////////////////////////////////////////////////////////////////
  49. // CChangeDCDialog
  50. BEGIN_MESSAGE_MAP(CChangeDCDialog, CDialog)
  51. ON_BN_CLICKED(IDC_RADIO_ANY, OnChangeRadio)
  52. ON_BN_CLICKED(IDC_RADIO_SPECIFY, OnChangeRadio)
  53. ON_MESSAGE(WM_HELP, OnHelp)
  54. ON_MESSAGE(WM_CONTEXTMENU, OnContextHelp)
  55. END_MESSAGE_MAP()
  56. const DWORD CChangeDCDialog::help_map[] =
  57. {
  58. IDC_EDIT_CURRENT_DC, IDH_EDIT_CURRENT_DC2,
  59. IDC_RADIO_ANY, IDH_RADIO_ANY,
  60. IDC_RADIO_SPECIFY, IDH_RADIO_SPECIFY,
  61. IDC_EDIT_DC, IDH_EDIT_DC,
  62. 0,0
  63. };
  64. CChangeDCDialog::CChangeDCDialog(MyBasePathsInfo* pInfo, HWND hWndParent) :
  65. CDialog(IDD_CHANGE_DC, CWnd::FromHandle(hWndParent))
  66. {
  67. m_pInfo = pInfo;
  68. }
  69. BOOL CChangeDCDialog::OnInitDialog()
  70. {
  71. CDialog::OnInitDialog();
  72. SetDlgItemText(IDC_EDIT_CURRENT_DC, m_pInfo->GetServerName());
  73. // set the default radiobutton
  74. CButton* pCheck = (CButton*)GetDlgItem(IDC_RADIO_ANY);
  75. pCheck->SetCheck(TRUE);
  76. pCheck->SetFocus();
  77. OnChangeRadio();
  78. return FALSE; // we are setting the focus
  79. }
  80. void CChangeDCDialog::OnChangeRadio()
  81. {
  82. CWnd* pEdit = GetDlgItem(IDC_EDIT_DC);
  83. BOOL bAny = IsDlgButtonChecked(IDC_RADIO_ANY);
  84. pEdit->EnableWindow(!bAny);
  85. if (bAny)
  86. {
  87. SetDlgItemText(IDC_EDIT_DC, NULL);
  88. }
  89. else
  90. {
  91. SetDlgItemText(IDC_EDIT_DC, m_pInfo->GetServerName());
  92. }
  93. }
  94. void CChangeDCDialog::OnOK()
  95. {
  96. // NTRAID#NTBUG9-562426-2002/03/04-dantra-GetDlgItemText Result being ignored
  97. GetDlgItemText(IDC_EDIT_DC, m_szNewDCName);
  98. m_szNewDCName.TrimLeft();
  99. m_szNewDCName.TrimRight();
  100. CDialog::OnOK();
  101. }
  102. ///////////////////////////////////////////////////////////////////////
  103. // CEditFsmoDialog
  104. BEGIN_MESSAGE_MAP(CEditFsmoDialog, CDialog)
  105. ON_BN_CLICKED(IDC_CHANGE_FSMO, OnChange)
  106. ON_BN_CLICKED(IDCLOSE, OnClose)
  107. ON_MESSAGE(WM_HELP, OnHelp)
  108. ON_MESSAGE(WM_CONTEXTMENU, OnContextHelp)
  109. END_MESSAGE_MAP()
  110. CEditFsmoDialog::CEditFsmoDialog(MyBasePathsInfo* pInfo,
  111. HWND hWndParent,
  112. IDisplayHelp* pIDisplayHelp,
  113. BOOL fAllowFSMOChange ) :
  114. CDialog(IDD_EDIT_FSMO, CWnd::FromHandle(hWndParent))
  115. {
  116. m_pInfo = pInfo;
  117. m_spIDisplayHelp = pIDisplayHelp;
  118. m_fFSMOChangeAllowed = fAllowFSMOChange;
  119. }
  120. const DWORD CEditFsmoDialog::help_map[] =
  121. {
  122. IDC_EDIT_CURRENT_DC, IDH_EDIT_CURRENT_DC3,
  123. IDC_STATIC_FSMO_NOTE, NO_HELP,
  124. IDC_STATIC_FSMO_STATUS, NO_HELP,
  125. IDC_EDIT_CURRENT_FSMO_DC, IDH_EDIT_CURRENT_FSMO_DC2,
  126. IDC_CHANGE_FSMO, IDH_CHANGE_FSMO2,
  127. 0,0
  128. };
  129. BOOL CEditFsmoDialog::OnInitDialog()
  130. {
  131. CDialog::OnInitDialog();
  132. ASSERT( GetDlgItem(IDC_CHANGE_FSMO) );
  133. ASSERT( ::GetDlgItem(m_hWnd, IDC_STATIC_FSMO_STATUS) );
  134. // init the status (online/offline) control)
  135. m_fsmoServerState.Init(::GetDlgItem(m_hWnd, IDC_STATIC_FSMO_STATUS));
  136. SetDlgItemText(IDC_EDIT_CURRENT_DC, m_pInfo->GetServerName());
  137. MyBasePathsInfo fsmoOwnerInfo;
  138. PWSTR pszFsmoOwner = 0;
  139. HRESULT hr = FindFsmoOwner(m_pInfo, SCHEMA_FSMO, &fsmoOwnerInfo, &pszFsmoOwner);
  140. if(pszFsmoOwner)
  141. {
  142. m_szFsmoOwnerServerName = pszFsmoOwner;
  143. delete[] pszFsmoOwner;
  144. pszFsmoOwner = 0;
  145. }
  146. _SetFsmoServerStatus(SUCCEEDED(hr));
  147. if( m_fFSMOChangeAllowed )
  148. {
  149. // set the focus on change button
  150. GetDlgItem(IDC_CHANGE_FSMO)->SetFocus();
  151. }
  152. else
  153. {
  154. GetDlgItem(IDC_CHANGE_FSMO)->EnableWindow( FALSE );
  155. }
  156. return FALSE;
  157. }
  158. void CEditFsmoDialog::OnClose()
  159. {
  160. EndDialog(IDCLOSE);
  161. }
  162. void CEditFsmoDialog::OnChange()
  163. {
  164. CThemeContextActivator activator;
  165. // verify we have different servers
  166. if (m_szFsmoOwnerServerName.CompareNoCase(m_pInfo->GetServerName()) == 0)
  167. {
  168. AfxMessageBox(IDS_WARNING_CHANGE_FOCUS, MB_OK);
  169. return;
  170. }
  171. // make sure the user wants to do it
  172. if (AfxMessageBox(IDS_CHANGE_FSMO_CONFIRMATION, MB_YESNO|MB_DEFBUTTON2) != IDYES)
  173. return;
  174. HRESULT hr = GracefulFsmoOwnerTransfer(m_pInfo, SCHEMA_FSMO);
  175. if (FAILED(hr))
  176. {
  177. CString szFmt, szMsg;
  178. PWSTR pszError = 0;
  179. StringErrorFromHr(hr, &pszError);
  180. szFmt.LoadString(IDS_ERROR_CHANGE_FSMO_OWNER);
  181. szMsg.Format(szFmt, pszError);
  182. delete[] pszError;
  183. pszError = 0;
  184. CMoreInfoMessageBox dlg(m_hWnd, m_spIDisplayHelp);
  185. dlg.SetMessage(szMsg);
  186. dlg.SetURL(L"ADconcepts.chm::/FSMO_SCHEMA_ForcefulSeizure.htm");
  187. dlg.DoModal();
  188. }
  189. else
  190. {
  191. m_szFsmoOwnerServerName = m_pInfo->GetServerName();
  192. _SetFsmoServerStatus(TRUE);
  193. AfxMessageBox(IDS_CHANGE_FSMO_SUCCESS, MB_OK);
  194. }
  195. }
  196. void CEditFsmoDialog::_SetFsmoServerStatus(BOOL bOnLine)
  197. {
  198. // set the FSMO owner server name
  199. if (m_szFsmoOwnerServerName.IsEmpty())
  200. {
  201. CString szError;
  202. szError.LoadString(IDS_FSMO_SERVER_ERROR);
  203. SetDlgItemText(IDC_EDIT_CURRENT_FSMO_DC, szError);
  204. }
  205. else
  206. {
  207. SetDlgItemText(IDC_EDIT_CURRENT_FSMO_DC, m_szFsmoOwnerServerName);
  208. }
  209. // set the status of the FSMO owner server
  210. m_fsmoServerState.SetToggleState(bOnLine);
  211. }