Solve WPF nested sub-window resizing the window when the flicker problem

Disclaimer: This article is a blogger original article, follow the CC 4.0 BY-SA copyright agreement, reproduced, please attach the original source link and this statement.
This link: https://blog.csdn.net/WPwalter/article/details/102775135

Because the Win32 window handle is passed across process, it can be used to achieve inter-process UI. However, this article will not talk about specific cross-process UI will only mention a significant and ease of implementation, the way the use of child windows.

You may use after the child window, found the drag resize the window when the contents of the child window flashing. If you have encountered such a problem, then just read this article to resolve.


In this article

problem

You can look at this dynamic figure below, feel the window flashing:

Window Flashing

In fact, when dragging the window, it is always in a flash, but each flash is very fast, gif interception when less than cut.

If you want to actually run a race to see the project, you can use the following code:

I have looked at the code extracted a submission, if you want to try, you can not use masterbranches because masterbranch fixes flicker problem.

Later use CreateWindowExto create a pure Win32 window, this flickering is more likely to be shot:

Win32 window flashing
Win32 window flashing - movable FIG.

solve

    public class HwndWrapper : HwndHost
    {
        protected override HandleRef BuildWindowCore(HandleRef hwndParent)
        {
            const int WS_CHILD = 0x40000000;
++          const int WS_CLIPCHILDREN = 0x02000000;
            var owner = ((HwndSource)PresentationSource.FromVisual(this)).Handle;

            var parameters = new HwndSourceParameters("demo")
            {
                ParentWindow = owner,
--              WindowStyle = (int)(WS_CHILD),
++              WindowStyle = (int)(WS_CHILD | WS_CLIPCHILDREN),
            };
            var source = new HwndSource(parameters);
            source.RootVisual = new ChildPage();
            return new HandleRef(this, source.Handle);
        }

        protected override void DestroyWindowCore(HandleRef hwnd)
        {
        }
    }

the reason

We are exploring ......


Reference material


My blog will be starting in https://blog.walterlv.com/ , and will be released from CSDN which featured, but it is rarely updated once released.

If you see any do not understand the contents of the blog, please share. I built dotnet Vocational and Technical College welcome to join.

Creative Commons License

This work is Creative Commons Attribution - NonCommercial - ShareAlike 4.0 International License Agreement for licensing. Welcome to reprint, use, repost, but be sure to keep the article signed by Lu Yi (containing links: https://walterlv.blog.csdn.net/ ), shall not be used for commercial purposes, a work based on the article be sure to modify the same license release. If you have any questions, please contact me .

Guess you like

Origin blog.csdn.net/WPwalter/article/details/102775135