✅ 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. 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,
}
2 Replies
Hazel 🌊💃
Hazel 🌊💃10mo ago
$code
MODiX
MODiX10mo ago
To post C# code type the following: ```cs // code here ``` Get an example by typing $codegif in chat For longer snippets, use: https://paste.mod.gg/
Want results from more Discord servers?
Add your server