Help and Support

PRB: COleMessageFilter Doesn't Process WM_PAINT

Article ID:152074
Last Review:November 21, 2006
Revision:2.1
This article was previously published under Q152074
On This Page

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.

Back to the top

CAUSE

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

Back to the top

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.

Back to the top

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.

Back to the top

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.
   // 
   BOOL 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();
				

Back to the top


APPLIES TO
Microsoft Foundation Class Library 4.2, when used with:
  Microsoft Visual C++ 4.0 Standard Edition
  Microsoft Visual C++ 4.1 Subscription

Back to the top

Keywords: 
kbcode kbprb KB152074

Back to the top

Article Translations

 

Other Support Options

  • Contact Microsoft
    Phone Numbers, Support Options and Pricing, Online Help, and more.
  • Customer Service
    For non-technical assistance with product purchases, subscriptions, online services, events, training courses, corporate sales, piracy issues, and more.
  • Newsgroups
    Pose a question to other users. Discussion groups and Forums about specific Microsoft products, technologies, and services.