How to get a working context menu on a dialog bar RichEditCtrl ?
I need to get a simple edit menu popup to work on a CRichEditCtrl window in a dialog bar. (VC 2010). I cannot figure out how to 'subclass' (if that is the correct term to use) the dialog bar text window in order to get the popup menu to work. I have tried to subclass the edit window on initialization of the dialog bar using but this invariably results in an appcrash.
Code:
LONG CDialogBar1::OnInitDialog ( UINT wParam, LONG lParam)
{
BOOL bRet = HandleInitDialog(wParam, lParam);
if (!UpdateData(FALSE))
{
TRACE0("Warning: UpdateData failed during dialog init.\n");
}
// TODO: Add extra initialization here
//GetDlgItem(IDC_EDIT_QUERY)->SubclassDlgItem(IDC_EDIT_QUERY, m_pRichEditEx);
//SubclassDlgItem(IDC_EDIT_QUERY, m_pRichEditEx);
return bRet;
}
I do not understand the debug messages generated:
Unhandled exception at 0x77ad15de in XDbar.exe 0xC015000F: The activation context being deactivated is not the most recently activated one.
Re: How to get a working context menu on a dialog bar RichEditCtrl ?
Rich edit control has not a built-in context menu because it is not only designed to keep simple text like in case of the simpe edit control.
Instead, it can ask the client to provide a menu handle (which may depend on current selection contents), via IRichEditOleCallback interface.
For this purpose you have to:
derive from IRichEditOleCallback and implement its methods.
Re: How to get a working context menu on a dialog bar RichEditCtrl ?
Thanks alot Ovi. Awesome code. It's also a nice mini-tutorial on how to set up a COM interface which has always been a mystery to me. But how do I implement the menu (undo, cut, copy, paste, delete, select all, etc), assuming that I have a separate popup menu ?
Last edited by Mike Pliam; April 22nd, 2012 at 12:54 PM.
Re: How to get a working context menu on a dialog bar RichEditCtrl ?
Override OnCommand in dialog bar class and "reflect" to child controls the commands which are coming from a menu.
Code:
BOOL CTestDialogBar::OnCommand(WPARAM wParam, LPARAM lParam)
{
// if command is from a menu, "reflect" it to the child controls
if(0 == HIWORD(wParam))
{
SendMessageToDescendants(WM_COMMAND, wParam, lParam);
}
return CDialogBar::OnCommand(wParam, lParam);
}
Now, we can map (using wizard) and handle menu commands (ID_EDIT_COPY and so on) in the rich edit control class.
Code:
class CTestRichEditCtrl : public CRichEditCtrl
{
// ...
afx_msg void OnEditCopy();
// ...
};
Re: How to get a working context menu on a dialog bar RichEditCtrl ?
I forgot to add:
I have subclassed rich edit control using standard DDX and CRichEditCtrlEx class. I had to write the code to insert member variable; class wizard is dumb handling CDialogBar derived class since it needs resource ID for a dialog template.
There are only 10 types of people in the world: Those who understand binary and those who do not.
* The Best Reasons to Target Windows 8
Learn some of the best reasons why you should seriously consider bringing your Android mobile development expertise to bear on the Windows 8 platform.