ios198
ios198

Reputation: 37

mouse click to get coordinates of picture control-MFC

I created a picture control (type: frame) to display image. Now I want to use mouse to click specified coordinates of picture control to show position and R, G,B values. How could I solve this problem?

Upvotes: 0

Views: 1035

Answers (1)

Roel
Roel

Reputation: 19642

Catch the WM_LBUTTONDOWN message. Get x/y coordinates from lParam (see MSDN for details). Get bits from image using GetDIBits(). Read RGBA from bitmap buffer you got from GetDIBits(), at the location x/y you got from lParam. This assumes your picture control doesn't do scaling etc., you'd have to correct x/y for that. Alternatively, you could use the ::PrintWindow() API to get a copy of the window into a DC; you could then use GetPixel() on the DC to get a COLORREF. Come to think of it, this is probably a better solution, if you're only after one RGB value.

Upvotes: 1

Related Questions