15 мая 2023 года "Исходники.РУ" отмечают своё 23-летие!
Поздравляем всех причастных и неравнодушных с этим событием!
И огромное спасибо всем, кто был и остаётся с нами все эти годы!

Главная Форум Журнал Wiki DRKB Discuz!ML Помощь проекту


[Q] CCmdTarget derived object and Message Maps

SUBRAMANIAN -- SUBRAMANIAN.BALAKRISHNEN@tencor.com
Friday, November 01, 1996


Environment: NT 3.51 Visual C++ 4.2b

Hi,

Can a CCmdTarget derived object use MFC mapping mechanism ??( MFC 4.2 )
I am planning to use the MFC message passing mechanism for communication
among my own "non windows" objects.
I am able to do it but not sure if I am doing the right thing.



Back ground :
This is what I have tried so far .
	I created a new CCmdTarget derived class using Class Wizard ( say
"CCmdTargetDerived" ) . Using class wizard I mapped the menu (say
"ID_TEST_MENU")  message to a method of the "CCmdTargetDerived".  I
created
the instance of the
"CCmdTargetDerived" in the constructor of the CMainFrame class.
	I have overwritten the "OnCmdMsg()" of my MainFrame. In the
"CMainFrame::OnCmdMsg()" I check for the "ID_TEST_MENU" and if found I
route it
to the "CCmdTargetDerived::OnCmdMsg()".



Seed  :
	I got this idea from the MFC implementation for redirecting the menu
messages to the Document. Consider a situation where a menu message
could be mapped to CDocument's method.
	I looked into the CView's OnCmdMsg() method and found that CView is
calling the OnCmdMsg() of CDocument . Can I do something like this
except that
I make my CCmdTarget derived object as a member of Main Window and
overide
MainWindow's OnCmdMsg to call my





Thanks

Subu Balakrishnan

( subub@tencor.com )




Mike Blaszczak -- mikeblas@nwlink.com
Sunday, November 03, 1996

At 12:21 11/1/96 -0800, you wrote:

>Environment: NT 3.51 Visual C++ 4.2b

>Back ground :
>This is what I have tried so far .
>	I created a new CCmdTarget derived class using Class Wizard ( say
>"CCmdTargetDerived" ) . Using class wizard I mapped the menu (say
>"ID_TEST_MENU")  message to a method of the "CCmdTargetDerived".  I
>created the instance of the
>"CCmdTargetDerived" in the constructor of the CMainFrame class.
>	I have overwritten the "OnCmdMsg()" of my MainFrame. In the
>"CMainFrame::OnCmdMsg()" I check for the "ID_TEST_MENU" and if found I
>route it to the "CCmdTargetDerived::OnCmdMsg()".

This will work.  All you're doing is extending the message dispatch mechanism
yourself, and that's just fine.  The thing to remember is that you can't
expect to receive messages themselves directly.  You're not really receiving
messages--you're just getting OnCmdMsg() calls when some other window decides
not to handle a message.


.B ekiM
http://www.nwlink.com/~mikeblas/
I'm afraid I've become some sort of speed freak.
These words are my own. I do not speak on behalf of Microsoft.





| Вернуться в корень Архива |