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. ON_LBUTTONDOWN

ON_LBUTTONDOWN

Scheduled Pinned Locked Moved C / C++ / MFC
question
12 Posts 4 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.
  • V Offline
    V Offline
    Vancouver
    wrote on last edited by
    #1

    Hi, I have defined handlers for WM_LBUTTONDOWN and WM_LBUTTONUP. The routines do receive control when pressing/releasing the button, EXCEPT if the mouse is over a static control - and I want to gain control exactly in that situation. In fact, the handlers don't receive the control if the mouse is over any control on the main window, only if the mouse is over an area of the main window, where there is no control. I can process the CLICKED event for that control, but that's not what I need. This particular control does not have any message handler. The documentation states If the mouse is not captured, the message is posted to the window beneath the cursor but ON_WM_LBUTTONDOWN and LBUTTONUP don't accept a specification of the control. How can I catch this event related to a specific control?

    _ 1 Reply Last reply
    0
    • V Vancouver

      Hi, I have defined handlers for WM_LBUTTONDOWN and WM_LBUTTONUP. The routines do receive control when pressing/releasing the button, EXCEPT if the mouse is over a static control - and I want to gain control exactly in that situation. In fact, the handlers don't receive the control if the mouse is over any control on the main window, only if the mouse is over an area of the main window, where there is no control. I can process the CLICKED event for that control, but that's not what I need. This particular control does not have any message handler. The documentation states If the mouse is not captured, the message is posted to the window beneath the cursor but ON_WM_LBUTTONDOWN and LBUTTONUP don't accept a specification of the control. How can I catch this event related to a specific control?

      _ Offline
      _ Offline
      _AnsHUMAN_
      wrote on last edited by
      #2

      You can subclass your control. Suppose you have a static control on which you want to handle the notifications for WM_LBUTTONDOWN and WM_LBUTTONUP. Derive a class from CStatic( say you name the derived class as CExStatic). Create a member variable for the static control and change CStatic to CExStatic.( Add the header file CExStatic.) You can implement the notifications and handle the behavior in the derived class.

      Somethings seem HARD to do, until we know how to do them. ;-)_AnShUmAn_

      V 1 Reply Last reply
      0
      • _ _AnsHUMAN_

        You can subclass your control. Suppose you have a static control on which you want to handle the notifications for WM_LBUTTONDOWN and WM_LBUTTONUP. Derive a class from CStatic( say you name the derived class as CExStatic). Create a member variable for the static control and change CStatic to CExStatic.( Add the header file CExStatic.) You can implement the notifications and handle the behavior in the derived class.

        Somethings seem HARD to do, until we know how to do them. ;-)_AnShUmAn_

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

        I was afraid of this answer, I thought I can somehow avoid the trouble. Anyway, thanks.

        P M 2 Replies Last reply
        0
        • V Vancouver

          I was afraid of this answer, I thought I can somehow avoid the trouble. Anyway, thanks.

          P Offline
          P Offline
          PJ Arends
          wrote on last edited by
          #4

          If you use the SS_NOTIFY style on your static controls they will notify their parent window when the user clicks on them.


          It's not rocket surgery!

          Within you lies the power for good, use it!!!

          V 1 Reply Last reply
          0
          • P PJ Arends

            If you use the SS_NOTIFY style on your static controls they will notify their parent window when the user clicks on them.


            It's not rocket surgery!

            Within you lies the power for good, use it!!!

            V Offline
            V Offline
            Vancouver
            wrote on last edited by
            #5

            That's what I too believed, however, that is not so. I had an ON_BN_CLICKED handler for this control, which worked, but as it turned out, SS_NOTIFY does not cause the xBUTTONxxx events pass to the parent.

            1 Reply Last reply
            0
            • V Vancouver

              I was afraid of this answer, I thought I can somehow avoid the trouble. Anyway, thanks.

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

              Vancouver wrote:

              I thought I can somehow avoid the trouble

              It's not much trouble. MFC does the work for you :)

              "Posting a VB.NET question in the C++ forum will end in tears." Chris Maunder

              V 1 Reply Last reply
              0
              • M Mark Salsbery

                Vancouver wrote:

                I thought I can somehow avoid the trouble

                It's not much trouble. MFC does the work for you :)

                "Posting a VB.NET question in the C++ forum will end in tears." Chris Maunder

                V Offline
                V Offline
                Vancouver
                wrote on last edited by
                #7

                It was not MUCH trouble, for sure, but it increases the amount of code, it requires two new source files, it requires duplicating some handlers. I am not lazy to do that, but I like compact code, the smaller the better. Plus, my SetCursor is not working any more, not only in the new handlers, but not even in the main window, and I don't see the connection.

                M 1 Reply Last reply
                0
                • V Vancouver

                  It was not MUCH trouble, for sure, but it increases the amount of code, it requires two new source files, it requires duplicating some handlers. I am not lazy to do that, but I like compact code, the smaller the better. Plus, my SetCursor is not working any more, not only in the new handlers, but not even in the main window, and I don't see the connection.

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

                  Vancouver wrote:

                  Plus, my SetCursor is not working any more, not only in the new handlers, but not even in the main window, and I don't see the connection.

                  Not working how? Do you have a cursor defined for the window class or have you set it to NULL? Also, how have you subclassed the control? Mark

                  "Posting a VB.NET question in the C++ forum will end in tears." Chris Maunder

                  V 1 Reply Last reply
                  0
                  • M Mark Salsbery

                    Vancouver wrote:

                    Plus, my SetCursor is not working any more, not only in the new handlers, but not even in the main window, and I don't see the connection.

                    Not working how? Do you have a cursor defined for the window class or have you set it to NULL? Also, how have you subclassed the control? Mark

                    "Posting a VB.NET question in the C++ forum will end in tears." Chris Maunder

                    V Offline
                    V Offline
                    Vancouver
                    wrote on last edited by
                    #9

                    As I posted, it worked yesterday, before I subclassed the control, and it is not working any more. I can't claim, that the subclassing is to blame, as it is not working in the main window either. The questions indicate, that there is no point to discuss this subject here and now. I have to work backwards and see, at which point the problem appears respectively disappears.

                    M 1 Reply Last reply
                    0
                    • V Vancouver

                      As I posted, it worked yesterday, before I subclassed the control, and it is not working any more. I can't claim, that the subclassing is to blame, as it is not working in the main window either. The questions indicate, that there is no point to discuss this subject here and now. I have to work backwards and see, at which point the problem appears respectively disappears.

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

                      Vancouver wrote:

                      The questions indicate, that there is no point to discuss this subject here and now. I have to work backwards and see, at which point the problem appears respectively disappears.

                      Cool. I would start with just an empty, CStatic-derived class - with just the constructor implemented. Create objects of the derived type to encapsulate the CStatic controls in the window. Everything should work normally at that point. If not, then the problem is elsewhere - maybe an existing problem has been exposed. Once it works like that, add the mouse button handlers to the derived class. Initially, your implementation can just call the base class implementation. Once that is done, you'd probably simply need to notify the parent window of the clicks - via a message, member method, etc. That should be the extent of the subclassing necessary for the controls :) Mark

                      "Posting a VB.NET question in the C++ forum will end in tears." Chris Maunder

                      V 1 Reply Last reply
                      0
                      • M Mark Salsbery

                        Vancouver wrote:

                        The questions indicate, that there is no point to discuss this subject here and now. I have to work backwards and see, at which point the problem appears respectively disappears.

                        Cool. I would start with just an empty, CStatic-derived class - with just the constructor implemented. Create objects of the derived type to encapsulate the CStatic controls in the window. Everything should work normally at that point. If not, then the problem is elsewhere - maybe an existing problem has been exposed. Once it works like that, add the mouse button handlers to the derived class. Initially, your implementation can just call the base class implementation. Once that is done, you'd probably simply need to notify the parent window of the clicks - via a message, member method, etc. That should be the extent of the subclassing necessary for the controls :) Mark

                        "Posting a VB.NET question in the C++ forum will end in tears." Chris Maunder

                        V Offline
                        V Offline
                        Vancouver
                        wrote on last edited by
                        #11

                        Mark, I have to disappoint you. I am in the middle(?) of a program, many thousands of code lines. I don't intend to go back in time and in code. I had come to the idea, that it would be nice to have a feature controlled with the mouse button hold down. (No, I don't need any suggestions, how to realize that. I only need "my cursor" back.)

                        M 1 Reply Last reply
                        0
                        • V Vancouver

                          Mark, I have to disappoint you. I am in the middle(?) of a program, many thousands of code lines. I don't intend to go back in time and in code. I had come to the idea, that it would be nice to have a feature controlled with the mouse button hold down. (No, I don't need any suggestions, how to realize that. I only need "my cursor" back.)

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

                          Ok no problem :) There's lots of us here that can help with the cursor problem if needed! Good luck! Mark

                          "Posting a VB.NET question in the C++ forum will end in tears." Chris Maunder

                          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