I know how to make an image. But I don't know how to execute somthing when the image is clicked on. Can any one show me how to do that?
Thanks in advance, August.
Printable View
I know how to make an image. But I don't know how to execute somthing when the image is clicked on. Can any one show me how to do that?
Thanks in advance, August.
Check your main window events for WM_LBUTTONDOWN and WM_LBUTTONUP messages. Check MSDN for exact specs on these windows event messages. These will give you the notice that the left mouse button is either down (clicked) or up (un-clicked). When you receive the WM_LBUTTONUP message it means that your left mouse button was clicked, then released (used incase the button is held). Now these messages (from what I remember) will give you the mouse co-ords on the screen of where the mouse cursor is. By determining the position of the image you have a boundary. Compare the mouse co-ords against your boundary to see if it's within that area. Then execute code if the mouse click is within.
Hope this helps.
The coods are based on what is the top left corner, the screen or the dialog. Make sure you convert to the same set of coords
ie both in screen or both in dialog.
Look at
ClientToScreen() and the reverse
PtInRect() might also be helpful
I'm not sur I think I know what you meant,
but from what it sounds like and from what I can think of,
I only need to know how to read the X-Y posistion of the cursor.
Could you show me how to do that?
something like......
Code:case WM_LBUTTONDOWN:
//find point clicked
POINT ptMouse;
ptMouse.x = GET_X_LPARAM(lParam);
ptMouse.y = GET_Y_LPARAM(lParam);
//convert to screen coods
ClientToScreen(hWnd, &prMouse);
//get the images coods
RECT rcImage;
HWND hwndImage = GetDlgItem(hWnd, IDC_IMAGE); // use your image controls resource ID#
//get the image coods in screen coods
GetWindowRect(hwndImage, &rcImage);
//check to see if mouse is in image
if(PtInRect(&rcImage, ptMouse)==TRUE)
//image was clicked
thanks novacain.