简体   繁体   中英

How to disable MFC Edit control popup menu additional items?

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.

I在此处输入图片说明

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM