Completed
Last Updated: 09 Nov 2021 09:01 by ADMIN
Release R3 2021 SP1
Massimo
Created on: 13 Oct 2021 15:19
Category: UI for WinForms
Type: Feature Request
0
RadForm: When the mouse is over the maximize button, the snap layouts window is not shown in Windows 11

The snap layouts window can be opened by using the Win+Z keyboard combination, but when the mouse is over the Maximize button of RadForm, the window is not shown.
MSDN information is available here: https://docs.microsoft.com/en-us/windows/apps/desktop/modernize/apply-snap-layout-menu

Following the guides from MSDN, we need to override the WndProc method of the form, listen to the WM_NCHITTEST message, and return HTMAXBUTTON result when the mouse is over the maximize button.


private const int HTMAXBUTTON = 9;
protected override void WndProc(ref Message m)
{
    if (m.Msg == NativeMethods.WM_NCHITTEST)
    {
        // Get the hit test location from message parameters
        Point location = this.ParseIntPtr(m.LParam);
        location = this.GetMappedWindowPoint(location);

        // Get the hit tested element and check if it is the Maximize button
        RadElement element = this.ElementTree.GetElementAtPoint(location);
        if (element == this.FormElement.TitleBar.MaximizeButton)
        {
            m.Result = new IntPtr(HTMAXBUTTON);
            return;
        }
    }

    base.WndProc(ref m);
}

private Point ParseIntPtr(IntPtr param)
{
    if (IntPtr.Size == 4) //x86
    {
        return new Point(param.ToInt32());
    }
    else //x64
    {
        long intParam = param.ToInt64();
        short x = (short)intParam;
        short y = (short)(intParam >> 16);
        return new Point(x, y);
    }
}

protected virtual Point GetMappedWindowPoint(Point screenPoint)
{
    NativeMethods.POINT inputPoint = new NativeMethods.POINT();
    inputPoint.x = screenPoint.X;
    inputPoint.y = screenPoint.Y;

    if (this.IsHandleCreated)
    {
        NativeMethods.MapWindowPoints(new HandleRef(this, IntPtr.Zero), new HandleRef(this, this.Handle), inputPoint, 1);
    }

    return new Point(
    inputPoint.x + this.FormBehavior.ClientMargin.Left,
    inputPoint.y + this.FormBehavior.ClientMargin.Top);
}

              
0 comments