近日,在ocxA中调用ocxB,但总是失败。查找msdn及高手指点原来是mfc程序可能不支持ole控件,解决方法:
1、AfxEnableControlContainer Header: afxdisp.h
Call this function in your application object's InitInstance function to enable support for containment of OLE controls.
2、动态创建控件对象
m_ledocx1 = new CCl2005ocxctrl1();
CRect rt(0,0,500,500); //控件位置大小
long lStyle = WS_CHILDWINDOW|WS_VISIBLE;
m_ledocx1->Create(_T("LEDWINDOW"),_T(""),lStyle,rt,this,IDC_CL2005OCXCTRL1);
m_ledocx1->ShowWindow(TRUE);
注意:IDC_CL2005OCXCTRL1为标识ole控件的资源ID 需要手动添加,并将_APS_NEXT_CONTROL_VALUE置为IDC_CL2005OCXCTRL1+1