Announcement

Collapse
No announcement yet.

Tracking the mouse buttons during Default Drag/Size operations ???

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

  • Tracking the mouse buttons during Default Drag/Size operations ???

    When the API function DefWindowProc begins a drag/size
    operation generated by messages like : WM_NCLBUTTONDOWN
    There is NO WM_NCLBUTTONUP message generated when the mouse button
    goes up (ending the drag/size operation). The MSDN docs say that
    WM_NCLBUTTONUP isn't posted.

    How do you "test" to see that the drag/size operation has
    finished (mouse button up), when you can't use either
    WM_MOVE or WM_SIZE ?

    When the end users system is set to "show window contents while dragging"
    the window will receive "multiple" WM_SIZE or WM_MOVE messages, so
    they can't be relied upon to test for the "end of the drag operation"
    (mouse up).

    Does anybody have any ideas of how to handle this ?

    I have to know when the mouse button has been released !




    ------------------
    Chris Boss
    Computer Workshop
    Developer of "EZGUI"
    http://cwsof.com
    http://twitter.com/EZGUIProGuy

  • #2
    Chris --
    SetCapture doesn't work (in combination with WM_LBUTTONUP) ?

    BTW, I used WM_SIZE event in following context:
    1) In WM_SIZE: SetTimer (for example, 200 ms)
    Further WM_SIZE resets a timer again.
    2) If occurs timer event - sizing is finished.

    [This message has been edited by Semen Matusovski (edited November 29, 2000).]

    Comment


    • #3
      Chris,
      When the mouse button is released you should receive a WM_CAPTURECHANGED
      (Windows95) or WM_CANCELMODE(Windows NT).

      Semen,
      Using WM_LBUTTONUP to test for the end of a drag operation is not a good
      method. For example, your application will not get a WM_LBUTTONUP if the
      user releases the button outside of the window where the drag operation
      was initiated.

      Clean up code etc. should be placed in either WM_CAPTURECHANGED or
      WM_CANCELMODE.

      ------------------
      Dominic Mitchell
      Dominic Mitchell
      Phoenix Visual Designer
      http://www.phnxthunder.com

      Comment


      • #4
        I just came across two new messages :

        %WM_EXITSIZEMOVE

        and

        %WM_ENTERSIZEMOVE

        Has anyone used these ?


        Dominic, I thought about %WM_CAPTURECHANGED and did some testing
        with it. That message gets sent "after" the drag when sizing, but both
        before and after the drag when moving a control (2 times).

        Another consideration is making sure what I do works on all platforms
        95/98/NT 3.x/2000

        ------------------


        [This message has been edited by Chris Boss (edited November 30, 2000).]
        Chris Boss
        Computer Workshop
        Developer of "EZGUI"
        http://cwsof.com
        http://twitter.com/EZGUIProGuy

        Comment


        • #5
          Semen;

          I like the Timer idea, but I "have to poll the statis of the mouse
          button" rather than use WM_SIZE. If the end user has the
          "show window contents while dragging" flag selected, then the
          control will get "multiple" WM_SIZE messages and not just one.

          Do you know how to "poll" to see if the mouse button is up ?


          Dominic;

          The %WM_CAPTURECHANGED message is a good idea, but there
          is a problem with that too. When the mouse button is pressed down,
          if the mouse doesn't move and the button comes up, then only 1 %WM_CAPTURECHANGED
          message is generated. IF the control is dragged, then two %WM_CAPTURECHANGED
          messages are generated. I don't want to "mess up" a proper drag.




          ------------------
          Chris Boss
          Computer Workshop
          Developer of "EZGUI"
          http://cwsof.com
          http://twitter.com/EZGUIProGuy

          Comment


          • #6
            repeated message


            [This message has been edited by Chris Boss (edited November 30, 2000).]
            Chris Boss
            Computer Workshop
            Developer of "EZGUI"
            http://cwsof.com
            http://twitter.com/EZGUIProGuy

            Comment


            • #7
              Chris,
              You should not have any problems using WM_CAPTURECHANGED. The following
              is a basic outline of my implementation for dragging, resizing or creating
              a new control in a visual designer. This is bullet proof.
              Hints:
              1. do not let the control capture the mouse
              2. do not use the WM_MOVE or WM_SIZE messages for dragging or resizing
              a control. Use them for the form.

              Code:
                  
              WM_LBUTTONDOWN
                SetFocus hWnd
                SetCapture hWnd
                ' Get the current position of the mouse
                x = LoIntVPB(lParam)
                y = HiIntVPB(lParam)
                ' Set flag indicating type of operation
                lAction = selecting, dragging, resizing etc.
                .
                .
                Code to initialize marquee etc.
                .
                .
                FUNCTION = %FALSE
                EXIT FUNCTION
                  
              WM_MOUSEMOVE
                lKeyState = (%MK_LBUTTON	AND wParam)
                ' If something is being selected, dragged, drawn or resized
                IF (ISTRUE lAction) AND (ISTRUE lKeyState) THEN
                  ' If we have capture
                  IF hWnd = GetCapture() THEN
                    .
                    .
                    Code to move and/or resize marquee etc.
                    .
                    .
                    FUNCTION = %FALSE
                    EXIT FUNCTION
                    
              WM_LBUTTONUP
                ReleaseCapture
                .
                .
                Code to reset action flag etc.
                .
                .
                FUNCTION = %FALSE
                EXIT FUNCTION
                  
              WM_CAPTURECHANGED
                .
                .
                Code to erase marquee, draw new control, move control to new location,
                resize control, reset action flag etc.
                .
                .
                FUNCTION = %FALSE
                EXIT FUNCTION
              ------------------
              Dominic Mitchell
              Dominic Mitchell
              Phoenix Visual Designer
              http://www.phnxthunder.com

              Comment


              • #8
                Dominic;

                I am "modifying" the WM_NCHITTEST values for controls so the
                control now receives the WM_NCLBUTTONDOWN message which
                initiates dragging or sizing of a control (not a Dialog).

                The control that is getting this message is a custom control
                which displays "drag Handles" over another control.

                The custom control displays drag handles "outside" the borders
                of the other control, but when the WM_NCLBUTTONDOWN message occurs
                , the custom control changes its shape, just before the dragging
                or sizing begins. Once the dragging is done, the custom control
                must change its shape back to its original form. I have no problem
                if the control is moved or dragged. The problem is when the mouse
                button is simply clicked on the control, without dragging or
                sizing. My control gets the WM_NCLBUTTON message, changes it shape,
                passes the message to DefWindowProc, Windows captures the mouse,
                no drag or size occurs, the mouse button goes up canceling the drag
                mode (Windows is in control), but my custom control doesn't get
                a WM_NCLBUTTONUP message, so I can't tell the mouse button is
                up and my control doesn't know its time to change its shape
                back to its original shape.

                The custom control is a "Drag Handle" control which attaches itself
                to another control and impliments dragging and sizing. The other
                controls handle is sent to my custom control (as a buddy) and the
                Drag Handle control moves the buddy control to whereever the
                custom control moves to.

                The custom control displays drag handles "outside" of the buddy control
                but when the dragging starts, the handles display "inside" the
                buddy control. I have everything working, but it can't handle
                when the custom control is just clicked and not moved/sized.



                ------------------
                Chris Boss
                Computer Workshop
                Developer of "EZGUI"
                http://cwsof.com
                http://twitter.com/EZGUIProGuy

                Comment


                • #9
                  Chris,
                  So that's how you implemented the drag operation, a variation of the
                  transparent(WS_EX_TRANSPARENT) window method. Without some code snippets
                  to see what you are doing I am shooting in the dark but here goes.
                  Maybe you can try intercepting WM_SETCURSOR.
                  You said Windows captured the mouse. How did it do that?
                  If the mouse is captured you will not get a WM_NCLBUTTONUP.

                  The technique of overlaying a window above controls to draw handles has
                  problems and limitations. In a simple application like the MS dialog
                  editor then its ok. However, if you intend to allow the user to select
                  and/or drag more than one control at a time or use nested controls you
                  will run into serious problems.

                  A program like VisualBasic does the following for drag handles-
                  1. When a single control is selected - 8 windows
                  2. When more than one control is selected - paint 8 rectangles
                  using the client device context of the control the handles are over.


                  ------------------
                  Dominic Mitchell
                  Dominic Mitchell
                  Phoenix Visual Designer
                  http://www.phnxthunder.com

                  Comment


                  • #10
                    I solved my problem !

                    First, I use the %WM_EXITSIZEMOVE message to determine when
                    the drag (move) or size operation is done.

                    The big problem was when the user lets the mouse button up without
                    dragging or sizing the control.

                    It was basically impossible to track the mouse button event, since
                    Windows is processing the drag/size operation and it eats up the
                    message.

                    The solution ?

                    SetWindowsHookEx API function !

                    Using this function, I can create a "hook" into the windows
                    message processing. I can preprocess all the mouse messages
                    even though windows takes control. Using this technique, I can
                    track the mouse button up message and then I post the mouse
                    button up message to my controls window procedure and then
                    in my window procedure, I remove the hook procedure when the
                    mouse button goes up.


                    The beauty of a mouse hook procedure, is that it tracks the mouse
                    events even when another window has Captured the mouse.


                    The hook is only in effect between when the mouse button goes down
                    and when it comes up.

                    It works perfectly !

                    Thanks for all the suggestions. They kept me searching for a
                    solution, rather than give up.




                    ------------------
                    Chris Boss
                    Computer Workshop
                    Developer of "EZGUI"
                    http://cwsof.com
                    http://twitter.com/EZGUIProGuy

                    Comment

                    Working...
                    X