How to get a working context menu on a dialog bar RichEditCtrl ?
CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 12 of 12

Thread: How to get a working context menu on a dialog bar RichEditCtrl ?

Hybrid View

  1. #1
    Join Date
    May 2002
    Posts
    1,718

    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.

    afxcomctl32.h
    AFX_ISOLATIONAWARE_STATICLINK_FUNC(HWND ,CreateWindowExW,(DWORD dwExStyle,LPCWSTR lpClassName,LPCWSTR lpWindowName,DWORD dwStyle,int X,int Y,int nWidth,int nHeight,HWND hWndParent,HMENU hMenu,HINSTANCE hInstance,LPVOID lpParam),(dwExStyle,lpClassName,lpWindowName,dwStyle,X,Y,nWidth,nHeight,hWndParent,hMenu,hInstance,lpParam),NULL)
    I have attached a demo XDBarDemo to illustrate the problem and serve as a basis for discussion.

    Any help greatly appreciated.
    Attached Files Attached Files
    mpliam

  2. #2
    VictorN's Avatar
    VictorN is offline Super Moderator Power Poster
    Join Date
    Jan 2003
    Location
    Wallisellen (ZH), Switzerland
    Posts
    17,301

    Re: How to get a working context menu on a dialog bar RichEditCtrl ?

    Quote Originally Posted by Mike Pliam View Post
    I do not understand the debug messages generated:
    Code:
    Unhandled exception at 0x77ad15de in XDbar.exe 0xC015000F: The activation context being deactivated is not the most recently activated one.
    Mike, did you google for this messae?
    For example: http://social.msdn.microsoft.com/For...-8d4d615438cc/
    Or much more: http://www.google.de/search?rlz=1C1S...+activated+one
    Victor Nijegorodov

  3. #3
    Join Date
    May 2002
    Posts
    1,718

    Re: How to get a working context menu on a dialog bar RichEditCtrl ?

    Thanks, Victor. I think I understand what the error message refers to. But HOW DO I get the context menu to run ?
    mpliam

  4. #4
    ovidiucucu's Avatar
    ovidiucucu is offline Moderator/Reviewer Power Poster
    Join Date
    Feb 2003
    Location
    Iasi - Romania
    Posts
    8,021

    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:
    1. derive from IRichEditOleCallback and implement its methods.
    2. call CRichEditCtrl::SetOLECallback.
    3. in GetContextMenu implementation, provide a menu handle.


    See attached test/demo project.
    Attached Files Attached Files
    Ovidiu Cucu
    "When in Rome, do as Romans do."
    Visit: Microsoft Virtual Academy
    Follow: https://twitter.com/#!/ovidiucucu
    My blog: http://codexpert.ro/blog/author/ovidiu-cucu/

  5. #5
    Join Date
    May 2002
    Posts
    1,718

    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.
    mpliam

  6. #6
    ovidiucucu's Avatar
    ovidiucucu is offline Moderator/Reviewer Power Poster
    Join Date
    Feb 2003
    Location
    Iasi - Romania
    Posts
    8,021

    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();
       // ...
    };
    Code:
       //...
       ON_COMMAND(ID_EDIT_COPY, OnEditCopy)
       //}}AFX_MSG_MAP
    END_MESSAGE_MAP()
    
    //...
    void CTestRichEditCtrl::OnEditCopy() 
    {
       Copy();
    }
    Ovidiu Cucu
    "When in Rome, do as Romans do."
    Visit: Microsoft Virtual Academy
    Follow: https://twitter.com/#!/ovidiucucu
    My blog: http://codexpert.ro/blog/author/ovidiu-cucu/

  7. #7
    Join Date
    May 1999
    Location
    DELAWARE, USA
    Posts
    9,915

    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.

  8. #8
    Join Date
    May 2002
    Posts
    1,718

    Re: How to get a working context menu on a dialog bar RichEditCtrl ?

    Thanks John. I'll give your implmentation a try.
    mpliam

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  


Azure Activities Information Page

Windows Mobile Development Center


Click Here to Expand Forum to Full Width

This is a CodeGuru survey question.


Featured


HTML5 Development Center