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. catch mouse event

catch mouse event

Scheduled Pinned Locked Moved C / C++ / MFC
question
9 Posts 3 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.
  • S Offline
    S Offline
    Sabry1905
    wrote on last edited by
    #1

    Hello All I am trying to catch a right button down event for a control before the form sends it to this control; Is there any way to do that?

    CPalliniC M 2 Replies Last reply
    0
    • S Sabry1905

      Hello All I am trying to catch a right button down event for a control before the form sends it to this control; Is there any way to do that?

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

      IMHO the event travels in the opposite direction, i.e. the message comes to the control that usually notify it to its parent. :)

      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.

      In testa che avete, signor di Ceprano?

      1 Reply Last reply
      0
      • S Sabry1905

        Hello All I am trying to catch a right button down event for a control before the form sends it to this control; Is there any way to do that?

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

        Mouse events are sent by the system, not a form (unless you have a form that sends them). Subclass the control and you'll get the first look at the messages and you can decide what messages to let the control handle. Are you using MFC or straight Win32 APIs? Mark

        Mark Salsbery Microsoft MVP - Visual C++ :java:

        S 1 Reply Last reply
        0
        • M Mark Salsbery

          Mouse events are sent by the system, not a form (unless you have a form that sends them). Subclass the control and you'll get the first look at the messages and you can decide what messages to let the control handle. Are you using MFC or straight Win32 APIs? Mark

          Mark Salsbery Microsoft MVP - Visual C++ :java:

          S Offline
          S Offline
          Sabry1905
          wrote on last edited by
          #4

          Actually I am using MFC but I am able to use direct win32 And I got what you mean by sub classing the control, But the problem is that I am trying to catch mouse event send to a com component not an ordinary control, so that I can't subclass it, it is a black box But I believe that I should be able to catch the event through the default window Proc and before dispatching it, where the application itself dispatch the every event and send it any GUI item But I am new in that area so I found difficulty And I need help.

          M 1 Reply Last reply
          0
          • S Sabry1905

            Actually I am using MFC but I am able to use direct win32 And I got what you mean by sub classing the control, But the problem is that I am trying to catch mouse event send to a com component not an ordinary control, so that I can't subclass it, it is a black box But I believe that I should be able to catch the event through the default window Proc and before dispatching it, where the application itself dispatch the every event and send it any GUI item But I am new in that area so I found difficulty And I need help.

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

            In that case, override CWinApp::PreTranslateMessage()[^] in your application class. You can filter messages there. Mark

            Mark Salsbery Microsoft MVP - Visual C++ :java:

            S 1 Reply Last reply
            0
            • M Mark Salsbery

              In that case, override CWinApp::PreTranslateMessage()[^] in your application class. You can filter messages there. Mark

              Mark Salsbery Microsoft MVP - Visual C++ :java:

              S Offline
              S Offline
              Sabry1905
              wrote on last edited by
              #6

              many thx, it works and here is the code const UINT RBUTTONDOWN = 0x204; const UINT RBUTTONUP= 0x205; BOOL Cmfc01App::PreTranslateMessage(MSG* pMsg) { switch (pMsg->message) { case RBUTTONDOWN:return true; case RBUTTONUP:return true; default:CWinApp::PreTranslateMessage(pMsg); } }

              M 1 Reply Last reply
              0
              • S Sabry1905

                many thx, it works and here is the code const UINT RBUTTONDOWN = 0x204; const UINT RBUTTONUP= 0x205; BOOL Cmfc01App::PreTranslateMessage(MSG* pMsg) { switch (pMsg->message) { case RBUTTONDOWN:return true; case RBUTTONUP:return true; default:CWinApp::PreTranslateMessage(pMsg); } }

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

                Remember, that disables ALL RBUTTON messages for ALL windows :) You can also check the message and filter by HWND if you need to. Cheers, Mark

                Mark Salsbery Microsoft MVP - Visual C++ :java:

                S 1 Reply Last reply
                0
                • M Mark Salsbery

                  Remember, that disables ALL RBUTTON messages for ALL windows :) You can also check the message and filter by HWND if you need to. Cheers, Mark

                  Mark Salsbery Microsoft MVP - Visual C++ :java:

                  S Offline
                  S Offline
                  Sabry1905
                  wrote on last edited by
                  #8

                  hey i tried to use the handle to not disable all the RButton messages and i used this code but it fails BOOL Cmfc01App::PreTranslateMessage(MSG* pMsg) { CButton* pb = (CButton*) GetDlgItem( m_pMainWnd->m_hWnd,IDC_BUTTON5); switch (pMsg->message) { case RBUTTONDOWN:if(pMsg->hwnd==pb->m_hWnd)return true; default:CWinApp::PreTranslateMessage(pMsg); } } give me an exception " Access violation reading location 0x00100d46." plz help

                  S 1 Reply Last reply
                  0
                  • S Sabry1905

                    hey i tried to use the handle to not disable all the RButton messages and i used this code but it fails BOOL Cmfc01App::PreTranslateMessage(MSG* pMsg) { CButton* pb = (CButton*) GetDlgItem( m_pMainWnd->m_hWnd,IDC_BUTTON5); switch (pMsg->message) { case RBUTTONDOWN:if(pMsg->hwnd==pb->m_hWnd)return true; default:CWinApp::PreTranslateMessage(pMsg); } } give me an exception " Access violation reading location 0x00100d46." plz help

                    S Offline
                    S Offline
                    Sabry1905
                    wrote on last edited by
                    #9

                    is there any one can help ?

                    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