使用VC++6.0創建帶界面的ActiveX控件
1.新建一個MFC ActiveX ControlWizard工程,例如demoActiveX.
2.運行看效果
3.添加對話框並生成對話框類CMyDialog
4.CDemoActiveXCtrl添加CMyDialog窗口變量
#include "MyDialog.h"//引用頭文件
/////////////////////////////////////////////////////////////////////////////
// CDemoActiveXCtrl : See DemoActiveXCtl.cpp for implementation.
class CDemoActiveXCtrl : public COleControl
{
DECLARE_DYNCREATE(CDemoActiveXCtrl)
// Constructor
public:
CDemoActiveXCtrl();
CMyDialog m_myDialog;//創建窗口變量
5.CDemoActiveXCtrl添加OnCreate事件
int CDemoActiveXCtrl::OnCreate(LPCREATESTRUCT lpCreateStruct)
{
if (COleControl::OnCreate(lpCreateStruct) == -1)
return -1;
// TODO: Add your specialized creation code here
m_myDialog.Create(IDD_DIALOG1,this);//創建窗口
m_myDialog.ShowWindow(SW_SHOW);//顯示窗口
return 0;
}
6.CDemoActiveXCtrl修改OnDraw方法
void CDemoActiveXCtrl::OnDraw(CDC* pdc, const CRect& rcBounds, const CRect& rcInvalid)
{
// TODO: Replace the following code with your own drawing code.
//pdc->FillRect(rcBounds, CBrush::FromHandle((HBRUSH)GetStockObject(WHITE_BRUSH)));
//pdc->Ellipse(rcBounds);
//以下爲修改的代碼
if(m_myDialog.GetSafeHwnd())
{
m_myDialog.MoveWindow(rcBounds);
}
}