Write - Copy.png
writesmall - Copy.bmp
writesmall - Copy.png
// $Workfile: ControlledCmdTargetT.h $
// $Header: /SbjDev/SbjCore/ControlledCmdTargetT.h 3 10/14/08 1:12p Steve $
// Copyright � 2008 SbjCat
// All rights reserved.
// *** Authors ***
// Steve Johnson
// $Revision: 3 $
template class wraps a CCmdTarget or derivative to add a
link to a CmdTargetController class for processing CmdMsg
ControlledCmdTargetT overrides OnCmdMsg method of its template
base class so messages can be forwarded to an assigned
CmdTargetController before the default MFC message processing
can occur. The ControlledCmdTargetT will set the CmdTargetController
in its constructor with a call to ControlledCmdTargetT::SetController.
\param _baseClass Any CCmdTarget or derived class.
NOTE: A ControlledWndT derivation of ControlledCmdTargetT is provided
for CWnd classes that provides support for all other Windows messages.
class ControlledCmdTargetT : public _baseClass
pTheController = NULL;
/// sets the CmdTargetController for this target
void SetController(CmdTargetController *pController)
ASSERT((pController == NULL) || (pTheController == NULL));
pTheController = pController;
if (pTheController != NULL)
CmdTargetController* GetController() const
/** routes WM_COMMAND messages to the CmdTargetController.
A call to CmdTargetController::HandleCmdMsg is made.
If the return is false the _baseclass OnCmdMsg is called.
\return true if the message was handled, otherwise false.
virtual BOOL OnCmdMsg(UINT nID,
BOOL bRslt = FALSE;
// if we have a controller make sure it gets the message first
if (pTheController != NULL)
// mfc message map is checking to disable messages with no handler
if (pHandlerInfo != NULL)
// check to see if our controller has a handler
if (pTheController->GetHandler(nID) != NULL)
pHandlerInfo->pTarget = this;
pHandlerInfo->pmf = NULL; // we are't a message map function
bRslt = true; // still we let mfc know we have one
else if ((nCode != CN_EVENT) && (nCode != CN_OLECOMMAND)) // let _baseClass handle ole
// debug trap, just change to the id you want
if (ID_SBJCORE_CTX_DELETE == nID)
nID = ID_SBJCORE_CTX_DELETE;
// check all non-cmdUI first
if (nCode != CN_UPDATE_COMMAND_UI)
// check for a Notify message
UINT nTempCode = LOWORD(nCode);
if (nTempCode > 0)
AFX_NOTIFY* pNotify = static_cast<AFX_NOTIFY*>(pExtra);
if (pNotify != NULL)
// Notify message
bRslt = pTheController->HandleNotifyMsg(pNotify->pNMHDR, pNotify->pResult);
// standard message
bRslt = pTheController->HandleCmdMsg(nID);
// cmdUI message
bRslt = pTheController->HandleCmdUIMsg(nID, static_cast<CCmdUI*>(pExtra));
// if still not handled allow controller to rout the message
bRslt = pTheController->RoutCmdMsg(nID, nCode, pExtra, pHandlerInfo);
// still not handled
bRslt = _baseClass::OnCmdMsg(nID, nCode, pExtra, pHandlerInfo);
/// a pointer to the attached CmdTargetController class
//*** Modification History ***
// $Log: /SbjDev/SbjCore/ControlledCmdTargetT.h $
// 3 10/14/08 1:12p Steve
// Implemented Deletes
By viewing downloads associated with this article you agree to the Terms of Service and the article's licence.
If a file you wish to view isn't highlighted, and is a text file (not binary), please
let us know and we'll add colourisation support for it.
Real name is Steve Johnson. Programming since 1979. Started on a Heathkit Micro with a DEC LSI-11 and UCSD Pascal. Moved to PCs & DOS as soon as Turbo Pascal became available. Did some Assembly, ISR, TSR etc. All this while working for a Manufacturing Co. for 8 years. Had my own solo Co. doing barcode labeling software for 4 years (terrible business man, all I wanted to do was code). Since then working for various software companies. Moved to Windows around the time of 3.1 with Borland C then C++. Then on to VC++ and MFC, and just about anything I could get my hands on or had to learn for my job, and been at it ever since. Of course recently I've been playing with .NET, ASP, C#, WPF etc.