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