OnCmdMsg for Menu Commands...

I have an SDI application,

I Dynamically create some Menu Items in my Dialog Class but I want to handle the commands as well in my dialog class, ie OnCmdMsg(.....).

I can see these commands being Handled in the Mainframe class's and not the dialog class's OnCmdMsg(...),

 

LVL 1
nv3prasadAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

SteveGTRCommented:
You can try to extend the default command routing by overriding your view's OnCmdMsg() handler and allowing your dialog to process the request:

BOOL CMyView::OnCmdMsg(UINT nID, int nCode, void* pExtra,
      AFX_CMDHANDLERINFO* pHandlerInfo)
{
   if (m_pMyDlg != NULL
      && m_pMyDlg->OnCmdMsg(nID, nCode, pExtra, pHandlerInfo))
      return TRUE;

   return CView::OnCmdMsg(nID, nCode, pExtra, pHandlerInfo);
}

I hope this helps.

Steve
0
mikeblasCommented:
My book discusses handling this situation at great length.

..B ekiM
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
nv3prasadAuthor Commented:
Hi SteveGTR,

I tried the similar one to send commands to my Derived Dialog Class which in turn is the Base Dialog Class for my app. I also have a lot of Dialogs derived from that base class.

Can you tell me what happens in my case?

Hi Mike,

I do not have your MFC book, so if you can tell be how I should proceed I will highly Appreciate it.

Prasad
0
Upgrade your Question Security!

Your question, your audience. Choose who sees your identity—and your question—with question security.

SteveGTRCommented:
I don't understand what you mean. Did you override OnCmdMsg() in your view (or in CMainFrame) and install handlers to the menu commands in your dialog?

BEGIN_MESSAGE_MAP(CMyDlg, CMyBaseDlg)
        //{{AFX_MSG_MAP(CMyDlg)
        //}}AFX_MSG_MAP
        ON_COMMAND(ID_DYNAMIC_MENU, OnDynamicMenu)
END_MESSAGE_MAP()

void CMyDlg::OnDynamicMenu()
{
        // Do your thing...
}

Steve
0
mikeblasCommented:
> I do not have your MFC book, so if you can tell
 > be [sic] how I should proceed I
 > will highly Appreciate it.

1) Go to amazon.com
2) Buy my book.
3) Look up "OnCmdTarget" in the index.
4) Follow the advice I give.

Specifically, the OCBENCH sample is what you want.

..B ekiM
0
nv3prasadAuthor Commented:
I went through your Book, but I have a slightly different situation, but more or less the same and I have done most of what you did.

Let me more clear,

1. I have a CBaseDialog class derived from CDialog.

2. I derive CMyDialog from CBaseDialog Class.

3. I have a "Window" menu Item which I append with all modeless dialogs created
from CBaseDialog. ( all thsese are in excellent shape )

4. I do store the Window pointers in a list and do my sorting etc which is agin with in the CBaseDialog.

5. It is easier for me to handle things in my CBaseDialog's onCmdMsg() rather than the CFrameWnd  or CView Derived class.

Now my question is How can I route the Command Message from CframeWnd Derived class to my CBaseDialog Class. ( My Fr CFrameWnd derived class does not have an Instance of CBaseDialog.


Mike can you tell me more about this kind of message routing.
0
The_EE_ManCommented:
This question has been undeleted.  The points for this question were originally 100 but have been reduced to 0
0
The_EE_ManCommented:
nv3prasad:  I have undeleted this question and refunded your points.  Having admitted to following mikeblas' suggestions, it would have been appropriate to explain why you were going to have community support delete this question.  In the future please do so.

I have also accepted mikeblas' comment as an answer in this case.
0
The_EE_ManCommented:
I also increased the points for this question back to 100.
0
mikeblasCommented:
> Now my question is How can I route the Command Message from
 > CframeWnd Derived class to my CBaseDialog Class. ( My Fr CFrameWnd
 > derived class does not have an Instance of CBaseDialog.

You have to override OnCmdMsg() in the frame window. With MFC's default handling, the modeless dialogs don't get a crack at the message. So, you have to step in at the frame winodw (which _does_ get the messages directed to it) and reflect 'em to the dialog[s] you have.

..B ekiM
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
System Programming

From novice to tech pro — start learning today.