// (c) R.I.Allen 2002
// You may use this code in anyway that you feel, no guarantees or waranties are implied
// please keep all headers with any source used.
//
// PIDialog.cpp : implementation file
//
#include "stdafx.h"
#include "PlugInApp.h"
#include "PIDialog.h"
#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif
/////////////////////////////////////////////////////////////////////////////
// CPIDialog dialog
IMPLEMENT_DYNCREATE(CPIDialog, CDialog)
CPIDialog::CPIDialog()
{
ASSERT(FALSE); // this class should not be called this way
m_pMaps = NULL;
m_MapCount = 0;
}
CPIDialog::~CPIDialog()
{
// release message map pointers
for (int i = 0; i < m_MapCount; ++i)
{
delete m_pMaps[i];
m_pMaps[i] = NULL;
}
delete []m_pMaps;
m_pMaps = NULL;
m_state.SetDestroyed();
}
void CPIDialog::InitialisePlugIns()
{
CPlugInApp *pApp = static_cast<CPlugInApp*>(AfxGetApp());
// get our pointers to any plug in maps
m_pMaps = pApp->GetMessageMaps(this, m_MapCount);
}
BEGIN_MESSAGE_MAP(CPIDialog, CDialog)
//{{AFX_MSG_MAP(CPIDialog)
//}}AFX_MSG_MAP
END_MESSAGE_MAP()
/////////////////////////////////////////////////////////////////////////////
// CPIDialog message handlers
BOOL CPIDialog::OnCmdMsg(UINT nID, int nCode, void* pExtra, AFX_CMDHANDLERINFO* pHandlerInfo)
{
// check to see whether any of the plug-in DLL's
// want to intercept this message and process it before the application class
CPlugInApp *pApp = static_cast<CPlugInApp*>(AfxGetApp());
CPIState stateCopy(m_state);
ASSERT(pApp);
BOOL ret_pre = FALSE;
BOOL ret_app = FALSE;
BOOL ret_post = FALSE;
m_bSuppressThisMessage = false;
// allow DLL's to process this message before the exe
ret_pre = pApp->ProcessCommandMessageMaps(stateCopy, true, &m_bSuppressThisMessage, m_pMaps, m_MapCount, nID, nCode, pExtra, pHandlerInfo);
if (!m_bSuppressThisMessage)
{
// allow the exe to process the message is it hasn't been suppressed by a DLL
ret_app = CDialog::OnCmdMsg(nID, nCode, pExtra, pHandlerInfo);
}
// allow DLL to process the message after the exe
// note that DLLs get to do this whether the message has been supressed or not
if (!stateCopy.IsDestroyed())
{
ret_post = pApp->ProcessCommandMessageMaps(stateCopy, false, &m_bSuppressThisMessage, m_pMaps, m_MapCount, nID, nCode, pExtra, pHandlerInfo);
}
if (ret_pre || ret_app || ret_post)
return TRUE;
return FALSE;
}
BOOL CPIDialog::OnWndMsg(UINT message, WPARAM wParam, LPARAM lParam, LRESULT* pResult)
{
LRESULT lResult;
// special case for commands
if (message == WM_COMMAND)
{
if (OnCommand(wParam, lParam))
{
lResult = 1;
if (pResult != NULL)
*pResult = lResult;
return TRUE;
}
return FALSE;
}
// special case for notifies
if (message == WM_NOTIFY)
{
NMHDR* pNMHDR = (NMHDR*)lParam;
if (pNMHDR->hwndFrom != NULL && OnNotify(wParam, lParam, &lResult))
{
if (pResult != NULL)
*pResult = lResult;
return TRUE;
}
return FALSE;
}
// check to see whether any of the plug-in DLL's
// want to intercept this message and process it before the application class
CPlugInApp *pApp = static_cast<CPlugInApp*>(AfxGetApp());
ASSERT(pApp);
CPIState stateCopy(m_state);
BOOL ret_pre = FALSE;
BOOL ret_app = FALSE;
BOOL ret_post = FALSE;
m_bSuppressThisMessage = false;
// allow DLL's to process this message before the exe
ret_pre = pApp->ProcessWindowMessageMaps(stateCopy, true, &m_bSuppressThisMessage, m_pMaps, m_MapCount, message, wParam, lParam, pResult);
if (!m_bSuppressThisMessage)
{
// allow the exe to process the message is it hasn't been suppressed by a DLL
ret_app = CDialog::OnWndMsg(message, wParam, lParam, pResult);
}
if (!stateCopy.IsDestroyed())
{
// allow DLL to process the message after the exe
// note that DLLs get to do this whether the message has been supressed or not
ret_pre = pApp->ProcessWindowMessageMaps(stateCopy, false, &m_bSuppressThisMessage, m_pMaps, m_MapCount, message, wParam, lParam, pResult);
}
if (ret_pre || ret_app || ret_post)
return TRUE;
return FALSE;
}