public void ShowPreview(int previewHandle, string rootVisualPropertyName) { V preview = this.CreateWindow(System.Windows.Forms.Screen.PrimaryScreen, true); IntPtr previewPointer = new IntPtr(previewHandle); Interop.Rectangle clientRectange = new Interop.Rectangle(); bool result = Interop.Win32Api.GetClientRect(previewPointer, ref clientRectange); HwndSourceParameters sourceParams = new HwndSourceParameters("sourceParams"); sourceParams.PositionX = 0; sourceParams.PositionY = 0; sourceParams.Height = clientRectange.Bottom - clientRectange.Top; sourceParams.Width = clientRectange.Right - clientRectange.Left; sourceParams.ParentWindow = previewPointer; sourceParams.WindowStyle = (int)(Interop.WindowStyles.WindowStyleVisible | Interop.WindowStyles.WindowStyleChild | Interop.WindowStyles.WindowStyleClipChildren); try { // at this point a window with the specified handle may no longer exist, so we wrap this in a try-catch this.hostWindow = new HwndSource(sourceParams); } catch (Exception) { return; } this.hostWindow.Disposed += OnHostWindowDisposed; this.hostWindow.RootVisual = (Visual)preview.FindName(rootVisualPropertyName); }
public static extern bool GetClientRect(IntPtr hWnd, ref Rectangle lpRect);