5

所以我正在使用 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::list 我的标签:

#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;

但是在调整主窗口大小时,它既不会调整主选项卡的大小,也不会调整我的自定义选项卡的大小。

我究竟做错了什么?

4

1 回答 1

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);
于 2014-03-05T13:18:17.970 回答