CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 7 of 7
  1. #1
    Join Date
    Mar 2002
    Location
    Chicago, IL
    Posts
    255

    Refreshing region outside client area.

    I have a window, and as part of an internal diagnostic, I frame a region around it. I have a CRgn member, and whenever my window receives the WM_PAINT message, I create a CWindowDC given the Desktop window and call FrameRgn on it. This part works fine. However when my window goes away, I want to invalidate and repaint the region to remove the frame from the windows I painted over. I can't seem to figure out how to do this since the InvalidateRgn and Update API methods all take an HWND. In this case, I don't have an HWND, I just have an HRGN on the screen. What's the best way to invalidate this region without knowing what windows intersect it? Thanks!

  2. #2
    Join Date
    Mar 2002
    Location
    Chicago, IL
    Posts
    255

    Re: Refreshing region outside client area.

    I was able to find a way to do it by enumerating all top-level windows (EnumWindows) and seeing if the region intersected with each window. If so, invalidate and redraw that window (as long as its visible). While this seems to work, it's not ideal. Is there a better way?

  3. #3
    Join Date
    May 2006
    Location
    Dresden, Germany
    Posts
    458

    Re: Refreshing region outside client area.

    What is wrong with this solution?

    What should be better?

  4. #4
    Join Date
    Mar 2002
    Location
    Chicago, IL
    Posts
    255

    Re: Refreshing region outside client area.

    I was hoping you could just pass NULL as the 'hWnd' into InvalidateRgn or something, and the Win32API would invalidate all windows that intersect the given region. It just seems like there should be a single API for doing this rather than having to enumerate all the top-level windows. Seems like a hack to me.

  5. #5
    Join Date
    May 2006
    Location
    Dresden, Germany
    Posts
    458

    Re: Refreshing region outside client area.

    The MSDN says:

    Quote Originally Posted by MSDN
    A handle to the window whose update region has changed. If this parameter is NULL, the system invalidates and redraws all windows, not just the windows for this application, and sends the WM_ERASEBKGND and WM_NCPAINT messages before the function returns. Setting this parameter to NULL is not recommended.
    To try it out I did the following:

    Code:
        HWND hWnd = ::GetDesktopWindow();
        if (hWnd)
        {
            ::InvalidateRect(hWnd, NULL, TRUE);
            ::SendMessage(hWnd, WM_PAINT, 0, 0);
        }
    and it didn't work (no flickering of my great IDE occured)

    But the MSDN indeed is right:

    Code:
            ::InvalidateRect(NULL, NULL, TRUE);
    worked.

    So you shouldn't set the HWND param of InvalidateRect to the handle of the desktop window, but instead set it to NULL.

    I don't knwo exactly how mean I'm since I'm doing something "not recommended"..., but it worked.

    regards
    PA

  6. #6
    Join Date
    Mar 2002
    Location
    Chicago, IL
    Posts
    255

    Re: Refreshing region outside client area.

    I do lots of things that aren't recommended, so what's one more? =) Thanks for your assistance, ProgramArtist.

  7. #7
    Join Date
    Jun 2010
    Location
    Germany
    Posts
    2,675

    Re: Refreshing region outside client area.

    So it looks like the appilication windows aren't all children of the desktop window. Instead, the desktop is just some sort of another application window, invariably lying below all the others in the Z order.
    I was thrown out of college for cheating on the metaphysics exam; I looked into the soul of the boy sitting next to me.

    This is a snakeskin jacket! And for me it's a symbol of my individuality, and my belief... in personal freedom.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured