Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Overflow during the conversion from a Message.LParam to the Point for the NonClientHitTest #64

Open
PaceyIV opened this issue Dec 22, 2020 · 0 comments

Comments

@PaceyIV
Copy link

PaceyIV commented Dec 22, 2020

In the RibbonFormHelper::WndProc there is this peace of code

else if (m.Msg == WinApi.WM_NCHITTEST && (int)m.Result == 0) //0x84
{
        m.Result = new IntPtr(Convert.ToInt32(NonClientHitTest(WinApi.GetPoint(m.LParam))));
        handled = true;
}

The cast to int is wrong. I have received a message with LParam = 4294508536 that throw an Overflow exception.

I suggest this function to convert a LParam to the corresponding x,y coordinate

/// <summary>
/// Retrieve the signed x,y-coordinate from the specified LPARAM value`
/// </summary>
/// <param name="lParam"></param>
/// <returns></returns>
public static Point GetPoint(IntPtr lParam)
{
        int value = unchecked((int)(long)lParam);
        int x = (short)(value & 0xffff);
        int y = (short)((value >> 16) & 0xffff);
        return new Point(x, y);
}

See also this API https://docs.microsoft.com/en-us/windows/win32/api/windowsx/nf-windowsx-get_x_lparam

harborsiem added a commit that referenced this issue Sep 13, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant