© 2026 Hedgehog Software, LLC

TwitterGitHubDiscord
More
CommunitiesDocsAboutTermsPrivacy
Search
Star
Setup for Free
C#C
C#•2y ago•
2 replies
incel detector

✅ How to intercept and cancel minimize events | C# WPF newbie

I have a borderless C# WPF window that supports aerosnap, aeroglass, and the native windows animations.

I am not sure why the minimize animation does not work when it gets minimized from clicking the app icon from the taskbar.

So initially, I thought maybe I should somehow intercept an event before the windows gets actually minimized, and then add the code
this.WindowState = WindowState.Minimized
this.WindowState = WindowState.Minimized
. If not, maybe intercepting if the taskbar button ( window app icon ) was clicked, and also manually minimizing it through setting window states. If both aren't solutions, there should be some sort of "native check" to see if an application icon was clicked from the taskbar and maybe hook that function, IDK WHAT IM TALKING ABOUT 😦

public void SetAnimation(IntPtr handle)
{
        SetWindowLong(handle, -16, (long)StyleFlag.acrylic);
        SetWindowPos(handle, IntPtr.Zero, 0, 0, 0, 0, 0x0020 | 0x0002 | 0x0001); // SWP_FRAMECHANGED | SWP_NOMOVE | SWP_NOSIZE
        ShowWindow(handle, 5);
}

public enum WindowStyles : uint
{
        WS_OVERLAPPEDWINDOW = 0x00CF0000,
        WS_POPUP = 0x80000000,
        WS_THICKFRAME = 0x00040000,
        WS_CAPTION = 0x00C00000,
        WS_SYSMENU = 0x00080000,
        WS_MINIMIZEBOX = 0x00020000,
        WS_MAXIMIZEBOX = 0x00010000
}


public enum StyleFlag : uint
{

    acrylic = WindowStyles.WS_POPUP | WindowStyles.WS_THICKFRAME | WindowStyles.WS_CAPTION | WindowStyles.WS_SYSMENU | WindowStyles.WS_MAXIMIZEBOX | WindowStyles.WS_MINIMIZEBOX,
}
public void SetAnimation(IntPtr handle)
{
        SetWindowLong(handle, -16, (long)StyleFlag.acrylic);
        SetWindowPos(handle, IntPtr.Zero, 0, 0, 0, 0, 0x0020 | 0x0002 | 0x0001); // SWP_FRAMECHANGED | SWP_NOMOVE | SWP_NOSIZE
        ShowWindow(handle, 5);
}

public enum WindowStyles : uint
{
        WS_OVERLAPPEDWINDOW = 0x00CF0000,
        WS_POPUP = 0x80000000,
        WS_THICKFRAME = 0x00040000,
        WS_CAPTION = 0x00C00000,
        WS_SYSMENU = 0x00080000,
        WS_MINIMIZEBOX = 0x00020000,
        WS_MAXIMIZEBOX = 0x00010000
}


public enum StyleFlag : uint
{

    acrylic = WindowStyles.WS_POPUP | WindowStyles.WS_THICKFRAME | WindowStyles.WS_CAPTION | WindowStyles.WS_SYSMENU | WindowStyles.WS_MAXIMIZEBOX | WindowStyles.WS_MINIMIZEBOX,
}
C# banner
C#Join
We are a programming server aimed at coders discussing everything related to C# (CSharp) and .NET.
61,871Members
Resources

Similar Threads

Was this page helpful?
Recent Announcements

Similar Threads

Using C# to intercept touchpad input?
C#CC# / help
2y ago
✅ How To Run CMD C WPF
C#CC# / help
4y ago
How to save and restore window position in wpf c#
C#CC# / help
3y ago