If you click on the image that I have created...

This is a discussion on If you click on the image that I have created... within the Windows Programming forums, part of the Platform Specific Boards category; I know how to make an image. But I don't know how to execute somthing when the image is clicked ...

  1. #1
    Registered User Queatrix's Avatar
    Join Date
    Apr 2005
    Posts
    1,342

    Question If you click on the image that I have created...

    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.

  2. #2
    uh oh
    Join Date
    Jan 2005
    Location
    Ontario, CA
    Posts
    66
    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.

  3. #3
    train spotter
    Join Date
    Aug 2001
    Location
    near a computer
    Posts
    3,859
    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
    "Man alone suffers so excruciatingly in the world that he was compelled to invent laughter."
    Friedrich Nietzsche

    "I spent a lot of my money on booze, birds and fast cars......the rest I squandered."
    George Best

    "If you are going through hell....keep going."
    Winston Churchill

  4. #4
    Registered User Queatrix's Avatar
    Join Date
    Apr 2005
    Posts
    1,342
    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?

  5. #5
    train spotter
    Join Date
    Aug 2001
    Location
    near a computer
    Posts
    3,859
    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
    Last edited by novacain; 06-14-2005 at 12:04 AM.
    "Man alone suffers so excruciatingly in the world that he was compelled to invent laughter."
    Friedrich Nietzsche

    "I spent a lot of my money on booze, birds and fast cars......the rest I squandered."
    George Best

    "If you are going through hell....keep going."
    Winston Churchill

  6. #6
    Registered User Queatrix's Avatar
    Join Date
    Apr 2005
    Posts
    1,342
    thanks novacain.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. open and read bmp image files
    By cnewbie85 in forum C Programming
    Replies: 2
    Last Post: 05-19-2009, 01:36 AM
  2. LoadBitmap image not shown problem
    By what3v3r in forum Windows Programming
    Replies: 3
    Last Post: 12-14-2007, 03:38 AM
  3. image processing
    By ICool in forum C Programming
    Replies: 75
    Last Post: 10-15-2007, 04:42 AM
  4. Webcam Image Capture
    By AtomRiot in forum Windows Programming
    Replies: 6
    Last Post: 06-04-2007, 11:08 PM
  5. Memory Allocation in Intell Image processing liberary
    By nisar in forum Windows Programming
    Replies: 0
    Last Post: 01-12-2003, 06:29 AM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21