现在的位置: 首页 > 综合 > 正文

调用OCX控件时的声明和实现

2017年08月23日 ⁄ 综合 ⁄ 共 3255字 ⁄ 字号 评论关闭
FirstLessonOcx.h

#if !defined(AFX_FIRSTLESSONOCX_H__0CA538A0_1E9A_49D9_ADBE_0D21B83849DF__INCLUDED_)
#define AFX_FIRSTLESSONOCX_H__0CA538A0_1E9A_49D9_ADBE_0D21B83849DF__INCLUDED_

#if _MSC_VER > 1000
#pragma once
#endif // _MSC_VER > 1000
// Machine generated IDispatch wrapper class(es) created by Microsoft Visual C++

// NOTE: Do not modify the contents of this file.  If this class is regenerated by
//  Microsoft Visual C++, your modifications will be overwritten.

/////////////////////////////////////////////////////////////////////////////
// FIRSTLESSONOCX wrapper class

class CFirstLessonOcx : public CWnd
{
protected:
	DECLARE_DYNCREATE(CFirstLessonOcx)
public:
	CLSID const& GetClsid()
	{
		static CLSID const clsid
			= { 0x58134c6c, 0x7b0e, 0x4a14, { 0xb0, 0x5b, 0x15, 0xc4, 0x9c, 0x6c, 0x6c, 0xdd } };
		return clsid;
	}
	virtual BOOL Create(LPCTSTR lpszClassName,
		LPCTSTR lpszWindowName, DWORD dwStyle,
		const RECT& rect,
		CWnd* pParentWnd, UINT nID,
		CCreateContext* pContext = NULL)
	{ return CreateControl(GetClsid(), lpszWindowName, dwStyle, rect, pParentWnd, nID); }

	BOOL Create(LPCTSTR lpszWindowName, DWORD dwStyle,
		const RECT& rect, CWnd* pParentWnd, UINT nID,
		CFile* pPersist = NULL, BOOL bStorage = FALSE,
		BSTR bstrLicKey = NULL)
	{ return CreateControl(GetClsid(), lpszWindowName, dwStyle, rect, pParentWnd, nID,
	pPersist, bStorage, bstrLicKey); }

	// Attributes
public:
	long StartMonitor(LPCTSTR szDevIDNO, long nChannel);
	void CloseAllSound();
	long GetLayout();
	void SetLayout(long propVal);
};

//{{AFX_INSERT_LOCATION}}
// Microsoft Visual C++ will insert additional declarations immediately before the previous line.

#endif // !defined(AFX_FIRSTLESSONOCX_H__0CA538A0_1E9A_49D9_ADBE_0D21B83849DF__INCLUDED_)

FirstLessonOcx.cpp

// Machine generated IDispatch wrapper class(es) created by Microsoft Visual C++

// NOTE: Do not modify the contents of this file.  If this class is regenerated by
//  Microsoft Visual C++, your modifications will be overwritten.


#include "stdafx.h"
#include "FirstLessonOcx.h"

/////////////////////////////////////////////////////////////////////////////
// CCMSV6OCX

IMPLEMENT_DYNCREATE(CFirstLessonOcx, CWnd)

/////////////////////////////////////////////////////////////////////////////
// CFirstLessonOcx properties

long CFirstLessonOcx::StartMonitor(LPCTSTR szDevIDNO, long nChannel)
{
	long result;
	static BYTE parms[] = VTS_BSTR VTS_I4;
	InvokeHelper(0x1, DISPATCH_METHOD, VT_I4, (void*)&result, parms, szDevIDNO, nChannel);//适合有输入参数,有返回值的调度接口
	return result;
}

void CFirstLessonOcx::CloseAllSound()
{
	InvokeHelper(0x2, DISPATCH_METHOD, VT_EMPTY, NULL, NULL);//无输入参数无返回值,也可调用此接口
}

long CFirstLessonOcx::GetLayout()
{
	long result;
	GetProperty(0x3, VT_I4, (void*)&result);//适合无输入参数,只获取返回值的调度接口
	return result;
}

void CFirstLessonOcx::SetLayout(long propVal)
{
	SetProperty(0x4, VT_I4, propVal);//适合无返回的调度接口
}

ActiveXTestDlg.h
// ActiveXTestDlg.h : 头文件
//

#pragma once
#include "FirstLessonOcx.h"

// CActiveXTestDlg 对话框
class CActiveXTestDlg : public CDialog
{
// 构造
public:
	CActiveXTestDlg(CWnd* pParent = NULL);	// 标准构造函数

// 对话框数据
	enum { IDD = IDD_ACTIVEXTEST_DIALOG };

	protected:
	virtual void DoDataExchange(CDataExchange* pDX);	// DDX/DDV 支持

private:
	CFirstLessonOcx m_ocx;

// 实现
protected:
	virtual BOOL OnInitDialog();
};

ActiveXTestDlg.cpp
void CActiveXTestDlg::DoDataExchange(CDataExchange* pDX)
{
	CDialog::DoDataExchange(pDX);
	DDX_Control(pDX, IDC_ACTIVEXFIRSTLESSCTRL1, m_ocx);
}


BOOL CActiveXTestDlg::OnInitDialog()
{
	CDialog::OnInitDialog();
	
	//如果不绑定控件,可自己创建,必须用WS_CHILD,并指定父窗口  
	//m_ocx.Create(_T("My ocx"), WS_CHILD | WS_VISIBLE, CRect(10,10,100,30), this, 100);

	m_ocx.GetLayout();
}


抱歉!评论已关闭.