[英]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.是否有一种干净简单的方法可以从编辑控件的上下文弹出菜单中禁用“从右到左阅读顺序”和与 Unicode 相关的消息。 Yes, I know that I can subclass and intercept
WM_CONTEXTPOPUP
, then walk the menu.是的,我知道我可以子类化并拦截
WM_CONTEXTPOPUP
,然后遍历菜单。 Attached is the image with menu items in question.附件是带有相关菜单项的图像。
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:派生自
CEdit
,在本例中,我使用了类名CEditContextMenu
并将WM_CONTEXTMENU
添加到您的消息映射中:
EditContextMenu.cpp
编辑上下文菜单.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.也许你可以做一些花哨的事情并观察
WS_EX_RTLREADING
并以某种方式阻止它。
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.
我认为没有一种优雅的方式可以有机地做到这一点。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.