Drawing focus rectangles

This is a discussion on Drawing focus rectangles within the Windows Programming forums, part of the Platform Specific Boards category; Hi, I'm trying to add the ability for a user to select multiple objects within my window via dragging the ...

  1. #1
    Registered /usr
    Join Date
    Aug 2001
    Location
    Newport, South Wales, UK
    Posts
    1,262

    Unhappy Drawing focus rectangles

    Hi,

    I'm trying to add the ability for a user to select multiple objects within my window via dragging the mouse to create a focus rectangle (or bounding box) around the objects they wish to select. The thing is, I would like to know the best painting practices for this process. I've currently written (in the WindowProc):-
    Code:
    (iButton and ptPos are global variables... I'll fix that when this works!)
    case WM_LBUTTONDOWN:
    {
    	ptPos.x = MAKEPOINTS(lParam).x;
    	ptPos.y = MAKEPOINTS(lParam).y;
    	iButton = TRUE;
    	break;
    }
    case WM_LBUTTONUP:
    {
    	iButton = FALSE;
    	break;
    }
    case WM_MOUSEMOVE:
    {
    	if (iButton == TRUE)
    	{
    		HDC dc;
    		RECT rc;
    		
    		dc = GetDC(hwnd);
    		rc.left = ptPos.x;
    		rc.top = ptPos.y;
    		rc.right = MAKEPOINTS(lParam).x;
    		rc.bottom = MAKEPOINTS(lParam).x;
    		DrawFocusRect(dc, &rc);
    		ReleaseDC(hwnd, dc);
    	}
    	break;
    }
    This generates a focus rectangle when the user holds the left mouse button down and drags it across the window. My point is, what's the best way to repaint the sections of the window formerly covered by the focus rectangle? It doesn't seem to deal properly with negative coordinates, either...

  2. #2
    Registered User
    Join Date
    Jul 2002
    Posts
    273
    Use the invert pen. Then when you want to erase it, use the invert pen again over the same rect then draw the new one.
    always looking, make an offer. get me out of this place.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Drawing two or more rectangles on client area.. HELP!
    By csonx_p in forum Windows Programming
    Replies: 2
    Last Post: 05-12-2008, 01:43 AM
  2. Drawing The Focus
    By SMurf in forum Windows Programming
    Replies: 1
    Last Post: 03-21-2006, 10:38 AM
  3. Problem drawing Rectangles and Text
    By cram in forum Windows Programming
    Replies: 2
    Last Post: 10-13-2004, 09:51 PM
  4. Drawing Rectangles and Text
    By cram in forum Windows Programming
    Replies: 7
    Last Post: 10-13-2004, 03:45 PM
  5. Focus & Always-On-Top :: MFC
    By kuphryn in forum Windows Programming
    Replies: 2
    Last Post: 06-13-2002, 05:44 PM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21