Skip to content

Window border and icon was missing after invoking Win32 API 'SetWindowLong' #5001

@raphael008

Description

@raphael008
  • .NET Framework Version: 4.8
  • Windows version: 20H2 - 19042.1110
  • Does the bug reproduce also in WPF for .NET Framework 4.8?: Yes
  • Is this bug related specifically to tooling in Visual Studio (e.g. XAML Designer, Code editing, etc...)? No

WPF window border(left, right and bottom) and icon was missing after invoking Win32 API 'SetWindowLong'.
Someone found the same issue since 2016, but seems still not fixing, click here to see the details.

private void HideFromProgramSwitcher()
{
      var handle = GetMainWindowHandle();
      int style = NativeMethods.GetWindowLong(handle, -20);
      windowStyle = style; // windowStyle is used to store original window style.
      NativeMethods.SetWindowLong(handle, -20, style | 0x00000080);
}

private void ShowFromProgramSwitcher()
{
    var handle = GetMainWindowHandle();
    NativeMethods.SetWindowLong(handle, -20, windowStyle);
}

Actual behavior: only the top border displayed and icon was missing.
image

Expected behavior: left, right and bottom border should be displayed as well.
image

Minimal repro: This can be reproduced in .NET 4.7.2 & 4.8

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions