Thread: InvalidateRgn for clipped regions

  1. #1
    Registered User
    Join Date
    Apr 2008
    Posts
    610

    InvalidateRgn for clipped regions

    Hi, i've used InvalidateRng to invalidate a clipped rectangle region for updating (repainting) the region every few seconds and works perfectly. But, the moment i add one more region (Use CombineRgn to combine two regions) and call InvalidateRng with the handle to two regions to repaint, my edit controls, i get flickering... Can't InvalidateRng handle more than one clipped regions well?

  2. #2
    Registered User Codeplug's Avatar
    Join Date
    Mar 2003
    Posts
    4,981
    >> i've used InvalidateRng to invalidate a clipped rectangle region
    If it's a rectangle, just use InvalidateRect().

    >> moment i add one more region (Use CombineRgn to combine two regions)
    You don't have to do this either. Using Rects or Rgn's, both invalidate-functions will "accumulate" the invalidated regions for the next WM_PAINT.

    >> my edit controls, i get flickering
    If you aren't already - use WS_CLIPCHILDREN on the parent. Also handle WM_ERASEBKGND in the parent to do nothing. And exclude your controls form the update region if they don't need to repaint themselves.

    gg

  3. #3
    Registered User
    Join Date
    Apr 2008
    Posts
    610
    Quote Originally Posted by Codeplug View Post
    >> i've used InvalidateRng to invalidate a clipped rectangle region
    If it's a rectangle, just use InvalidateRect().
    Yes but InvalidateRect() updates the entire window (client window). I have rectangles in one window and need to update some of them

    >> moment i add one more region (Use CombineRgn to combine two regions)
    You don't have to do this either. Using Rects or Rgn's, both invalidate-functions will "accumulate" the invalidated regions for the next WM_PAINT.
    No, i don't think so...
    Code:
    BOOL InvalidateRgn(
      HWND hWnd,    // handle to window
      HRGN hRgn,    // handle to region
      BOOL bErase   // erase state
    );
    as you can see, hRgn expects you to specify 'which' region... how would InvalidateRgn function know which regions to 'accumulate' in a window anyway if not specified? My thoughts were to add two regions and assign them as a single combined region...
    >> my edit controls, i get flickering
    If you aren't already - use WS_CLIPCHILDREN on the parent. Also handle WM_ERASEBKGND in the parent to do nothing. And exclude your controls form the update region if they don't need to repaint themselves.
    gg
    Tried both a while ago and the WS_CLIPCHILDREN gave "Failed to register wnd class" when trying to run it .. I used WS_EX_COMPOSITED rather, worked well...

    thnx...

  4. #4
    Registered User Codeplug's Avatar
    Join Date
    Mar 2003
    Posts
    4,981
    >> Yes but...
    >> No, i don't think so...
    Read the documentation. I suggest you download MSDN locally so you don't have to hit the website.
    http://msdn.microsoft.com/en-us/libr...93(VS.85).aspx
    http://msdn.microsoft.com/en-us/libr...66(VS.85).aspx

    >> I used WS_EX_COMPOSITED rather, worked well...
    Nice. Another viable solution to most flicker issues.

    gg

  5. #5
    C++まいる!Cをこわせ!
    Join Date
    Oct 2007
    Location
    Inside my computer
    Posts
    24,654
    WS_EX_COMPOSITED is available from XP+, but since mostly everyone is running XP, it doesn't matter that much.
    It should apply double buffering to all child controls. THE single best feature I have seen in Windows to date.
    Quote Originally Posted by Adak View Post
    io.h certainly IS included in some modern compilers. It is no longer part of the standard for C, but it is nevertheless, included in the very latest Pelles C versions.
    Quote Originally Posted by Salem View Post
    You mean it's included as a crutch to help ancient programmers limp along without them having to relearn too much.

    Outside of your DOS world, your header file is meaningless.

  6. #6
    Registered User
    Join Date
    Apr 2008
    Posts
    610
    Quote Originally Posted by Codeplug View Post
    >>
    Read the documentation. I suggest you download MSDN locally so you don't have to hit the website.
    http://msdn.microsoft.com/en-us/libr...93(VS.85).aspx
    http://msdn.microsoft.com/en-us/libr...66(VS.85).aspx
    gg
    What knowledge do i lack really... I obviously have gone through the docs plenty of times for me to even comment on the two... Would be helpful if you identify my misconceptions regarding the two fuctions...

    Code:
    InvalidateRect(hdc, NULL, FALSE);
    : Updates entire client area

    Code:
    InvalidateRgn(hdc, region, FALSE);
    : Updates specified coordinates, region must have been created by CreateRectRgn() or similar functions...

    Code:
    InvalidateRect(hdc, &areaRect, FALSE);
    : Updates specified coordinates (areaRect)

    Now, where's my fault here?

  7. #7
    Registered User Codeplug's Avatar
    Join Date
    Mar 2003
    Posts
    4,981
    >> Yes but InvalidateRect() updates the entire window (client window).
    Yeah, and so does InvalidateRgn() - just pass NULL to the second parameter. For both functions, a real second parameter is accumulated into the overall region that needs updating in the next WM_PAINT.

    >> Using Rects or Rgn's, both invalidate-functions will "accumulate" the invalidated regions for the next WM_PAINT.
    >> No, i don't think so...
    Docs are fairly clear on this - don't know what to say that the docs don't:
    Quote Originally Posted by MSDN, InvalidateRect
    The InvalidateRect function adds a rectangle to the specified window's update region.
    ...
    The invalidated areas accumulate in the update region until the region is processed when the next WM_PAINT message occurs or until the region is validated by using the ValidateRect or ValidateRgn function.
    Quote Originally Posted by MSDN, InvalidateRgn
    The InvalidateRgn function invalidates the client area within the specified region by adding it to the current update region of a window.
    ...
    Invalidated areas accumulate in the update region until the next WM_PAINT message is processed or until the region is validated by using the ValidateRect or ValidateRgn function.
    So in summary - both functions are identical, except one takes a rect and one takes a region. Both functions "accumulate" update regions - so there is not need to OR them together yourself. Just make multiple calls to InvalidateRgn() - which will OR the regions together for you.

    >> Now, where's my fault here?
    The debate, as I read this thread, is how the invalidate functions "accumulate" invalidated regions (or rects). You seemed to disagree, or not understand, how these functions accumulate regions to be updated. To me the docs are fairly clear, but I can understand that may not be the case for everyone.

    >> Would be helpful if you identify my misconceptions regarding the two fuctions...
    I apologize for just pointing you to the docs without an explanation. I don't want to be the bearer of "bad feelings" in any thread

    gg

  8. #8
    Registered User
    Join Date
    Apr 2008
    Posts
    610
    Quote Originally Posted by Codeplug View Post
    use WS_CLIPCHILDREN on the parent. Also handle WM_ERASEBKGND in the parent to do nothing. And exclude your controls form the update region if they don't need to repaint themselves.

    gg
    Didn't work because i did it this way
    Code:
    wcx.style = WS_CLIPCHILDREN;
    changed it to...
    Code:
    CreateWindowEx(..., ... , ... , | WS_CLIPCHILDREN, ...);
    Now works, what's the difference?

  9. #9
    C++まいる!Cをこわせ!
    Join Date
    Oct 2007
    Location
    Inside my computer
    Posts
    24,654
    There's a difference between window styles and class styles.
    Constants that begins with WS_ are window styles (Window Style).
    Quote Originally Posted by Adak View Post
    io.h certainly IS included in some modern compilers. It is no longer part of the standard for C, but it is nevertheless, included in the very latest Pelles C versions.
    Quote Originally Posted by Salem View Post
    You mean it's included as a crutch to help ancient programmers limp along without them having to relearn too much.

    Outside of your DOS world, your header file is meaningless.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. A strange problem with regions
    By Overlord in forum Windows Programming
    Replies: 5
    Last Post: 05-10-2008, 01:06 AM
  2. Clicking in regions.
    By harmony_krieg in forum Windows Programming
    Replies: 3
    Last Post: 09-26-2007, 03:05 PM
  3. Update Regions in Window Managers
    By SMurf in forum Tech Board
    Replies: 1
    Last Post: 09-12-2005, 07:51 PM
  4. Dividing window into regions
    By Tesita in forum Windows Programming
    Replies: 3
    Last Post: 11-05-2003, 02:30 PM
  5. Update, Clipping regions
    By bennyandthejets in forum Windows Programming
    Replies: 1
    Last Post: 06-29-2003, 06:38 AM