Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 502623
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 13, 20262026-05-13T06:18:37+00:00 2026-05-13T06:18:37+00:00

My MFC application has a CView and a couple of floating non-modal dialogs. I

  • 0

My MFC application has a CView and a couple of floating non-modal dialogs. I am currently trying to figure why an invalidation/repaint of my view also causes the dialogs to be redrawn. This even happens if the dialogs are not overlapping with the view.

Does anybody know how to debug/track who request a specific dialog redraw? Intercepting the WM_PAINT message on the dialog seems to be too late.

Thanks in advance for any help!

Best wishes,

Fabian

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-13T06:18:37+00:00Added an answer on May 13, 2026 at 6:18 am

    I presume that your non-modal dialogs are WS_POPUP windows, right? (i.e. they are floating windows that can appear anywhere on the screen, not just inside your app window.).

    If they are floating windows then technically they aren’t child windows of your frame window, but the documentation tends to use the term parent in places where it should really use owner so this is easy to get confused about. Child windows can’t appear outside the client area of their parent, owned windows can. A child window will be invalidated whenever its parent window is invalidated. But an owned window will not.

    Only windows with the WS_CHILD style flag can be child windows, otherwise they are owned windows.

    If these are owned windows, they won’t inherit invalidation from your main app window, so you need to look for places in your code where there is a call ::InvalidateRect() with a NULL handle as the first parameter. Usually this will be because of an uninitialized variable.

    When you call ::InvalidateRect(NULL, ...) this tells Windows to invalidate ALL windows. (it actually tells Windows to invalidate the desktop window, which is the parent of all windows). With MFC, the base class for all windows has a method for InvalidateRect that turns around and calls the windows api but with the window handle of the current object. as a first order approximation, I think you can assume that THAT window handle will be initialized correctly. You should start by looking for calls in your own code.

    Once you get the OnPaint, its too late to know where the invalidation request came from. So in order to find this bug, you are going to have to either inspect your code or intercept InvalidateRect() and look for NULL in the first param.

    This is a HARD problem in the general case, because there are several ways to invalidate all or part of a window, and lots of code in header files to ‘help’ you by creating variants of this functions that do some things automatically.

    You might try to set a breakpoint at the top of InvalidateRect (it’s in user32.dll) and make that conditional on the first parameter being null. But depending on how your debugger is setup, you may not be allowed to do this.

    You could also try and force all of your code to compile so that calls to InvalidateRect are redirected through a function that you control.

    // in some header file that gets included early by all of your code
    #define InvalidateRect my_InvalidateRect
    
    // in one of your .cpp files.
    BOOL WINAPI my_InvalidateRect(HWND hwnd, CONST RECT *prc, BOOL bErase)
    {
      #undef InvalidateRect
      assert(hwnd != NULL);
      InvalidateRect(hwnd, prc, bErase);
      #define InvalidateRect my_InvalidateRect
    };
    

    If that doesn’t find it, then do the same thing to InvalidateRgn and RedrawWindow

    These kinds of bugs are nasty to find. I don’t envy you. In my own code I have a permanent ban on direct calls to InvalidateRect, they must ALWAYS pass through a wrapper function so I can always check for NULL window handles in debug builds. But then again, I don’t use MFC so enforcing this sort of policy is easier.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am currently working on a very large legacy MFC MDI application. It has
Im using VS2008 and My MFC application has started to crash when setting breakpoints
I have C++ application which has UI developed using MFC, does some networking using
I'm trying to get a legacy MFC application and a new WPF usercontrol to
I am trying to build an install CD with a custom MFC application set
I have a MFC application, which has a worker thread, what I want to
I have an MFC application. It has a CMap which contains certain data objects,
I'm trying to launch a modal dialog from a DLL loaded by an MFC
I am writing an MFC C++ application that has a Save As button for
I have an MFC application that has a webcontrol. When clickable links are clicked,

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.