通过CreateControl()直接创建控件(ocx)失败时的处理
来源:互联网 发布:js判断css样式 编辑:程序博客网 时间:2024/05/12 19:02
刚开始的时候,在一个对话框工程exe中,通过CreateControl()可以成功地直接创建一个控件(ocx),后来由于变化,需要在一个控件中再手动创建其它的控件,结果却失败了,创建的代码和在exe中完全一样,可为什么不成功呢?
出问题的那一句是:
m_pCtrlCont = afxOccManager->CreateContainer(this);
是windows自己的文件中,函数如下:
BOOL CWnd::InitControlContainer(BOOL bCreateFromResource)
{
if (m_pCtrlCont == NULL)
{
BOOL bSuccess;
bSuccess = CreateControlContainer( &m_pCtrlCont );
if (bSuccess && (m_pCtrlCont == NULL))
{
// The window wants to use the default control container.
TRY
{
m_pCtrlCont = afxOccManager->CreateContainer(this);
}
END_TRY
}
//When Container is created and it is not during creation from resources,
//populate the list with all resource created Win32 controls.
if (!bCreateFromResource)
{
m_pCtrlCont->FillListSitesOrWnds(GetOccDialogInfo());
}
}
// Mark all ancestor windows as containing OLE controls.
if (m_pCtrlCont != NULL)
{
CWnd* pWnd = this;
while ((pWnd != NULL) && !(pWnd->m_nFlags & WF_OLECTLCONTAINER))
{
pWnd->m_nFlags |= WF_OLECTLCONTAINER;
pWnd = pWnd->GetParent();
if (! (GetWindowLong(pWnd->GetSafeHwnd(), GWL_STYLE) & WS_CHILD))
break;
}
}
return (m_pCtrlCont != NULL);
}
然后查看afxOccManager,发现有
#define afxOccManager AfxGetModuleState()->m_pOccManager
这时,m_pOccManager为NULL,所以创建不成功
这个变量名称让我想起可能是和ole有关的环境没有初始化造成的,查看exe工程的CexeApp::InitInstance()中,有 AfxEnableControlContainer();,而控件工程中却没有,于是把它拷贝到控件工程的CocxApp::InitInstance()中,编译运行,控件创建成功
拷贝之后的函数如下:
BOOL CocxApp::InitInstance()
{
BOOL bInit = COleControlModule::InitInstance();
if (bInit)
{
// TODO: Add your own module initialization code here.
AfxEnableControlContainer();
}
return bInit;
}
- 通过CreateControl()直接创建控件(ocx)失败时的处理
- VS2010创建OCX控件
- VS2010创建OCX控件
- VS2010创建OCX控件
- ocx控件注册失败常见问题
- Release编译出的ocx控件注册失败问题解决
- CreateControl
- CreateControl
- CreateControl
- JavaScript串口(通过vb的MSCOMM32.OCX控件)
- 通过脚本在窗体上加载ocx控件的方法
- 动态创建的ACTIVEX。OCX控件 发布不能显示问题
- java 利用jacob调用ocx控件时怎么处理带返回值的参数?
- MFC OCX 控件事件的添加和处理
- MFC OCX 控件事件的添加和处理
- MFC OCX 控件事件的添加和处理
- MFC OCX 控件事件的添加和处理
- ocx控件的注册
- 递归常见问题
- DHTML,Table标签,固定行头,固定列头
- 天书夜读:从汇编语言到Windows内核编程
- 利用.net的内部机制在asp.net中实现身份验证
- asp调用打开exe文件
- 通过CreateControl()直接创建控件(ocx)失败时的处理
- NOTE: javascript prototype chain
- 接口
- 1
- 类的初始化和对象的初始化
- 好男人必学的10道超级简单的菜
- 八步立体裸妆打造梦幻小脸
- 理解表格一:图解 frame 和 rules 属性
- Struts, hibernate and spring interview questions