Hi all,
In my program I have an array of rectangles positioned in window client area. Now I need to determine on which rectangle user has clicked.
Hers is part of my code:
// hwnd - handle of window
// MAX_X=16 MAX_Y=32
case WM_NOTIFY:
{
int pos=GetMessagePos();
POINTS ps=MAKEPOINTS(pos);
POINT p={ps.x,ps.y};
ScreenToClient(hwnd,&p); // I think problem is here
// loop through array of rectangles rect
for(int i =0; i < MAX_Y; i++)
{
for(int j =0; j < MAX_X; j++)
{
if(PtInRect(&rect[i][j],p))
{
cry=i; crx=j;
Invert(hwnd,crx,cry);
break;
}
}
}
} break;
The messages and functions you really want to use are:
WM_LBUTTONDOWN
WM_LBUTTONUP
CaptureMouse function
ReleaseMouse function
PtInRect function (which you already know about)