1
我將WebKit作爲COM對象嵌入到純WinApi應用程序中。我想通過獲取WM_WINDOWPOSCHANGED來調整WebKit窗口的大小。通過WinApi調整WebKit COM的大小
LRESULT CALLBACK CBrowserView::WndProc(HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam)
{
typedef LRESULT (CBrowserView::*PFNPROC)(WPARAM wParam, LPARAM lParam);
PFNPROC pfnProc;
switch (uMsg)
{
case WM_WINDOWPOSCHANGED:
pfnProc = &CBrowserView::DoWindowPosChanged;
...
// CBrowserView::DoWindowPosChanged
LRESULT CBrowserView::DoWindowPosChanged(WPARAM wParam, LPARAM lParam)
{
_ASSERT(m_hWnd);
WINDOWPOS* pwp = (WINDOWPOS*)lParam;
{
if (pwp->cx != m_lClientWidth || pwp->cy != m_lClientHeight)
{
m_lClientWidth = pwp->cx;
m_lClientHeight = pwp->cy;
if (m_pIWebBrowser)
{
{
RECT rcClient;
rcClient.left = 0;
rcClient.top = 0;
rcClient.right = m_lClientWidth;
rcClient.bottom = m_lClientHeight;
HRESULT hr = m_pIWebBrowser->initWithFrame(rcClient, 0, 0);
if (FAILED(hr))
return E_FAIL;
hr = m_pIWebBrowser->mainFrame(&m_mainWebFrame);
if (FAILED(hr))
return E_FAIL;
BSTR urlBstr = SysAllocString(m_pszFile);;
WebKitToUrl(urlBstr, true);
}
}
}
}
return 0;
}
但是,這個工作只有一次,在OnCreate對話框,小部件填充此客戶區。在調整大小失敗時,m_pIWebBrowser-> initWithFrame(rcClient,0,0)返回E_FAIL。
是否有另一種方法來設置m_pIWebBrowser大小?