DanDan
DanDan

Reputation: 10562

Delegating OnUpdate... messages from CMainFrame in MFC

I am using MFC and have a main frame and this receives the WM_PASTE, WM_COPY messages etc from the toolbar. What I want to do is pass this message on to the CPaneDialog which has the focus, because this is where I want my pasted text to go.

I've figured out how to send the message to the correct view, by using this:

void CMainFrame::OnEditPaste()
{
  GetFocus()->SendMessage(WM_PASTE, 0);
}

What I want to do now is ask the form if it can receive a paste message. I figure I can do this by passing on the command ui message...but how do I do this?

void CMainFrame::OnUpdateEditPaste(CCmdUI *pCmdUI)
{
  if(GetFocus())
  {
    GetFocus()->???
  }
}

If there's a better way to do this then please let me know that as well.

I have tried

ON_UPDATE_COMMAND_UI(ID_EDIT_PASTE, &CDerivedPaneDialog::OnUpdateEditPaste)

in my derived CPaneDialog but this does not work.

Upvotes: 0

Views: 599

Answers (1)

arx
arx

Reputation: 16904

MFC uses command routing to get commands (and UI updates) to the code that can handle them. If you fix the routing, this should handle both the paste command and the UI update for it.

This article describes the default routing.

This article describes how to change the routing.

Basically, you override OnCmdMsg in your frame and call the OnCmdMsg in your pane to see if it wants to handle the message. If it doesn't then call the base class to do the standard handling.

Upvotes: 3

Related Questions