Skip to content

Fix issues with app hanging during window resize when calling WindowUtils.OnSize. Expose new Browser.SetBounds method. #464

Closed

Description

@cztomczak

I noticed app sometimes hanging during window resize in the wxpython.py example. It occurs during the EVT_SIZE event when calling WindowUtils.OnSize. That function does not handle things properly and it should only be called when handling WM_SIZE message, as it makes calls to DefWindowProc.

The solution will be to expose Browser.SetBounds on Windows which will be a wrapper for SetWindowPos WIN32 API.

All examples should be updated to use the new Browser.SetBounds method.

In v49 release for WinXP/Vista there is WindowUtils.UpdateBrowserSize, so it needs to be added to Migration Guide doc that it is require to call Browser.SetBounds now..

Related issue: #345 ("Crash when resizing browser using WindowUtils.OnSize with multi-threaded message loop set to True").

window_utils_win.pyx

    @staticmethod
    def OnSize(WindowHandle windowHandle, long msg, long wparam, long lparam):
        cdef PyBrowser pyBrowser = GetBrowserByWindowHandle(windowHandle)
        if not pyBrowser:
            return DefWindowProc(<HWND>windowHandle, msg, wparam, lparam)

        cdef HWND innerHwnd = <HWND>pyBrowser.GetWindowHandle()
        if not innerHwnd:
            return DefWindowProc(<HWND>windowHandle, msg, wparam, lparam)

        cdef RECT rect2
        cdef BOOL result = GetClientRect(<HWND>windowHandle, &rect2)

        cdef HDWP hdwp
        if result != 0:
            hdwp = BeginDeferWindowPos(1)
            if hdwp:
                hdwp = DeferWindowPos(hdwp, innerHwnd, NULL,
                        rect2.left, rect2.top,
                        rect2.right - rect2.left,
                        rect2.bottom - rect2.top,
                        SWP_NOZORDER)
                if hdwp:
                    EndDeferWindowPos(hdwp)

        return DefWindowProc(<HWND>windowHandle, msg, wparam, lparam)

    @staticmethod
    def UpdateBrowserSize(WindowHandle parent_window_handle,
                          PyBrowser browser,
                          py_bool redraw=True):
        cdef HWND innerHwnd = <HWND>browser.GetWindowHandle()
        if not innerHwnd:
            return
        cdef RECT rect2
        cdef BOOL result = GetClientRect(<HWND>parent_window_handle, &rect2)
        cdef UINT flags = SWP_NOZORDER
        if not redraw:
            flags = SWP_NOZORDER | SWP_NOREDRAW
        if result != 0:
            SetWindowPos(innerHwnd, NULL,
                rect2.left, rect2.top,
                rect2.right - rect2.left,
                rect2.bottom - rect2.top,
                flags)

wxpython.py

WindowUtils.UpdateBrowserSize,(self.browser_panel.GetHandle(), self.browser)

Activity

  1. cztomczak commented on Aug 29, 2018

    @cztomczak
    OwnerAuthor

    A temporary fix for the tkinter.py example in commit 38bcf0c. Using ctypes module to call SetWindowPos.

  2. changed the title [-]Fix issues with app hanging during window resize when calling WindowUtils.OnSize[/-] [+]Fix issues with app hanging during window resize when calling WindowUtils.OnSize. Expose new Browser.SetBounds method.[/+] on Jan 23, 2020
  3. added a commit that references this issue on Jan 28, 2020
  4. cztomczak commented on Jan 28, 2020

    @cztomczak
    OwnerAuthor

    Fixes in commit de6bcd5 in the dev branch. Expose Browser.SetBounds method, update examples and documentation. There are still sometimes hangs (although rare) when resizing window in wxpython.py and qt.py examples. Needs retesting after updating to latest CEF version.

  5. added a commit that references this issue on Nov 24, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions