0

Say I create a polygon with the Polygon function, and i'd like it to accept input from the mouse (similar to a button).

How would I do that?

EDIT:
Processing the WM_LBUTTONDOWN and WM_MOUSEMOVE messages, I'm using this code to check if the mouse is in the area of the polygon:

if (LOWORD(lParam) < 375 && LOWORD(lParam) > 340 &&
    HIWORD(lParam) < 200 && HIWORD(lParam) > 90)

Problem is, the polygon is not a rectangle, its a polygon. So how would I go about detecting if the mouse was in the polygon only?

EDIT 2: I should also note, its only a triangle lol. Hope that makes this simpler.

Josh
  • 6,046
  • 11
  • 52
  • 83

2 Answers2

0

Polygon() is a function that is used to draw to a device context. As such it cannot receive inupt. You need a windowed control to do that.

Handle the input in your window and use a hit test to check if you are inside the polygon.

David Heffernan
  • 601,492
  • 42
  • 1,072
  • 1,490
0

A polygon can't accept input, it must be done through the window that the polygon was drawn on. Listen for the WM_LBUTTONDOWN message and look at the coordinates delivered with the message; determine if the coordinate is within the polygon or not. The easiest way to do that might be to draw the polygon on a bitmap the same size as the window, and test the point on the bitmap to see if it is the polygon color or not.

Mark Ransom
  • 299,747
  • 42
  • 398
  • 622