我将 WebKit 作为 COM 对象嵌入到纯 WinApi 应用程序中。我想通过获取 WM_WINDOWPOSCHANGED 来调整 WebKit 窗口的大小。
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 大小的方法吗?