Results 1 to 4 of 4

Thread: Easy doubt using SetCapture/ReleaseCapture

  1. #1

    Thread Starter
    Addicted Member Michel Jr's Avatar
    Join Date
    Jan 2000
    Location
    Brazil
    Posts
    175

    Question

    Hello,


    I'm developing an OCX like an IE Button.
    When the mouse is over the button, I draw the borders.
    When the mouse leaves the button, I erase the borders.
    I'm using SetCapture (hwnd) and ReleaseCapture, but
    when I click on the Label1 nothing happens. I think there
    is a conflict between SetCapture/ReleaseCapture and the
    Click() event.

    My OCX just has a label (Called Label1) inside it.


    Private Sub UserControl_MouseMove(Button As Integer, Shift
    As Integer, X As Single, Y As Single)

    RaiseEvent MouseMove(Button, Shift, X, Y)
    wMouseEnter = (0 <= X) And (X <= UserControl.Width) And
    (0 <= Y) And (Y <= UserControl.Height)
    If wMouseEnter Then
    SetCapture (hWnd)
    Call DrawBorders 'Routine do draw the borders of
    ' the control
    Else
    ReleaseCapture
    Call EraseBorders 'Routine do draw the borders
    'of the control
    End If
    End Sub


    Private Sub UserControl_Click()
    RaiseEvent Click
    End Sub


    Private Sub Label1_Click()
    RaiseEvent Click
    End Sub


    Anybody knows how can I solve this?

    Thanks for any help.

    Michel Jr.

  2. #2
    Frenzied Member
    Join Date
    Mar 2000
    Posts
    1,089
    hmm, not entirely sure, I know that the capture resets itself on any mouseevent apart from the mousemove event, The usual way to do this is to set a mouse hook, there should be an article somewhere on this site.

  3. #3
    Junior Member
    Join Date
    Jan 1999
    Posts
    30
    I guess that you use the Label to show the text in the button. I suggest that you draw the text instead. You see that when you use the SetCapture on the usercontrol it will make any events to the label to be ignored.

  4. #4
    Guest
    i know that i am replying very late, probably you have already solved the problem yourself. If not, here are good news:

    if you use SetCapture and want to react on MouseClick-events inside your control, you have to monitor the MouseUp event and check weither that event occured inside or outside your control. if the MouseUp is inside your control, all you have to do is to send a mouse-event to windows to the same coordinates as were in your MouseUp.

    '*********************************************************

    Public Declare Function SetCapture Lib "user32.dll" (ByVal hwnd As Long) As Long

    Public Declare Function ReleaseCapture Lib "user32.dll" () As Long

    Public Declare Sub mouse_event Lib "user32.dll" (ByVal dwFlags As Long, ByVal dx As Long, ByVal dy As Long, ByVal cButtons As Long, ByVal dwExtraInfo As Long)

    Public Enum asMouseEvents
    asLeftButtonDown = &H2
    asLeftButtonUp = &H4
    End Enum


    Private mlngFormBackColor As Long

    Private Sub Form_Load()
    On Error Resume Next

    Dim i As Long

    i = SetCapture(Me.hwnd)

    End Sub

    Private Sub Form_MouseUp(Button As Integer, Shift As Integer, X As Single, Y As Single)
    On Error Resume Next

    Dim typRect As asRectApi, i As Long

    With Me
    If X < 0 Or X > .Width Or Y < 0 Or X > .Height Then
    Me.Hide
    Unload Me
    Else
    i = ReleaseCapture()
    mouse_event asLeftButtonDown, 0, 0, 0, 0
    mouse_event asLeftButtonUp, 0, 0, 0, 0
    End If
    End With

    End Sub

    '**********************************************************

    hope i could help you

    Sascha

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width