the SendMessage function

If you want to simulate a mouse click programatically, you must know the SendMessage function. To make your simulator work, you should understand the function well. First, the name is SendMessage, not sendMessage. The prototype of this function is:

LRESULT WINAPI SendMessage(
_In_ HWND   hWnd,
_In_ UINT   Msg,
_In_ WPARAM wParam,
_In_ LPARAM lParam
);

 

To simulate a mouse click, you should use the following code:

SendMessage(hwnd,WM_LBUTTONDOWN,MK_LBUTTON,MAKELPARAM(x,y));

SendMessage(hwnd,WM_LBUTTONUP,0,MAKELPARAM(x,y));

 

The confusing point is the third parameter which indicates “whether various virtual keys are down”. However, for a mouse click, this parameter seems redundant considering the second parameter. Some programmers may write the following code:

SendMessage(hwnd,WM_LBUTTONDOWN,0,MAKELPARAM(x,y));

SendMessage(hwnd,WM_LBUTTONUP,0,MAKELPARAM(x,y));

 

or,

SendMessage(hwnd,WM_LBUTTONDOWN,MK_LBUTTON,MAKELPARAM(x,y));

SendMessage(hwnd,WM_LBUTTONUP,MK_LBUTTON,MAKELPARAM(x,y));

 

Unfortunately, both the above two do not work. Also pay attention to the x,y coordinates, which are the positions of the click relative to the left-top of hwnd.

Comments are closed, but trackbacks and pingbacks are open.