MFC ActiveX (OCX) 创建技术


1、设置控件初始大小

First, we need to set the initial size of the control to its static size using the COleControl::SetInitialSize method. This should be done in your control's constructor like this:

 
// CFAQCtrl::CFAQCtrl - Constructor 
CFAQCtrl::CFAQCtrl() 
{
   InitializeIIDs(&IID_DFAQ, &IID_DFAQEvents); 
   SetInitialSize( 28, 28 ); 
}

override OnSetExtent and return FALSE, which tells the container that the control cannot be re-sized
BOOL CFAQCtrl::OnSetExtent( LPSIZEL lpSizeL ) 
{ 
   return FALSE; 
}
for more refer to
http://www.widgetware.com/FAQArticle.htm#Size

2、在ActiveX上动态创建控件、窗口

在CdemoMFCCtrl.h文件中声明变量

public:
	CButton m_btn;
	CVideoWnd wndVideo1,wndVideo2;//添加的一个对话框类
在CdemoMFCCtrl.cpp文件中实现

	m_btn.Create(_T("动态按钮"),BS_DEFPUSHBUTTON | WS_VISIBLE|WS_CHILD ,CRect(0,0,100,100),this,123);

	wndVideo1.Create(IDD_DLG_VIDEO,this); //这个窗口的stye属性需要设置child
	wndVideo2.Create(IDD_DLG_VIDEO,this);

	wndVideo1.MoveWindow(0,0,100,100);
	wndVideo2.MoveWindow(0,110,100,100);

	wndVideo1.ShowWindow(SW_SHOW);
	wndVideo2.ShowWindow(SW_SHOW);



评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值