5

Is there a clean and easy way to disable "Right to left reading order" and Unicode related messages from a context popup menu for an edit control. Yes, I know that I can subclass and intercept WM_CONTEXTPOPUP, then walk the menu. Attached is the image with menu items in question.

Ienter image description here

Andrew Truckle
  • 17,769
  • 16
  • 66
  • 164
dgrandm
  • 375
  • 3
  • 12
  • The context menu is provided by the stock edit control, and the MFC wrapper is largely irrelevant. There seems to be no "*clean and easy way*" to customize that context menu, see for example the top answer under [How to disable copy/paste commands in the Windows edit control context menu?](https://stackoverflow.com/questions/32991402/how-to-disable-copy-paste-commands-in-the-windows-edit-control-context-menu). – dxiv Sep 06 '20 at 02:29

1 Answers1

5

I know you said you don't want to subclass, but I don't think it's that painful.

Derive from CEdit, in this case I used the class name CEditContextMenu and add WM_CONTEXTMENU to your message map:

EditContextMenu.cpp

// ...
BEGIN_MESSAGE_MAP(CEditContextMenu, CEdit)
    ON_MESSAGE(WM_CONTEXTMENU, &CEditContextMenu::OnContextMenu)
END_MESSAGE_MAP()

// CEditContextMenu message handlers
LRESULT CEditContextMenu::OnContextMenu(WPARAM wParam, LPARAM lParam){
    HWINEVENTHOOK hWinEventHook{
        SetWinEventHook(EVENT_SYSTEM_MENUPOPUPSTART, EVENT_SYSTEM_MENUPOPUPSTART, NULL,
            [](HWINEVENTHOOK hWinEventHook, DWORD Event, HWND hWnd, LONG idObject,
                LONG idChild, DWORD idEventThread, DWORD dwmsEventTime){
                if (idObject == OBJID_CLIENT && idChild == CHILDID_SELF){
                    CMenu* pMenu{
                        CMenu::FromHandle((HMENU)::SendMessage(
                            hWnd, MN_GETHMENU, NULL, NULL))
                    };
                    pMenu->EnableMenuItem(32768, MF_DISABLED);
                }
            },
            GetCurrentProcessId(), GetCurrentThreadId(), WINEVENT_OUTOFCONTEXT)
    };

    LRESULT ret{ Default() };
    UnhookWinEvent(hWinEventHook);
    return ret;
}
// ...

Maybe you could do something fancy and watch for WS_EX_RTLREADING and block it some how.

At the end of the day you want to change how the OS functions at a low level. I don't think there is an elegant way to do it organically.

Andy
  • 12,859
  • 5
  • 41
  • 56
  • 1
    Thank you for the answer and the code. I was not aware it's coming from OS. I was hoping that I could set a flag on hWnd or set something in resource editor. – dgrandm Sep 06 '20 at 04:11
  • @dgrandm -- no problem. Any time you are dealing with system controls, it gets to be a pain. Good luck to you – Andy Sep 06 '20 at 04:15