Click here to Skip to main content
15,876,991 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
hi all:-)

I have Cwnd in which i draw a .png-file. (First i convert it to a CBitmap, then i draw it)

Now i need a hittest-function: If a user clicks on the png-Image, is there a way to find the pixel, he clicked on?

What would help me too:

If there is for example a circle in the png, is there a way to find the area of this circle in screen-coordinates, or is there a method to find, if a click on the png-image was inside this circle?

thx for any help!
Sergey Alexandrovich Kryukov 20-Feb-15 3:03am    
Wrong approach, I would say. Why doing so?
Member 10781325 20-Feb-15 3:14am    
i am just searching a way of knowing, where to user did the click in the png-image. Do you have an idea, or an approach to achieve this?

What i have is a picture with several enclosed areas. Now i want to invoke different functions, depending on which area the user clicked on.
Richard MacCutchan 20-Feb-15 3:53am    
You can use one of the various mouse messages/notifications to find the pixel that was clicked; that part is easy. However, image analysis is far more complex, since you have to account for shading and colour blending. Use Google to find one of the libraries that deal with the subject.

1 solution

You must handle the mouse messages. For that you must overwrite the message handler in your window. Here is the Microsoft documentation for the mouse messages. You must fetch the click coordinates and than check it with the coordinates of your picture.
Share this answer
Member 10781325 20-Feb-15 7:09am    
yes, thanks all! i found a way: mouse Messages-> coordinates of click. With this, i can find the Pixel which was clicked. When i create the Picture, i hold a second Bitmap in the Background (not drawn, but same size), whose Pixels tell me, in which Region the click was. (e.g. red Pixels mean in Region 1, black Pixels in Region 2 and so on)

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900