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. OnLButtonDown process

OnLButtonDown process

Scheduled Pinned Locked Moved C / C++ / MFC
helpquestion
14 Posts 6 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.
  • N Naveen

    Llasus wrote:

    would there be any other functions I can use to achieve what I am trying to do?

    overide the PreTranslateMessage function in the dialog class and check for the WM_LBUTTONDOWN message. BOOL CMyDlg::PreTranslateMessage(MSG* pMsg) { if( pMsg->message == WM_LBUTTONDOWN ) { if( pMsg->hwnd != m_hWnd )// ignore the message if user has clicked on the dialog { // Do the processing } } return CDialog::PreTranslateMessage( pMsg ); }

    nave [OpenedFileFinder]

    L Offline
    L Offline
    Llasus
    wrote on last edited by
    #5

    Naveen wrote:

    overide the PreTranslateMessage function in the dialog class and check for the WM_LBUTTONDOWN message.

    Thank you! Just what I was looking for :) Thank you very much!

    1 Reply Last reply
    0
    • L Llasus

      CPallini wrote:

      Actually you have only to call the same piece of code, in each event handler. I think it is not a big overhead. Why do you want to go against Windows event handling mechanism?

      The problem is, there are tons of objects in there, and I think by adding one OnClick for each objects will cause the code to be longer than what it should be. Like adding OnClick for each textbox and there are 20 of them and all of those 20 contains just one call of a function. :)

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

      Actually MFC allows to map messages of multiple controls to a single handler, provided their IDs are contiguous, see for instance [^] :)

      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

      L 1 Reply Last reply
      0
      • C CPallini

        Actually MFC allows to map messages of multiple controls to a single handler, provided their IDs are contiguous, see for instance [^] :)

        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

        L Offline
        L Offline
        Llasus
        wrote on last edited by
        #7

        Thanks! I have only seen this one just now though, I'll stick with PreTranslateMessage for now since its the best solution for my problem for now. Thank you for your help and time!

        1 Reply Last reply
        0
        • L Llasus

          Hello and good day. I have this one big dialog with different objects (buttons, listboxes, picturebox, static text, etc.) in it. All of these have a common process that should be called first when the user left clicks the mouse over the object. I have checked the OnLButtonDown method but it seems that it is not called when the user clicks over a component (for a button, it processes the OnClick method and doesn't process the OnLButtonDown). Now, the reason I want to do this is because I don't want to add an OnClick for every component I have then place the same codes over again; but instead just check a coordinates table and see if the user clicked over an object. Is this possible with OnLButtonDown or would there be any other functions I can use to achieve what I am trying to do? Thank you for the time and help.

          F Offline
          F Offline
          Force Code
          wrote on last edited by
          #8

          What about WM_MOUSEACTIVATE? Sincerely, Spy++

          F 2 Replies Last reply
          0
          • F Force Code

            What about WM_MOUSEACTIVATE? Sincerely, Spy++

            F Offline
            F Offline
            Force Code
            wrote on last edited by
            #9

            Within the WM_MOUSEACTIVATE handler, I guess you could call GetDlgCtrlID(GetFocus()) to get the identity of the control.

            1 Reply Last reply
            0
            • F Force Code

              What about WM_MOUSEACTIVATE? Sincerely, Spy++

              F Offline
              F Offline
              Force Code
              wrote on last edited by
              #10

              //In DlgProc: if ((msg == WM_MOUSEACTIVATE) && (HIWORD(lParam) == WM_LBUTTONDOWN)) { POINT pt; GetCursorPos(&pt); int ctrlID = GetDlgCtrlID(WindowFromPoint(pt))); }

              H L 2 Replies Last reply
              0
              • F Force Code

                //In DlgProc: if ((msg == WM_MOUSEACTIVATE) && (HIWORD(lParam) == WM_LBUTTONDOWN)) { POINT pt; GetCursorPos(&pt); int ctrlID = GetDlgCtrlID(WindowFromPoint(pt))); }

                H Offline
                H Offline
                Hamid Taebi
                wrote on last edited by
                #11

                You can write your answers at one message. ;)

                1 Reply Last reply
                0
                • L Llasus

                  CPallini wrote:

                  Actually you have only to call the same piece of code, in each event handler. I think it is not a big overhead. Why do you want to go against Windows event handling mechanism?

                  The problem is, there are tons of objects in there, and I think by adding one OnClick for each objects will cause the code to be longer than what it should be. Like adding OnClick for each textbox and there are 20 of them and all of those 20 contains just one call of a function. :)

                  D Offline
                  D Offline
                  David Crow
                  wrote on last edited by
                  #12

                  Llasus wrote:

                  ...cause the code to be longer than what it should be.

                  You can't seriously think this is a problem, can you? :rolleyes: :omg: See here for more.

                  "Love people and use things, not love things and use people." - Unknown

                  "To have a respect for ourselves guides our morals; to have deference for others governs our manners." - Laurence Sterne

                  L 1 Reply Last reply
                  0
                  • D David Crow

                    Llasus wrote:

                    ...cause the code to be longer than what it should be.

                    You can't seriously think this is a problem, can you? :rolleyes: :omg: See here for more.

                    "Love people and use things, not love things and use people." - Unknown

                    "To have a respect for ourselves guides our morals; to have deference for others governs our manners." - Laurence Sterne

                    L Offline
                    L Offline
                    Llasus
                    wrote on last edited by
                    #13

                    DavidCrow wrote:

                    You can't seriously think this is a problem, can you?

                    When you've got firmware programmers as your leaders, yes its a problem :)

                    1 Reply Last reply
                    0
                    • F Force Code

                      //In DlgProc: if ((msg == WM_MOUSEACTIVATE) && (HIWORD(lParam) == WM_LBUTTONDOWN)) { POINT pt; GetCursorPos(&pt); int ctrlID = GetDlgCtrlID(WindowFromPoint(pt))); }

                      L Offline
                      L Offline
                      Llasus
                      wrote on last edited by
                      #14

                      Thanks for the help and sorry for the late reply (different timezone) :) At what event handler should I place this code? I checked OnMouseActivate but lParam and msg is not there.

                      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