【发布时间】:2023-03-14 00:38:02
【问题描述】:
所以我正在使用 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;
但是在调整主窗口大小时,它既不会调整主选项卡也不会调整我的自定义选项卡。
我做错了什么?
【问题讨论】:
-
你解决了吗?如果是这样,您可以发布您的解决方案并接受它作为答案。您的回答可能对许多其他程序员有所帮助。
标签: visual-c++ tabs resize popup chromium-embedded