How to get mouse X,Y position in a specified area of window. Winapi



If i have like a 1000x1000 Window, and i am placing an image in the middle of that window (its less than 1000x1000 pixels), so the image is smaller than the window itself.

Now if the user clicks anywhere on that blitted image, I want to return the X,Y coordinates that that image was clicked.

Obviously what i would do is get the clicked coordinate with the GET_X/Y_LPARAM And subtract it from the space in between space around the picture.

Is there an easier way to do this? Can u redirect the orientation of get_x/y_ param?
This if statement is the easiest way I know to determine if a rectangle-shaped item on screen was clicked on.

x and y are the mouse-click points that you got from WM_LBUTTONDOWN's lparam LOWORD() and HIWORD()
1
2
3
4
5
6
7
static RECT pic;  //some rectangle that you define earlier in the program that represents
                          //where the picture is on screen

if(x > pic.left && x < pic.right && y > pic.top && y < pic.bottom)
{
//mouse clicked on pic's rectangle.
}


How you define 'pic' is going to depend on how you set the picture to your screen. Use the points in 'pic' as your sizes in your StretchBLT() function. If you want help with that then I would need to see some of your code. I usually define pic in my case WM_SIZE: process with something like

1
2
3
4
5
6
RECT crect;
GetClientRect(&crect);
pic.top = crect.bottom/4;
pic.bottom = crect.bottom/2;
pic.left = crect.left + 40;
pic.right = crect.right;


because I want the picture to resize with the screen.

Post some relevant code if you want more in-depth and less scattered help.
Last edited on
Topic archived. No new replies allowed.