Determining if mouse pointer is in rect

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:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
// 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;         
         

But why doesn't it work?
Thanks for help.
Last edited on
WM_NOTIFY isn't the message to use for this.

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)

Look up WM_CONTEXTMENU in MSDN. That is exactly what you want, and the MSDN section gives workable examples.
I thought WM_CONTEXTMENU message came in on the Right mouse button
Ooops. That's correct.
Thanks.
Topic archived. No new replies allowed.