another question on BeginPaint()

This is a discussion on another question on BeginPaint() within the Windows Programming forums, part of the Platform Specific Boards category; it says Windows restricts painting within the invalid region returned by BeginPaint...this means we cant paint anywhere else on the ...

  1. #1
    samurai warrior nextus's Avatar
    Join Date
    Nov 2001
    Posts
    196

    another question on BeginPaint()

    it says Windows restricts painting within the invalid region returned by BeginPaint...this means we cant paint anywhere else on the window?

    this is also from petzold's book
    nextus, the samurai warrior

  2. #2
    Ecologist
    Join Date
    Aug 2001
    Location
    Utah.
    Posts
    1,291
    You can paint anywhere in the window. Begin/EndPaint() are just
    used to 'redraw' an invalidated area. If you want to 'redraw' the
    entire area, you can call InvalidateRect() before Begin/EndPaint()

    Code:
    BOOL InvalidateRect(
      HWND hWnd,  // handle of window with changed update region
      CONST RECT *lpRect, // address of rectangle coordinates
      BOOL bErase // erase-background flag
    );
    You'd first need to create a RECT that holds the coordinates of
    the client area of your window. Use GetClientRect()

    Code:
    BOOL GetClientRect(
      HWND hWnd,      // handle to window
      LPRECT lpRect   // address of structure for client coordinates
    );
    Code:
    LRESULT CALLBACK WindowProc(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam)
    {
      HDC gdc;
      RECT ClientArea;
      PAINTSTRUCT ps;
    
      GetClientArea(hwnd, &ClientArea);
    
      switch(msg)
      {
         case WM_PAINT:
                  InvalidateRect(hwnd, &ClientArea, false);
                  gdc = BeginPaint(hwnd, &ps);
                  EndPaint(hwnd, &ps)
                  return 0;
                  break;
        default: 
                 break;
      }
      return (DefWindowProc(hwnd, msg, wParam, lParam));
    }
    Or something like that. Maybe... I don't know.
    Staying away from General.

  3. #3
    Registered User Codeplug's Avatar
    Join Date
    Mar 2003
    Posts
    4,662
    An unoptimized paint routine will simply draw the entire client area and Windows will clip to only the invalidated region. I would start there. If need be, you can get fancy and write your code to only draw to the invalidated region.

    gg

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Alice....
    By Lurker in forum A Brief History of Cprogramming.com
    Replies: 16
    Last Post: 06-20-2005, 02:51 PM
  2. Debugging question
    By o_0 in forum C Programming
    Replies: 9
    Last Post: 10-10-2004, 05:51 PM
  3. Question about pointers #2
    By maxhavoc in forum C++ Programming
    Replies: 28
    Last Post: 06-21-2004, 12:52 PM
  4. Question...
    By TechWins in forum A Brief History of Cprogramming.com
    Replies: 16
    Last Post: 07-28-2003, 09:47 PM
  5. Question, question!
    By oskilian in forum A Brief History of Cprogramming.com
    Replies: 5
    Last Post: 12-24-2001, 12:47 AM

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