Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C / C++ / MFC
  4. [Win32]Add context menu to edit control

[Win32]Add context menu to edit control

Scheduled Pinned Locked Moved C / C++ / MFC
question
6 Posts 5 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • M Offline
    M Offline
    Member 2965471
    wrote on last edited by
    #1

    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.

    C V L 3 Replies Last reply
    0
    • M Member 2965471

      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.

      C Offline
      C Offline
      CPallini
      wrote on last edited by
      #2

      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]

      1 Reply Last reply
      0
      • M Member 2965471

        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.

        V Offline
        V Offline
        venkatmakam
        wrote on last edited by
        #3

        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[^]

        http://www.mono-project.com/Main\_Page

        M 1 Reply Last reply
        0
        • V venkatmakam

          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[^]

          http://www.mono-project.com/Main\_Page

          M Offline
          M Offline
          Member 2965471
          wrote on last edited by
          #4

          I'm not using MFC. So i've to call SetWindowSubclass function and set my own EditProc in which handle WM_CONTEXTMENU?

          M 1 Reply Last reply
          0
          • M Member 2965471

            I'm not using MFC. So i've to call SetWindowSubclass function and set my own EditProc in which handle WM_CONTEXTMENU?

            M Offline
            M Offline
            Mark Salsbery
            wrote on last edited by
            #5

            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:

            1 Reply Last reply
            0
            • M Member 2965471

              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.

              L Offline
              L Offline
              Lost User
              wrote on last edited by
              #6

              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);
              	}
              }
              
              1 Reply Last reply
              0
              Reply
              • Reply as topic
              Log in to reply
              • Oldest to Newest
              • Newest to Oldest
              • Most Votes


              • Login

              • Don't have an account? Register

              • Login or register to search.
              • First post
                Last post
              0
              • Categories
              • Recent
              • Tags
              • Popular
              • World
              • Users
              • Groups