所以我正在使用CEF v3.1180.823而我正在尝试使用多个标签制作浏览器。
对于每个新标签我都是:
1)创建一个样式为WS_POPUPWINDOW的新窗口。
HWND hWndTab = CreateWindowEx(NULL, w.lpszClassName, 0,
WS_POPUPWINDOW, x, y, width, height,
NULL, NULL, hInst, NULL);
2)创建一个新的“g_handler”
CefRefPtr<ClientHandler> cef_hTab = new ClientHandler();
3)创建新浏览器
CefBrowserHost::CreateBrowser(info, cef_hTab.get(), _url, settings);
4)将此窗口设置为永不关闭的第一个(主)选项卡的子窗口
SetParent(hWndTab, g_handler->GetMainHwnd());
5)将新窗口的HWND设置为新处理程序的主要HWND
cef_hTab->SetMainHwnd(hWndTab);
我的问题是:当主窗口调整大小时,如何调整所有标签的大小?
默认窗口过程(即主标签的过程)具有以下代码:
case WM_SIZE:
// Minimizing resizes the window to 0x0
// which causes our layout to go all
// screwy, so we just ignore it.
if (wParam != SIZE_MINIMIZED &&
g_handler.get() &&
g_handler->GetBrowser())
{
CefWindowHandle hwnd =
g_handler->GetBrowser()->GetHost()->GetWindowHandle();
if (hwnd)
{
// Resize the browser window and
// address bar to match the new frame
// window size
RECT rect;
GetClientRect(hWnd, &rect);
rect.top += URLBAR_HEIGHT;
int urloffset = rect.left + BUTTON_WIDTH * 4;
HDWP hdwp = BeginDeferWindowPos(1);
hdwp = DeferWindowPos(hdwp, hwnd, NULL, rect.left, rect.top,
rect.right - rect.left, rect.bottom - rect.top, SWP_NOZORDER);
EndDeferWindowPos(hdwp);
}
}
break;
我有一个std ::我的标签列表:
#include <vector>
#include <list>
#include "include/cef_app.h"
#include "cefclient/binding_test.h"
using namespace std;
struct STab
{
HWND hWndTab;
HWND hWndTabButton;
CefRefPtr<ClientHandler> cef_handler;
void Destroy();
};
typedef list<STab> LTabs;
LTabs* GetTabs();
我正在尝试编辑主窗口程序,如下所示:
case WM_SIZE:
if (wParam != SIZE_MINIMIZED &&
g_handler.get() &&
g_handler->GetBrowser())
{
CefWindowHandle hwnd =
g_handler->GetBrowser()->GetHost()->GetWindowHandle();
if (hwnd)
{
RECT rect;
GetClientRect(hWnd, &rect);
rect.top += URLBAR_HEIGHT;
int urloffset = rect.left + BUTTON_WIDTH * 4;
HDWP hdwp = BeginDeferWindowPos(1);
hdwp = DeferWindowPos(hdwp, hwnd, NULL, rect.left, rect.top,
rect.right - rect.left, rect.bottom - rect.top, SWP_NOZORDER);
// added:
//------------------------------------------------------------------
LTabs* lTabs = GetTabs();
LTabs::iterator it;
for (it = lTabs->begin(); it != lTabs->end(); ++it)
{
CefWindowHandle hWndTab =
it->cef_handler->GetBrowser()->GetHost()->GetWindowHandle();
if (hWndTab)
hdwp = DeferWindowPos(hdwp, hWndTab, NULL,
rect.left, rect.top, rect.right - rect.left,
rect.bottom - rect.top, SWP_NOZORDER);
}
//------------------------------------------------------------------
EndDeferWindowPos(hdwp);
}
}
break;
但是在调整主窗口大小时,它既不调整主标签也不调整自定义标签。
我做错了什么?
答案 0 :(得分:5)
快速解决方案是使用SetWindowPos
函数代替DeferWindowPos
函数。
//hdwp = DeferWindowPos(hdwp, hWndTab, NULL,
// rect.left, rect.top, rect.right - rect.left,
// rect.bottom - rect.top, SWP_NOZORDER);
SetWindowPos(hWndTab, NULL, rect.left, rect.top,
rect.right - rect.left, rect.bottom - rect.top,
SWP_NOMOVE|SWP_NOZORDER|SWP_NOACTIVATE);