MFC ActiveX (OCX) 创建技术

来源:互联网 发布:学java月薪多少 编辑:程序博客网 时间:2024/05/22 11:35


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-sizedBOOL CFAQCtrl::OnSetExtent( LPSIZEL lpSizeL ) {    return FALSE; }for more refer tohttp://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属性需要设置childwndVideo2.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);



原创粉丝点击