private void CreateHwndSource(IntPtr handle) { var rect = GetContainerArea(handle); var hwndSourceParameters = new HwndSourceParameters() { ParentWindow = handle, AcquireHwndFocusInMenuMode = false, PositionX = rect.Left, PositionY = rect.Top, Width = rect.Width, Height = rect.Height, WindowStyle = -2113929216, ExtendedWindowStyle = 524292 | Win32NativeMethods.WS_EX_TRANSPARENT, UsesPerPixelOpacity = true, WindowName = FrameName, }; var hwndSource = new HwndSource(hwndSourceParameters) { RootVisual = this }; var tableAbove = Win32NativeMethods.GetWindow(handle, (uint)GetWindowConsts.GW_HWNDPREV); Win32NativeMethods.SetWindowPos(hwndSource.Handle, tableAbove, 0, 0, 0, 0, (uint)SetWindowPosConsts.SWP_SHOWWINDOW | (uint)SetWindowPosConsts.SWP_NOACTIVATE | (uint)SetWindowPosConsts.SWP_NOMOVE | (uint)SetWindowPosConsts.SWP_NOSIZE); _hwndSource = hwndSource; }
private Rect GetContainerArea(IntPtr handle) { var area = new Rect(); Win32NativeMethods.GetWindowRect(handle, ref area); return(area); }
public void RefreshPosition(IntPtr handle) { var rect = GetContainerArea(handle); Win32NativeMethods.MoveWindow(_hwndSource.Handle, rect.Left, rect.Top, rect.Width, rect.Height, true); }