积极答复者
WebBrowser如何响应window.resizeTo方法?

问题
答案
-
实现IHTMLOMWindowServices和IServiceProvider看看
MSMVP VC++- 已标记为答案 piperworldcup98 2009年6月12日 7:02
全部回复
-
class ATL_NO_VTABLE CWebBrowser : public CWindowImpl<CWebBrowser>,
public CComObjectRootEx<CComSingleThreadModel>,
public CComCoClass<CWebBrowser>,
public IDispatch,
public IOleClientSite,
public IOleInPlaceSite,
public IOleInPlaceFrame,
public IDocHostUIHandler
////////////////////////////////////////////////////////
HRESULT CWebBrowser::Init( HWND hParent, CRect& rc )
{
Create( hParent, rc, _T("Web Host"), WS_VISIBLE | WS_CHILD,
0, NULL);
ShowWindow(SW_SHOWNORMAL);CRect rcClient;
GetClientRect( rcClient );// Create the WebBrowser control
CComPtr<IOleObject> spOleObject;
HRESULT hr = CoCreateInstance(CLSID_WebBrowser, NULL, CLSCTX_INPROC, IID_IWebBrowser2,
(void**)&m_spWebBrowser);if(FAILED(hr) || !m_spWebBrowser)
{
return E_FAIL;
}// Query WebBrowser for IOleObject pointer
m_spWebBrowser->QueryInterface(IID_IOleObject, (void**)&spOleObject);
if (hr != S_OK)
{
//MessageBox(_T("CoCreateInstance failed"));
return E_FAIL;
}if (spOleObject->SetClientSite(this) != S_OK)
{
//MessageBox(_T("SetClientSite failed"));
return E_FAIL;
}// In-place activate the WebBrower control
MSG msg;
GetClientRect(&rcClient);
hr = spOleObject->DoVerb(OLEIVERB_INPLACEACTIVATE, &msg, this, 0, m_hWnd, &rcClient);
if (hr != S_OK)
{
//MessageBox(_T("DoVerb failed"));
return E_FAIL;
}m_spWebBrowser = spOleObject;
if (!m_spWebBrowser)
return E_FAIL;//temp test
m_spWebBrowser->put_Silent(VARIANT_TRUE);
//temp test// Set up the connection to the WebBrowser control to receive events
hr = AtlAdvise(m_spWebBrowser, GetUnknown(), DIID_DWebBrowserEvents2, &m_dwCookie);
if (FAILED(hr))
ATLTRACE(_T("Failed to Advise\n"));// QI for the in-place object to set the size
m_spInPlaceObject = m_spWebBrowser;
_ASSERT(m_spInPlaceObject);if (m_spInPlaceObject)
m_spInPlaceObject->SetObjectRects(&rcClient, &rcClient);return S_OK;
}
//上面是创建方式
绑定连接点之后可以响应浏览器事件,也可以正常显示,但是对于js里的window.resizeto却无法响应,有文章说需要响应DISPID_WINDOWSETHEIGHT和DISPID_WINDOWSETWIDTH事件,但是调用window.resizeto的时候并没有接收到这两个事件。 -
Hi jiangsheng
下面是我的实现方式,请问你有什么建议吗?多谢!class ATL_NO_VTABLE CWebBrowser : public CWindowImpl<CWebBrowser>,
public CComObjectRootEx<CComSingleThreadModel>,
public CComCoClass<CWebBrowser>,
public IDispatch,
public IOleClientSite,
public IOleInPlaceSite,
public IOleInPlaceFrame,
public IDocHostUIHandler
////////////////////////////////////////////////////////
HRESULT CWebBrowser::Init( HWND hParent, CRect& rc )
{
Create( hParent, rc, _T("Web Host"), WS_VISIBLE | WS_CHILD,
0, NULL);
ShowWindow(SW_SHOWNORMAL);CRect rcClient;
GetClientRect( rcClient );// Create the WebBrowser control
CComPtr<IOleObject> spOleObject;
HRESULT hr = CoCreateInstance(CLSID_WebBrowser, NULL, CLSCTX_INPROC, IID_IWebBrowser2,
(void**)&m_spWebBrowser);if(FAILED(hr) || !m_spWebBrowser)
{
return E_FAIL;
}// Query WebBrowser for IOleObject pointer
m_spWebBrowser->QueryInterface(IID_IOleObject, (void**)&spOleObject);
if (hr != S_OK)
{
//MessageBox(_T("CoCreateInstance failed"));
return E_FAIL;
}if (spOleObject->SetClientSite(this) != S_OK)
{
//MessageBox(_T("SetClientSite failed"));
return E_FAIL;
}// In-place activate the WebBrower control
MSG msg;
GetClientRect(&rcClient);
hr = spOleObject->DoVerb(OLEIVERB_INPLACEACTIVATE, &msg, this, 0, m_hWnd, &rcClient);
if (hr != S_OK)
{
//MessageBox(_T("DoVerb failed"));
return E_FAIL;
}m_spWebBrowser = spOleObject;
if (!m_spWebBrowser)
return E_FAIL;//temp test
m_spWebBrowser->put_Silent(VARIANT_TRUE);
//temp test// Set up the connection to the WebBrowser control to receive events
hr = AtlAdvise(m_spWebBrowser, GetUnknown(), DIID_DWebBrowserEvents2, &m_dwCookie);
if (FAILED(hr))
ATLTRACE(_T("Failed to Advise\n"));// QI for the in-place object to set the size
m_spInPlaceObject = m_spWebBrowser;
_ASSERT(m_spInPlaceObject);if (m_spInPlaceObject)
m_spInPlaceObject->SetObjectRects(&rcClient, &rcClient);return S_OK;
}
//上面是创建方式
绑定连接点之后可以响应浏览器事件,也可以正常显示,但是对于js里的window.resizeto却无法响应,有文章说需要响应DISPID_WINDOWSETHEIGHT和DISPID_WINDOWSETWIDTH事件,但是调用window.resizeto的时候并没有接收到这两个事件。 -
实现IHTMLOMWindowServices和IServiceProvider看看
MSMVP VC++- 已标记为答案 piperworldcup98 2009年6月12日 7:02