From ccfc4d68f358d943b4934bb7809891e332857e41 Mon Sep 17 00:00:00 2001 From: chrisgch Date: Fri, 12 Jun 2020 00:32:35 +0200 Subject: [PATCH] Setting WS_CHILD on preview handler (#3048) --- .../common/controls/FormHandlerControl.cs | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) diff --git a/src/modules/previewpane/common/controls/FormHandlerControl.cs b/src/modules/previewpane/common/controls/FormHandlerControl.cs index 7c5de79574..b7b055852d 100644 --- a/src/modules/previewpane/common/controls/FormHandlerControl.cs +++ b/src/modules/previewpane/common/controls/FormHandlerControl.cs @@ -14,6 +14,12 @@ namespace Common /// public abstract class FormHandlerControl : Form, IPreviewHandlerControl { + /// + /// Needed to make the form a child window. + /// + private static int gwlStyle = -16; + private static int wsChild = 0x40000000; + /// /// Holds the parent window handle. /// @@ -150,6 +156,12 @@ namespace Common [DllImport("user32.dll", CharSet = CharSet.Auto)] private static extern IntPtr GetFocus(); + [DllImport("user32.dll", SetLastError = true)] + private static extern int GetWindowLong(IntPtr hWnd, int nIndex); + + [DllImport("user32.dll", SetLastError = true)] + private static extern int SetWindowLong(IntPtr hWnd, int nIndex, int dwNewLong); + /// /// Update the Form Control window with the passed rectangle. /// @@ -158,6 +170,13 @@ namespace Common { this.InvokeOnControlThread(() => { + // We must set the WS_CHILD style to change the form to a control within the Explorer preview pane + int windowStyle = GetWindowLong(this.Handle, gwlStyle); + if ((windowStyle & wsChild) == 0) + { + SetWindowLong(this.Handle, gwlStyle, windowStyle | wsChild); + } + SetParent(this.Handle, this.parentHwnd); this.Bounds = windowBounds; });