Subj : Re: Need help with cursor managment To : borland.public.cpp.borlandcpp From : Bob Gonder Date : Wed Jun 23 2004 03:56 pm Jeff Baker wrote: >Yeah I played with that but I just couldn't get it to work correctly (I'm >sure it's just me). I don't know how to use it correctly and I have no >documentation showing an example. I'd be more then happy if someone could >show me an example of it's use with this code. Just guessing at this... case WM_SETCURSOR: if( hwndOfControlImInteresedIn == (HWND) wParam ) { if( 0 == LOWORD(lParam) ) // hit-test code { SetCursor(arrow); }else{ SetCursor(cross); }; >One more question, is there a way to use PtInRect so that it only returns >true if the point is inside the rect? The PtInRect returns true if the point >is to the left or above the rect as well as inside of it. > >case WM_PAINT: > { > GetClientRect(hwnd,&ta); > ta.left += 100; > ta.top += 100; > ta.right -= 100; > ta.bottom -= 100; What if ta.left > ta.right or top>bottom? Better check that. That's probably why you are getting a hit "outside" the rect. > case WM_MOUSEMOVE: > { > GetCursorPos(&loc); /* loc = screen coords */ > MapWindowPoints(HWND_DESKTOP,hwnd,&loc,2); loc is a POINT, not a RECT. Last param should be 1. Note: That might affect ta if it is after loc in memory. ScreenToClient(hwnd,&loc) might be simpler. Might want to do the GetClientRect in here. Or, use GetWindowRect(hwnd,&ta) to have it in screen coords. > if (PtInRect(&ta,loc)) SetCursor(cross); > else SetCursor(arrow); > ShowCursor(TRUE); > } break; So: GetCursorPos(&loc);/* loc = screen coords */ ScreenToClient(hwnd,&loc);/*local coords*/ GetClientRect(hwnd,&ta);/*local coords*/ Or: GetCursorPos(&loc);/* loc = screen coords */ GetWindowRect(hwnd,&ta);/*screen coords*/ Then: ta.left += 100; ta.top += 100; ta.right = ta.left+50;/*or whatever*/ ta.bottom = ta.top+20;/*or whatever*/ if (PtInRect(&ta,loc)) SetCursor(cross); .