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?

[Webinar] Streamline your web hosting managementRegister Today

x
 
mikeblasConnect With a Mentor Commented:
My book discusses handling this situation at great length.

..B ekiM
0
 
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
 
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
Hire Technology Freelancers with Gigs

Work with freelancers specializing in everything from database administration to programming, who have proven themselves as experts in their field. Hire the best, collaborate easily, pay securely, and get projects done right.

 
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
All Courses

From novice to tech pro — start learning today.