views:

12

answers:

1

I have a button created with

//Create Compass
    HWND hWndCompass = CreateWindowEx(NULL, "BUTTON", "Compass", WS_TABSTOP|WS_VISIBLE|WS_CHILD|BS_DEFPUSHBUTTON,
        600, 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?

+1  A: 

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);
  }
}
Xavier V.