PDA

Click to See Complete Forum and Search --> : Easy doubt using SetCapture/ReleaseCapture


Michel Jr
May 3rd, 2000, 03:38 AM
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.

Sam Finch
May 3rd, 2000, 05:55 AM
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.

DrBrain
May 7th, 2000, 02:37 AM
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.

May 28th, 2000, 04:36 AM
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