Custom dwm drawn window frame flickers on resizing if the window contains a HwndHost element

时光总嘲笑我的痴心妄想 提交于 2019-12-03 14:44:26

I solved it by adding WS_CLIPCHILDREN as a style when CreatWindowEx

protected override HandleRef BuildWindowCore(HandleRef hwndParent)
{
    _hwndHost = Win32Api.CreateWindowEx(0, "Static", "", 
                        (int) (WS_CHILD | WS_VISIBLE | WS_CLIPCHILDREN),
                      0, 0,
                      _hostWidth, _hostHeight,
                      hwndParent.Handle,
                      IntPtr.Zero,
                      IntPtr.Zero,
                      0);

 }

Well, I finally found a fix but I think this one borders on black magic... anyway it turns out that responding to WM_NCCALCSIZE with any rect smaller than the window solves the problem. So for example changing the handler to look like below removes the flicker!

            case WM.NCCALCSIZE:
                if( wParam != IntPtr.Zero ) {
                    handled = true;
                    var client = (RECT)Marshal.PtrToStructure( lParam, typeof( RECT ) );
                    client.Bottom -= 1;
                    Marshal.StructureToPtr( client, lParam, false );
                }
                break;

I have no idea why this is working and I'm sure that a saner solution exists, so I'd be happy if someone could enlighten me.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!