在DIALOG类中加入了LoadActiveX方法
void CViewcharDlg::LoadActiveX(LPCTSTR strActiveXName, REFIID riidOfActiveX, int x, int y, int nWidth, int nHeight)
{
//Initialize ATL control containment code.
BOOL(WINAPI *m_AtlAxWinInit)();
m_AtlAxWinInit = (BOOL(WINAPI *)(void))::GetProcAddress
(_hWebLib, "AtlAxWinInit");
m_AtlAxWinInit();
// Get the dimensions of the main window's client
// area, and enumerate the child windows. Pass the
// dimensions to the child windows during enumeration.
RECT rcClient;
_hSelf = this->m_hWnd;
//GetClientRect(_hSelf, &rcClient);
_hAtl = ::CreateWindowEx(
WS_EX_CLIENTEDGE, \
TEXT("AtlAxWin"), \
strActiveXName, \
WS_CHILD | WS_VISIBLE | WS_EX_RTLREADING,\
x, y, nWidth, nHeight,\
this->m_hWnd, \
NULL, \
NULL, \
NULL);
if (!_hAtl)
{
::MessageBox(NULL, TEXT("Can not load AtlAxWin!"),
TEXT(""), MB_OK | MB_ICONSTOP);
throw int(106901);
}
HRESULT(WINAPI *m_AtlAxGetControl) (HWND h, IUnknown** pp);
m_AtlAxGetControl = (HRESULT(WINAPI *)
(HWND, IUnknown**))::GetProcAddress(_hWebLib, "AtlAxGetControl");
m_AtlAxGetControl(_hAtl, &_pUnk);
_pUnk->QueryInterface(__uuidof(Demo::IObjectSafetyPtr),
(LPVOID *)&_pDotNetCOMPtr);
if (_pDotNetCOMPtr != NULL)
{
//_pDotNetCOMPtr->SetInterfaceSafetyOptions((long)_hSelf);
}
else
{
// Get the dimensions of the main window's client
// area, and enumerate the child windows. Pass the
// dimensions to the child windows during enumeration.
//RECT rcClient;
// GetClientRect(_hSelf, &rcClient);
::DestroyWindow(_hAtl);
_hAtl = ::CreateWindowEx(
WS_EX_CLIENTEDGE, \
TEXT("AtlAxWin"), \
TEXT("MSHTML:""Please register ActiveX control before using this plugin."""),
WS_CHILD | WS_VISIBLE | WS_CLIPCHILDREN |
WS_EX_RTLREADING, \
0, 0, nWidth, nHeight, \
this->m_hWnd, \
NULL, \
NULL, \
NULL);
}
}
然后在在要使用ActiveX的Dialog的OnInitDialog()中加入下面的代码。
LoadActiveX(TEXT("Demo.IObjectSafety"), __uuidof(Demo::IObjectSafety), 0, 0, 750, 500);
但是程序运行后VC控件窗口中出现了ACTIVEX控件窗口但是里面显示 已取消到网页的导航,确保 Web 地址 http://demo.iobjectsafety 正确。
请各位大神看下这是怎么回事?