Custom dwm drawn window frame flickers on resizing if the window contains a HwndHost element
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.
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); }