PRB: COleMessageFilter Doesn't Process WM_PAINT

Last reviewed: July 10, 1997
Article ID: Q152074
4.00 4.10 WINDOWS NT kbole kbprb kbcode

The information in this article applies to:

  • The Microsoft Foundation Classes (MFC) included with: Microsoft Visual C++, 32-bit Edition, versions 4.0, 4.1

SYMPTOMS

If an automation client calls a method of an automation server that brings up a modal dialog, the client area below the dialog may not re-paint itself if the dialog is moved over it.

CAUSE

The painting problem occurs because the WM_PAINT messages are in the queue, but are not dispatched.

RESOLUTION

One solution is to retrieve and dispatch all WM_PAINT messages when IMessageFilter::MessagePending is called. The sample code below demonstrates one way for this resolution to be implemented.

MORE INFORMATION

To fix the problem with MFC, create a new class that overrides COleMessageFilter::OnMessagePending() as described below. Then revoke the old message filter and register this new one.

Sample Code

   //
   // definition of new COleMessageFilter-derived class
   //
   class CMyMessageFilter : public COleMessageFilter
   {
   public:
      virtual BOOL OnMessagePending(const MSG* pMsg);
   };


   //
   // add a member variable to the CWinApp-derived class
   //
   public:
      CMyMessageFilter MMF;


   //
   // add to the CWinApp::InitInstance after calling AfxOleInit
   //
      COleMessageFilter* OldFilter = AfxOleGetMessageFilter();
      OldFilter->Revoke();
      MMF.Register();


   //
   // Definition of OnMessageFilter
   //
   CMyMessageFilter::OnMessagePending(const MSG* pMsg)
   {
      MSG msg;

      while (PeekMessage(&msg, NULL, WM_PAINT, WM_PAINT,
                         PM_REMOVE | PM_NOYIELD))
      {
         DispatchMessage(&msg);
      }

      if (pMsg->message == WM_PAINT) return TRUE;

      return FALSE;
   }


   //
   // add to CWinApp::ExitInstance
   //
      MMF.Revoke();
      return CWinApp::ExitInstance();


Additional reference words: 2.00 2.10 2.20 4.00 4.10
KBCategory: kbole kbprb kbcode
KBSubcategory: MfcOLE VCx86
Keywords : MfcOLE VCx86 kbcode kbole kbprb
Technology : kbMfc
Version : 4.00 4.10
Platform : NT WINDOWS


THE INFORMATION PROVIDED IN THE MICROSOFT KNOWLEDGE BASE IS PROVIDED "AS IS" WITHOUT WARRANTY OF ANY KIND. MICROSOFT DISCLAIMS ALL WARRANTIES, EITHER EXPRESS OR IMPLIED, INCLUDING THE WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. IN NO EVENT SHALL MICROSOFT CORPORATION OR ITS SUPPLIERS BE LIABLE FOR ANY DAMAGES WHATSOEVER INCLUDING DIRECT, INDIRECT, INCIDENTAL, CONSEQUENTIAL, LOSS OF BUSINESS PROFITS OR SPECIAL DAMAGES, EVEN IF MICROSOFT CORPORATION OR ITS SUPPLIERS HAVE BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES. SOME STATES DO NOT ALLOW THE EXCLUSION OR LIMITATION OF LIABILITY FOR CONSEQUENTIAL OR INCIDENTAL DAMAGES SO THE FOREGOING LIMITATION MAY NOT APPLY.

Last reviewed: July 10, 1997
© 1998 Microsoft Corporation. All rights reserved. Terms of Use.