Вам нужно создать подкласс для элемента управления edit, затем использовать хук, следующий пример кода:
LRESULT CALLBACK EditSubclassProc(HWND hWndEdit, UINT Msg, WPARAM wParam, LPARAM lParam, UINT_PTR uIDSubclass, DWORD_PTR dwRefData)
{
LRESULT ret{};
switch (Msg)
{
case WM_CONTEXTMENU:
{
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)
{
HMENU hMenuContextEdit{ (HMENU)SendMessage(hWnd, MN_GETHMENU, NULL, NULL) };
// Do what you want to do
}
},
GetCurrentProcessId(), GetCurrentThreadId(), WINEVENT_OUTOFCONTEXT) };
ret = DefSubclassProc(hWndEditMessage, Msg, wParam, lParam);
UnhookWinEvent(hWinEventHook);
}
break;
default:
{
ret = DefSubclassProc(hWndEdit, Msg, wParam, lParam);
}
break;
}
return ret;
}