tags:

views:

36

answers:

2

I have a dialog with a rich-text control. The dialog wants to intercept right-click events on the control; in some cases the dialog should do its own functionality and block the message reaching the control, in other cases it should let the control receive the message.

So I have:

ON_NOTIFY(EN_MSGFILTER, IDC_RICHTEXT, OnRichTextMsgfilter)

void CMyDialog::OnRichTextMsgfilter(NMHDR *pNMHDR, LRESULT *pResult)
{
    MSGFILTER *pMsgFilter = reinterpret_cast<MSGFILTER *>(pNMHDR);
    *pResult = 0;
    if (pMsgFilter->msg == WM_RBUTTONUP)
    {
        if(...)
         *pResult=1;
    }
}

I step through the code and pResult is set when it should be, but the control still gets the message. Looking at MSDN it says:

If the control should process the event, the message returns a zero value. If the control should ignore the event, the message returns a nonzero value.

But the defined message handler signature has no return... I am assuming that's what *pResult is for. Is that not true? If so how do I achieve this?

+1  A: 

So i've tried to reproduce this behavior in a simple dialog based app and i really can't -- however, i'm not sure what it is that intercepting the right button message is trying to solve.

That said the following code completely blocks the Left button mouse clicks in my testing (If this returns TRUE the control does not respond to left clicks - however focus will get set to the control on the initial click down and that is more a window manager issue than the control itself)

void CTestDlg::OnMsgfilterRichedit1(NMHDR* pNMHDR, LRESULT* pResult) 
{
    MSGFILTER *pMsgFilter = reinterpret_cast<MSGFILTER *>(pNMHDR);

    if (pMsgFilter->msg == WM_LBUTTONUP || pMsgFilter->msg == WM_LBUTTONDOWN)
    {
        *pResult = TRUE;
        return;
    }

    *pResult = FALSE;
}

If i change *pResult = TRUE to *pResult = FALSE then the left clicks start working again.

It could be that you want to catch and filter out the WM_RBUTTONDOWN rather than WM_RBUTTONUP to do what you intend, but since i'm unsure what functionality you are trying to filter out i can't say for sure.

Ruddy
The reason for all this is the control in question is actually a custom rich-text control which displays a context menu. In some cases, the dialog wants to block that and display a different menu. What happens now is, the overridden menu is shown by the dialog, then as soon as it is cleared, the control displays its own dialog TOO.
John
Is the custom control your's - eg, you have the source code? - if so is it putting up the menu before or after you get the MsgFilter call?
Ruddy
Ruddy
A: 

The WM_RBUTTONDOWN is stil getting through...

Goz
but the control's own handler isn't firing until after this button-up event is caught and the custom code is run.
John