Knowledge Base Nr: 00108 messagefilter.cpp - http://www.swe-kaiser.de

Downloads:

OLE: Messagebox 'Server Busy' vermeiden

  
//Die Message erscheint meistens wenn eine Funktion zu lange dauert!
//(z.B.: Das Lesen/Schreiben eines Wertes im OPC-Server.)
//Ansonsten gibt es noch andere OLE Besonderheiten.

#include <afxole.h>

class CMyMessageFilter : public COleMessageFilter
{
virtual BOOL OnMessagePending(const MSG* pMsg);
};

BOOL CMyMessageFilter::OnMessagePending(const MSG* pMsg)
{
//The base class function dispatches WM_PAINT
//by returning FALSE no messages are being processed; the
//user can add code here to appropriately handle messages.
//WARNING: Not processing WM_PAINT messages will cause the user
// interface to appear to hang and not update until the
// current COM method call returns.
return FALSE;
}

BOOL CShellApp::InitInstance()
{
...
CWinThread* pThread = AfxGetThread();
if (pThread != NULL)
{
// Destroy message filter, thereby unregistering it.
delete pThread->m_pMessageFilter;
pThread->m_pMessageFilter = NULL;

// Create the new message filter object.
pThread->m_pMessageFilter = new CMyMessageFilter;
ASSERT(AfxOleGetMessageFilter() != NULL);

pThread->m_pMessageFilter->EnableBusyDialog (FALSE);
pThread->m_pMessageFilter->EnableNotRespondingDialog (FALSE);

// Register the new message filter object.
AfxOleGetMessageFilter()->Register();
}
...
}