开发者

I need to know the x and y coordinates of the button click when a WM_COMMAND is activated

开发者 https://www.devze.com 2022-12-26 04:22 出处:网络
I have a button created with //Create Compass HWND hWndCompass = CreateWindowEx(NULL, \"BUTTON\", \"Compass\", WS_TABSTOP|WS_VISIBLE|WS_CHILD|BS_DEFPUSHBUTTON,

I have a button created with

//Create Compass
    HWND hWndCompass = CreateWindowEx(NULL, "BUTTON", "Compass", WS_TABSTOP|WS_VISIBLE|WS_CHILD|BS_DEFPUSHBUTTON,
        600, 开发者_StackOverflow中文版10, 50, 24, hWnd, (HMENU)IDC_COMPASS, GetModuleHandle(NULL), NULL);

I will add the picture in the future but I need to know where on the button they clicked so I can determine if they clicked on N, S, E, W or some other point of the compass.

My call is:

LRESULT CALLBACK WndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam)

Do I need to look in the message for that infomration?


In order to retrieve the X and Y coordinates of a mouse click on your button, you should :

  • In the WndProc() function, catch the WM_MOUSEMOVE event
  • Once the event is raised, wParam will give you the type of event (Which button has been pressed)
  • On the desired event, you are able to retrieve the coordinates through lParam

Something like that :

RESULT CALLBACK WndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam)
{
  switch (message)
  {
    case WM_MOUSEMOVE:
    {
      if (lParam == MK_LBUTTON)
      {
        myXCoord = GET_X_LPARAM(lParam); 
        myYCoord = GET_Y_LPARAM(lParam); 
      }
    }
    break;
    default:
      DefWindowProc(hWnd, message, wParam, lParam);
  }
}
  • For more information about the WM_MOUSEMOVE message, go to : http://msdn.microsoft.com/en-us/library/ms645616%28v=vs.85%29.aspx
0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号