In view of the need, it makes no sense to transfer both parameters to the method, as well as to allocate dynamic memory for POINTS during the processing of a WM_MOUSEMOVE , WM_LBUTTONDOWN message, etc. It is necessary to use MAKEPOINTS(lparam) , which contributes to the creation of an object that is actually not needed, and the macro definitions GET_X_LPARAM and GET_Y_LPARAM do not work. But on the MSDN website there is information that if you work with these macro definitions, you can get incorrect data if the user has several monitors. How to do without these macros when connecting the windowsx.h header does not make sense for the sake of 2 macros.

  • And what does "GET_X_LPARAM and GET_Y_LPARAM macros do not work"? How did you try to make them work? Add a piece of code to the question to make it clear what is being said. - mega
  • @mega: Worked as HIWORD and LOWORD , int x = HIWORD(lparam), y = LOWORD(lparam); Always returns 0 - LLENN
  • 2
    Ok, then let's do this in order: int x = (short)HIWORD(lparam), y = (short)LOWORD(lparam); . Problem still exists? - mega
  • @mega: Thank you so much! The problem has disappeared. - LLENN
  • Then read the article on the "sign extension". Here, for example: en.wikipedia.org/wiki/Sign_extension - mega

1 answer 1

Macros GET_X_LPARAM and GET_Y_LPARAM certainly work and return correct values ​​regardless of the number of monitors. If you find somewhere in the documentation that it’s not true, this may be a mistake. They are defined in the header file as follows:

 #define GET_X_LPARAM(lp) ((int)(short)LOWORD(lp)) #define GET_Y_LPARAM(lp) ((int)(short)HIWORD(lp)) 

As you can see, the return type is int (signed), so negative coordinates will be processed correctly.

How to do without these macros when connecting the windowsx.h header does not make sense for the sake of 2 macros.

If you need only some separate definitions from the header file, you can simply copy them into your code. The effect will be the same.