[Win32]Add context menu to edit control
-
How can i add a context menu to an edit control? I try to handle WM_RBUTTONDOWN in the main window, but don't work if the mouse click is on the edit control.
-
How can i add a context menu to an edit control? I try to handle WM_RBUTTONDOWN in the main window, but don't work if the mouse click is on the edit control.
You have to subclass the Edit Control, see, for instance Create your own controls - the art of subclassing[^]. :)
If the Lord God Almighty had consulted me before embarking upon the Creation, I would have recommended something simpler. -- Alfonso the Wise, 13th Century King of Castile.
This is going on my arrogant assumptions. You may have a superb reason why I'm completely wrong. -- Iain Clarke
[My articles] -
How can i add a context menu to an edit control? I try to handle WM_RBUTTONDOWN in the main window, but don't work if the mouse click is on the edit control.
Derive a new class from the CEdit and handle the ON_WM_CONTEXTMENU() message.Check this article for referance, How to modify a CEdit context menu[^]
-
Derive a new class from the CEdit and handle the ON_WM_CONTEXTMENU() message.Check this article for referance, How to modify a CEdit context menu[^]
I'm not using MFC. So i've to call SetWindowSubclass function and set my own EditProc in which handle WM_CONTEXTMENU?
-
I'm not using MFC. So i've to call SetWindowSubclass function and set my own EditProc in which handle WM_CONTEXTMENU?
Member 2965471 wrote:
So i've to call SetWindowSubclass function and set my own EditProc in which handle WM_CONTEXTMENU?
Yes.
Mark Salsbery Microsoft MVP - Visual C++ :java:
-
How can i add a context menu to an edit control? I try to handle WM_RBUTTONDOWN in the main window, but don't work if the mouse click is on the edit control.
As an alternative to the mentioned subclassing, it is also possible to handle WM_RBUTTONDOWN directly in your dialogs message loop:
HWND hwndDlg = CreateDialog(...); MSG msg; while(GetMessage(&msg,0,0,0)){ if(msg.hwnd == GetDlgItem(hwndDlg,ID\_MYEDITCONTROL) && msg.message == WM\_RBUTTONDOWN) ; // WM\_RBUTTONDOWN has been received for ID\_MYEDITCONTROL on hwndDlg; show your context menu here else{ TranslateMessage(&msg); DispatchMessage(&msg); } }