Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to disable MFC Edit control popup menu additional items?

Tags:

c++

mfc

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

like image 663
dgrandm Avatar asked Sep 06 '20 01:09

dgrandm


1 Answers

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.

like image 177
Andy Avatar answered Nov 14 '22 23:11

Andy