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);



發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章