AutoTestDlg.cpp
上传用户:weisheen
上传日期:2022-07-09
资源大小:19390k
文件大小:5k
源码类别:

ActiveX/DCOM/ATL

开发平台:

Visual C++

  1. // AutoTestDlg.cpp : implementation file
  2. //
  3. #include "stdafx.h"
  4. #include "AutoTest.h"
  5. #include "AutoTestDlg.h"
  6. #ifdef _DEBUG
  7. #define new DEBUG_NEW
  8. #undef THIS_FILE
  9. static char THIS_FILE[] = __FILE__;
  10. #endif
  11. /////////////////////////////////////////////////////////////////////////////
  12. // CAboutDlg dialog used for App About
  13. class CAboutDlg : public CDialog
  14. {
  15. public:
  16. CAboutDlg();
  17. // Dialog Data
  18. //{{AFX_DATA(CAboutDlg)
  19. enum { IDD = IDD_ABOUTBOX };
  20. //}}AFX_DATA
  21. // ClassWizard generated virtual function overrides
  22. //{{AFX_VIRTUAL(CAboutDlg)
  23. protected:
  24. virtual void DoDataExchange(CDataExchange* pDX);    // DDX/DDV support
  25. //}}AFX_VIRTUAL
  26. // Implementation
  27. protected:
  28. //{{AFX_MSG(CAboutDlg)
  29. //}}AFX_MSG
  30. DECLARE_MESSAGE_MAP()
  31. };
  32. CAboutDlg::CAboutDlg() : CDialog(CAboutDlg::IDD)
  33. {
  34. //{{AFX_DATA_INIT(CAboutDlg)
  35. //}}AFX_DATA_INIT
  36. }
  37. void CAboutDlg::DoDataExchange(CDataExchange* pDX)
  38. {
  39. CDialog::DoDataExchange(pDX);
  40. //{{AFX_DATA_MAP(CAboutDlg)
  41. //}}AFX_DATA_MAP
  42. }
  43. BEGIN_MESSAGE_MAP(CAboutDlg, CDialog)
  44. //{{AFX_MSG_MAP(CAboutDlg)
  45. // No message handlers
  46. //}}AFX_MSG_MAP
  47. END_MESSAGE_MAP()
  48. /////////////////////////////////////////////////////////////////////////////
  49. // CAutoTestDlg dialog
  50. CAutoTestDlg::CAutoTestDlg(CWnd* pParent /*=NULL*/)
  51. : CDialog(CAutoTestDlg::IDD, pParent)
  52. {
  53. //{{AFX_DATA_INIT(CAutoTestDlg)
  54. // NOTE: the ClassWizard will add member initialization here
  55. //}}AFX_DATA_INIT
  56. // Note that LoadIcon does not require a subsequent DestroyIcon in Win32
  57. m_hIcon = AfxGetApp()->LoadIcon(IDR_MAINFRAME);
  58. }
  59. void CAutoTestDlg::DoDataExchange(CDataExchange* pDX)
  60. {
  61. CDialog::DoDataExchange(pDX);
  62. //{{AFX_DATA_MAP(CAutoTestDlg)
  63. // NOTE: the ClassWizard will add DDX and DDV calls here
  64. //}}AFX_DATA_MAP
  65. }
  66. BEGIN_MESSAGE_MAP(CAutoTestDlg, CDialog)
  67. //{{AFX_MSG_MAP(CAutoTestDlg)
  68. ON_WM_SYSCOMMAND()
  69. ON_WM_PAINT()
  70. ON_WM_QUERYDRAGICON()
  71. ON_BN_CLICKED(IDC_BUTTON1, OnButton1)
  72. //}}AFX_MSG_MAP
  73. END_MESSAGE_MAP()
  74. /////////////////////////////////////////////////////////////////////////////
  75. // CAutoTestDlg message handlers
  76. BOOL CAutoTestDlg::OnInitDialog()
  77. {
  78. CDialog::OnInitDialog();
  79. // Add "About..." menu item to system menu.
  80. // IDM_ABOUTBOX must be in the system command range.
  81. ASSERT((IDM_ABOUTBOX & 0xFFF0) == IDM_ABOUTBOX);
  82. ASSERT(IDM_ABOUTBOX < 0xF000);
  83. CMenu* pSysMenu = GetSystemMenu(FALSE);
  84. if (pSysMenu != NULL)
  85. {
  86. CString strAboutMenu;
  87. strAboutMenu.LoadString(IDS_ABOUTBOX);
  88. if (!strAboutMenu.IsEmpty())
  89. {
  90. pSysMenu->AppendMenu(MF_SEPARATOR);
  91. pSysMenu->AppendMenu(MF_STRING, IDM_ABOUTBOX, strAboutMenu);
  92. }
  93. }
  94. // Set the icon for this dialog.  The framework does this automatically
  95. //  when the application's main window is not a dialog
  96. SetIcon(m_hIcon, TRUE); // Set big icon
  97. SetIcon(m_hIcon, FALSE); // Set small icon
  98. // TODO: Add extra initialization here
  99. return TRUE;  // return TRUE  unless you set the focus to a control
  100. }
  101. void CAutoTestDlg::OnSysCommand(UINT nID, LPARAM lParam)
  102. {
  103. if ((nID & 0xFFF0) == IDM_ABOUTBOX)
  104. {
  105. CAboutDlg dlgAbout;
  106. dlgAbout.DoModal();
  107. }
  108. else
  109. {
  110. CDialog::OnSysCommand(nID, lParam);
  111. }
  112. }
  113. // If you add a minimize button to your dialog, you will need the code below
  114. //  to draw the icon.  For MFC applications using the document/view model,
  115. //  this is automatically done for you by the framework.
  116. void CAutoTestDlg::OnPaint() 
  117. {
  118. if (IsIconic())
  119. {
  120. CPaintDC dc(this); // device context for painting
  121. SendMessage(WM_ICONERASEBKGND, (WPARAM) dc.GetSafeHdc(), 0);
  122. // Center icon in client rectangle
  123. int cxIcon = GetSystemMetrics(SM_CXICON);
  124. int cyIcon = GetSystemMetrics(SM_CYICON);
  125. CRect rect;
  126. GetClientRect(&rect);
  127. int x = (rect.Width() - cxIcon + 1) / 2;
  128. int y = (rect.Height() - cyIcon + 1) / 2;
  129. // Draw the icon
  130. dc.DrawIcon(x, y, m_hIcon);
  131. }
  132. else
  133. {
  134. CDialog::OnPaint();
  135. }
  136. }
  137. // The system calls this to obtain the cursor to display while the user drags
  138. //  the minimized window.
  139. HCURSOR CAutoTestDlg::OnQueryDragIcon()
  140. {
  141. return (HCURSOR) m_hIcon;
  142. }
  143. void CAutoTestDlg::OnButton1() 
  144. {
  145. // TODO: Add your control notification handler code here
  146. ::CoInitialize(NULL);//初始化环境
  147. CString str="AutoDemo.MyAbc";
  148. CLSID mycomid;
  149. ::CLSIDFromProgID(L"AutoDemo.MyAbc",&mycomid);
  150. IDispatch* pDisp=NULL;
  151. ::CoCreateInstance(mycomid,NULL,CLSCTX_INPROC_SERVER,IID_IDispatch,(void **)&pDisp);
  152. DISPID addid;
  153. BSTR   funnames[1];
  154. funnames[0]=::SysAllocString(L"add");
  155. pDisp->GetIDsOfNames(IID_NULL,funnames,1,LOCALE_SYSTEM_DEFAULT,&addid);
  156. //准备输入参数;
  157. VARIANT inputs[2];
  158. inputs[0].vt=VT_I4;
  159. inputs[0].lVal=662;
  160. inputs[1].vt=VT_I4;
  161. inputs[1].lVal=13;
  162. DISPPARAMS paras;
  163. paras.cArgs=2;
  164. paras.rgvarg=inputs;
  165. paras.cNamedArgs=0;
  166. paras.rgdispidNamedArgs=NULL;
  167. //准备输出参数;
  168. UINT iErrorCode;
  169. EXCEPINFO  ex;
  170. VARIANT  vResult;
  171. pDisp->Invoke(
  172. addid,
  173. IID_NULL,
  174. LOCALE_SYSTEM_DEFAULT,
  175. DISPATCH_METHOD,
  176. &paras,
  177. &vResult,
  178. &ex,
  179. &iErrorCode
  180. );
  181. CString str1;
  182. str1.Format("%d",vResult.lVal);
  183. MessageBox(str1);
  184. ::CoUninitialize();
  185. }