Link to home
Start Free TrialLog in
Avatar of tkirby052098
tkirby052098

asked on

RichEdit32 and WM_CONTEXTMENU

I am using a richedit control (richedit32.dll) and I want to get the WM_CONTEXTMENU message to the parent window.  Problem is, RE32 eats all the mouse messages.  So, I used the events notify to capture the wm_rbuttonup message, and used SendMessage to send wm_contextmenu (with cursor x,y position) to the parent window.  Here's the problem--> the wm_contextmenu message dissappears!!  It seems so simple, what am I missing??  I do this:

case EN_MSGFILTER:
      {
      UINT uID = (UINT) wParam;
      MSGFILTER *pmf = (MSGFILTER*) lParam;
 
      if (pmf->msg == WM_RBUTTONUP)
            {
            if ((void*)GetWindowLong(hWnd,GWL_WNDPROC) != (void*)TextWndProc)
                  MessageBeep(0); // never gets here!!
            //TextWndProc(hWnd,WM_CONTEXTMENU,0,pmf->lParam); // works!!
            SendMessage(hWnd,WM_CONTEXTMENU,0,pmf->lParam);  // does not!!
            }
      *pResult = 0;
      }            
      
I put a breakpoint on the wm_contextmenu case in the parent window proc, trace thru SendMessage, (which returns) and the breakpoint is never hit.  If I call the window procedure directly (commented out above) it works fine.  Where did my message go????
Avatar of chensu
chensu
Flag of Canada image

Try using PostMessage instead of SendMessage.
Avatar of tkirby052098
tkirby052098

ASKER

I tried PostMessage with the same results.
ASKER CERTIFIED SOLUTION
Avatar of tonp
tonp

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
It's possible that richedit32 sends msgfilter notifications from another thread, so then the SendMessage thread issue might pop up.  However, even though the call returns immediately, the other (main) thread should process the message (eventually), right?  But, it does not happen: the message never gets to the intended window procedure.
The work-around for this problem was to call the wm_contextmenu handler function directly from the msgfilter notification.  If there was a thread problem, it would have definitely caused a failure (running TrackPopupMenu from a sub-thread).  Stumped?
Never did find out why this does not work....