Link to home
Start Free TrialLog in
Avatar of nv3prasad
nv3prasad

asked on

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(...),

 

Avatar of SteveGTR
SteveGTR
Flag of United States of America image

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
ASKER CERTIFIED SOLUTION
Avatar of mikeblas
mikeblas

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of nv3prasad
nv3prasad

ASKER

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
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
> 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
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.
This question has been undeleted.  The points for this question were originally 100 but have been reduced to 0
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.
I also increased the points for this question back to 100.
> 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