Setting WS_CHILD on preview handler (#3048)

This commit is contained in:
chrisgch 2020-06-12 00:32:35 +02:00 committed by GitHub
parent 071ea1dc97
commit ccfc4d68f3
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -14,6 +14,12 @@ namespace Common
/// </summary>
public abstract class FormHandlerControl : Form, IPreviewHandlerControl
{
/// <summary>
/// Needed to make the form a child window.
/// </summary>
private static int gwlStyle = -16;
private static int wsChild = 0x40000000;
/// <summary>
/// Holds the parent window handle.
/// </summary>
@ -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);
/// <summary>
/// Update the Form Control window with the passed rectangle.
/// </summary>
@ -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;
});