I am trying to change the rectangle in which windows are minimized with a shell hook to HSHELL_GETMINRECT in my C# WPF application.
Following this Win32 C API for redirecting minimize animation I was able to marshal the structure returned in the lParam parameter, but i can't change it's value so that windows gets the new rectangle.
This is my WndProc method so far.
public IntPtr WndProc(IntPtr hwnd, int msg, IntPtr wParam, IntPtr lParam, ref bool handled)
{
// If windows sends the HSHELL_GETMINRECT event, a window in the taskbar is minimizing or maximizing.
if (wParam.ToInt32() == WindowInterop.HSHELL_GETMINRECT)
{
var param = Marshal.PtrToStructure<WindowInterop.MinRectParam>(lParam);
var icon = FindIcon(param.hWnd);
var rect = new WindowInterop.SRect
{
Bottom = (short)(icon.Y + icon.Height),
Left = (short)icon.X,
Right = (short)(icon.X + icon.Width),
Top = (short)icon.Y
};
var newParam = new WindowInterop.MinRectParam
{
hWnd = param.hWnd,
Rect = rect
};
// As I understand it, this will only create a new IntPtr pointing to the structure,
// it won't write the new structure to the existing pointer's location.
Marshal.StructureToPtr(newParam, lParam, true);
handled = true;
}
return IntPtr.Zero;
}