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.

222 lines
5.0 KiB

  1. // ServiceTestDlg.cpp : implementation file
  2. //
  3. #include "stdafx.h"
  4. #include "ServiceTest.h"
  5. #include "ServiceTestDlg.h"
  6. #include "AgentRpcUtil.h"
  7. #include "..\DCTAgentService.h"
  8. #ifdef _DEBUG
  9. #define new DEBUG_NEW
  10. #undef THIS_FILE
  11. static char THIS_FILE[] = __FILE__;
  12. #endif
  13. /////////////////////////////////////////////////////////////////////////////
  14. // CAboutDlg dialog used for App About
  15. class CAboutDlg : public CDialog
  16. {
  17. public:
  18. CAboutDlg();
  19. // Dialog Data
  20. //{{AFX_DATA(CAboutDlg)
  21. enum { IDD = IDD_ABOUTBOX };
  22. //}}AFX_DATA
  23. // ClassWizard generated virtual function overrides
  24. //{{AFX_VIRTUAL(CAboutDlg)
  25. protected:
  26. virtual void DoDataExchange(CDataExchange* pDX); // DDX/DDV support
  27. //}}AFX_VIRTUAL
  28. // Implementation
  29. protected:
  30. //{{AFX_MSG(CAboutDlg)
  31. //}}AFX_MSG
  32. DECLARE_MESSAGE_MAP()
  33. };
  34. CAboutDlg::CAboutDlg() : CDialog(CAboutDlg::IDD)
  35. {
  36. //{{AFX_DATA_INIT(CAboutDlg)
  37. //}}AFX_DATA_INIT
  38. }
  39. void CAboutDlg::DoDataExchange(CDataExchange* pDX)
  40. {
  41. CDialog::DoDataExchange(pDX);
  42. //{{AFX_DATA_MAP(CAboutDlg)
  43. //}}AFX_DATA_MAP
  44. }
  45. BEGIN_MESSAGE_MAP(CAboutDlg, CDialog)
  46. //{{AFX_MSG_MAP(CAboutDlg)
  47. // No message handlers
  48. //}}AFX_MSG_MAP
  49. END_MESSAGE_MAP()
  50. /////////////////////////////////////////////////////////////////////////////
  51. // CServiceTestDlg dialog
  52. CServiceTestDlg::CServiceTestDlg(CWnd* pParent /*=NULL*/)
  53. : CDialog(CServiceTestDlg::IDD, pParent)
  54. {
  55. //{{AFX_DATA_INIT(CServiceTestDlg)
  56. m_Computer = _T("");
  57. //}}AFX_DATA_INIT
  58. // Note that LoadIcon does not require a subsequent DestroyIcon in Win32
  59. m_hIcon = AfxGetApp()->LoadIcon(IDR_MAINFRAME);
  60. }
  61. void CServiceTestDlg::DoDataExchange(CDataExchange* pDX)
  62. {
  63. CDialog::DoDataExchange(pDX);
  64. //{{AFX_DATA_MAP(CServiceTestDlg)
  65. DDX_Text(pDX, IDC_COMPUTER, m_Computer);
  66. //}}AFX_DATA_MAP
  67. }
  68. BEGIN_MESSAGE_MAP(CServiceTestDlg, CDialog)
  69. //{{AFX_MSG_MAP(CServiceTestDlg)
  70. ON_WM_SYSCOMMAND()
  71. ON_WM_PAINT()
  72. ON_WM_QUERYDRAGICON()
  73. ON_BN_CLICKED(IDC_SHUTDOWN, OnShutdown)
  74. //}}AFX_MSG_MAP
  75. END_MESSAGE_MAP()
  76. /////////////////////////////////////////////////////////////////////////////
  77. // CServiceTestDlg message handlers
  78. BOOL CServiceTestDlg::OnInitDialog()
  79. {
  80. CDialog::OnInitDialog();
  81. // Add "About..." menu item to system menu.
  82. // IDM_ABOUTBOX must be in the system command range.
  83. ASSERT((IDM_ABOUTBOX & 0xFFF0) == IDM_ABOUTBOX);
  84. ASSERT(IDM_ABOUTBOX < 0xF000);
  85. CMenu* pSysMenu = GetSystemMenu(FALSE);
  86. if (pSysMenu != NULL)
  87. {
  88. CString strAboutMenu;
  89. strAboutMenu.LoadString(IDS_ABOUTBOX);
  90. if (!strAboutMenu.IsEmpty())
  91. {
  92. pSysMenu->AppendMenu(MF_SEPARATOR);
  93. pSysMenu->AppendMenu(MF_STRING, IDM_ABOUTBOX, strAboutMenu);
  94. }
  95. }
  96. // Set the icon for this dialog. The framework does this automatically
  97. // when the application's main window is not a dialog
  98. SetIcon(m_hIcon, TRUE); // Set big icon
  99. SetIcon(m_hIcon, FALSE); // Set small icon
  100. // TODO: Add extra initialization here
  101. return TRUE; // return TRUE unless you set the focus to a control
  102. }
  103. void CServiceTestDlg::OnSysCommand(UINT nID, LPARAM lParam)
  104. {
  105. if ((nID & 0xFFF0) == IDM_ABOUTBOX)
  106. {
  107. CAboutDlg dlgAbout;
  108. dlgAbout.DoModal();
  109. }
  110. else
  111. {
  112. CDialog::OnSysCommand(nID, lParam);
  113. }
  114. }
  115. // If you add a minimize button to your dialog, you will need the code below
  116. // to draw the icon. For MFC applications using the document/view model,
  117. // this is automatically done for you by the framework.
  118. void CServiceTestDlg::OnPaint()
  119. {
  120. if (IsIconic())
  121. {
  122. CPaintDC dc(this); // device context for painting
  123. SendMessage(WM_ICONERASEBKGND, (WPARAM) dc.GetSafeHdc(), 0);
  124. // Center icon in client rectangle
  125. int cxIcon = GetSystemMetrics(SM_CXICON);
  126. int cyIcon = GetSystemMetrics(SM_CYICON);
  127. CRect rect;
  128. GetClientRect(&rect);
  129. int x = (rect.Width() - cxIcon + 1) / 2;
  130. int y = (rect.Height() - cyIcon + 1) / 2;
  131. // Draw the icon
  132. dc.DrawIcon(x, y, m_hIcon);
  133. }
  134. else
  135. {
  136. CDialog::OnPaint();
  137. }
  138. }
  139. // The system calls this to obtain the cursor to display while the user drags
  140. // the minimized window.
  141. HCURSOR CServiceTestDlg::OnQueryDragIcon()
  142. {
  143. return (HCURSOR) m_hIcon;
  144. }
  145. DWORD TryShutdown(handle_t hBinding,DWORD arg)
  146. {
  147. DWORD rc;
  148. RpcTryExcept
  149. {
  150. // the job file has been copied to the remote computer
  151. // during the installation
  152. rc = EaxcShutdown(hBinding,arg);
  153. }
  154. RpcExcept(1)
  155. {
  156. rc = RpcExceptionCode();
  157. }
  158. RpcEndExcept
  159. return rc;
  160. }
  161. void CServiceTestDlg::OnShutdown()
  162. {
  163. UpdateData(TRUE);
  164. // try to bind to the service on the specified server
  165. DWORD rc = 0;
  166. handle_t hBinding = NULL;
  167. WCHAR * sBinding = NULL;
  168. CString msg;
  169. rc = EaxBindCreate(m_Computer.GetBuffer(0),&hBinding,&sBinding,TRUE);
  170. if ( rc )
  171. {
  172. msg.Format(L"Failed to bind to the agent service, rc=%ld",rc);
  173. MessageBox(msg);
  174. }
  175. if( ! rc )
  176. {
  177. rc = TryShutdown(hBinding,0);
  178. if ( ! rc )
  179. {
  180. MessageBox(L"Service shutdown successfully.");
  181. }
  182. else
  183. {
  184. msg.Format(L"Service shutdown failed, rc=%ld",rc);
  185. MessageBox(msg);
  186. }
  187. }
  188. }