Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Chromium Embedded (CEF3). How to resize new browser window?

So i'm using CEF v3.1180.823 and i'm trying to make browser with multiple tabs.

For every new tab i'm:

1) creating a new window with style WS_POPUPWINDOW.

HWND hWndTab = CreateWindowEx(NULL, w.lpszClassName, 0,
    WS_POPUPWINDOW, x, y, width, height, 
    NULL, NULL, hInst, NULL);

2) creating a new "g_handler"

CefRefPtr<ClientHandler> cef_hTab = new ClientHandler();

3) creating new browser

CefBrowserHost::CreateBrowser(info, cef_hTab.get(), _url, settings);

4) setting this window as child for first (main) tab that never closes

SetParent(hWndTab, g_handler->GetMainHwnd());

5) Setting the HWND of new window as main HWND for new handler

cef_hTab->SetMainHwnd(hWndTab);

My problem is: how do i resize all of my tabs when main window is resizing?

The default window procedure (i.e. procedure of main tab) has this code:

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;

I have a std::list of my tabs:

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

And i'm trying to edit the main window procedure like this:

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;

But on resizing main window it resizes neither main tab nor my custom tabs.

What am i doing wrong?

like image 910
Alexander Avatar asked Jul 11 '13 08:07

Alexander


1 Answers

Quick solution is to use SetWindowPos function instead of DeferWindowPos function.

//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);
like image 135
Alexander Avatar answered Sep 25 '22 14:09

Alexander