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