Skip to content

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

@cztomczak

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)

Metadata

Metadata

Assignees

No one assigned

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions