microsoft / CsWin32

A source generator to add a user-defined set of Win32 P/Invoke methods and supporting types to a C# project.
MIT License
1.99k stars 84 forks source link

Add support for MAKEPOINTS, GET_X_LPARAM, GET_Y_LPARAM macros #1194

Open AffluentOwl opened 1 month ago

AffluentOwl commented 1 month ago

Problem

Each developer has to go out of their way to implement the MAKEPOINTS, GET_X_LPARAM, GET_Y_LPARAM macros manually when converting C++ code examples to C#. This adds one more point where bugs can be introduced, and slows down porting code due to this special case.

These are also some of the most basic and widely used macros, as they are used for handling clicks on forms. They are commonly found in Hello World Win32 examples. https://learn.microsoft.com/en-us/windows/win32/inputdev/wm-lbuttonup

Solution

Add the macros just like the opposite macros, which already exist, to combine shorts into a single int.

Alternative

Each developer has to go out of their way to implement this macro manually when converting C++ code examples to C#.

POINTS p = new ()
{
  x = (short)lParam,
  y = (short)(lParam >> 16),
};
AArnott commented 4 weeks ago

Sounds good. Thanks for the suggestion. Are you interested in submitting a pull request, like the one you already found?