我正在尝试在我的C#WPF应用程序中使用shell挂钩更改窗口最小化的矩形到HSHELL_GETMINRECT。
关注Win32 C API for redirecting minimize animation 我能够编组lParam参数中返回的结构,但我无法更改它的值,以便窗口获取新的矩形。
到目前为止,这是我的WndProc方法。
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;
}
答案 0 :(得分:0)
我需要为Windows添加return new IntPtr(1);
以使用新结构。