Need help with SetCapture & Release Capture API 
Author Message
 Need help with SetCapture & Release Capture API

Hi

I have a user control to display a thumbnail. When the mouse moves over the
thumbnail a blue square highlights the control and when it moves out of the
control it goes back to default.
All this works well except for one thing.

I create an array of 50 usercontrols and use a Picture Control and Scoll
bars to sroll the pics up and down. ie a Viewport.
I have 2 buttons at the bottom. Back & Forward

Now if I scoll down and hover over a usercontrol that is half displayed at
the bottom and then move downwards to click the forward button the
ReleaseCapture event is not being fired until i reach the outside of the
hidden user control.
What I would like to happen is that as soon as I move the mouse over the
form to get to the Buttons , the Release is fired and does not wait till it
goes outside of the usercontrol.

I hope someone can point me in the right direction

Here is the code I use.  Again what I would like to happen is the
ReleaseCapture to fire either when I leave the control which it does OR as
soon as the mouse moves over the Viewport Border

  If ((x < 0) Or (x > UserControl.Width) Or (y < 0) Or (y >
UserControl.Height)) Then
   'Mouse Leave (The mouse rolls out the control)
      RaiseEvent OnMouseLeave
      Call ReleaseCapture
   ElseIf GetCapture <> UserControl.hwnd Then
   'Mouse Enter (The mouse rolls over the control
   'and GetCapture <> UserControl.hWnd which means first time mouse move)
      RaiseEvent OnMouseEnter
      Call SetCapture(UserControl.hwnd)
   Else
   'Mouse Move
      RaiseEvent OnMouseMove(Button, Shift, x, y)

   End If

Thanks in Advance

Garry



Fri, 11 May 2012 06:53:32 GMT  
 Need help with SetCapture & Release Capture API
k_zeon pretended :

Quote:
> Now if I scoll down and hover over a usercontrol that is half displayed at
> the bottom and then move downwards to click the forward button the
> ReleaseCapture event is not being fired until i reach the outside of the
> hidden user control.
> What I would like to happen is that as soon as I move the mouse over the form
> to get to the Buttons , the Release is fired and does not wait till it goes
> outside of the usercontrol.

WindowFromPoint Function ()
http://msdn.microsoft.com/en-us/library/ms633558(VS.85).aspx

?

--
[.NET: It's About Trust!]



Fri, 11 May 2012 08:52:30 GMT  
 Need help with SetCapture & Release Capture API
Thanks.

Just tried that but i cannot get it to do what i need.
It gives me the screen X Y position.

Is it possible to get the viewport (picturebox) X Y as I could say if YPoint
 > Picturebox.height then ResleaseCapture etc

thanks

Garry



Quote:
> k_zeon pretended :
>> Now if I scoll down and hover over a usercontrol that is half displayed
>> at the bottom and then move downwards to click the forward button the
>> ReleaseCapture event is not being fired until i reach the outside of the
>> hidden user control.
>> What I would like to happen is that as soon as I move the mouse over the
>> form to get to the Buttons , the Release is fired and does not wait till
>> it goes outside of the usercontrol.

> WindowFromPoint Function ()
> http://msdn.microsoft.com/en-us/library/ms633558(VS.85).aspx

> ?

> --
> [.NET: It's About Trust!]



Fri, 11 May 2012 15:54:14 GMT  
 Need help with SetCapture & Release Capture API
k_zeon explained on 11/22/2009 :

Quote:
>>> Now if I scoll down and hover over a usercontrol that is half displayed at
>>> the bottom and then move downwards to click the forward button the
>>> ReleaseCapture event is not being fired until i reach the outside of the
>>> hidden user control.
>>> What I would like to happen is that as soon as I move the mouse over the
>>> form to get to the Buttons , the Release is fired and does not wait till
>>> it goes outside of the usercontrol.

>> WindowFromPoint Function ()
>> http://msdn.microsoft.com/en-us/library/ms633558(VS.85).aspx

> Just tried that but i cannot get it to do what i need.

Well, that's what you need to focus on, then.

Quote:
> It gives me the screen X Y position.

No, it gives you a window handle, based on the screen position you pass
it.  If you don't know the screen position, you'll probably want to
figure that out first.  (GetCursorPos)

--
[.NET: It's About Trust!]



Sat, 12 May 2012 03:52:07 GMT  
 Need help with SetCapture & Release Capture API
Re-Post as email did not appear

Hi Karl

I have searched the internet for some code re WindowFromPoint Function()  or
examples .
I have found a few and tried them , but i have still been unable to make the
ReleaseCatpure happen when i move out of the scrollport onto the Picture
Container

Below is some of the code i have placed in my usercontrol. (Contains a
Picturebox,Label & Shape)

When it gets to the white area (Picturebox) at the bottom , i am trying to
release the capture and allow my app to respond, as it stands , I have to
click the form or button once before I can then click the button.

I do this as a hobby as I love mucking around and making small applications.
I would very much appreciate it if you could show me an example of what i am
trying to acheive.

'Declarations
Private Declare Function ReleaseCapture Lib "user32.dll" () As Long
Private Declare Function SetCapture Lib "user32.dll" (ByVal hwnd As Long) As
Long
Private Declare Function GetCapture Lib "user32.dll" () As Long

Event OnMouseLeave()
Event OnMouseEnter()
Event OnMouseMove(Button As Integer, Shift As Integer, x As Single, y As
Single)

'This is the Picture Box within the usercontrol
Private Sub imgMoviePicture_MouseMove(Button As Integer, Shift As Integer, x
As Single, y As Single)
    RaiseEvent MouseMove(Button, Shift, x, y)

    If ((x < 0) Or (x > UserControl.Width) Or (y < 0) Or (y >
UserControl.Height)) Then
   'Mouse Leave (The mouse rolls out the control)
      RaiseEvent OnMouseLeave
      Call ReleaseCapture
   ElseIf GetCapture <> imgMoviePicture.hwnd Then
  'Mouse Enter (The mouse rolls over the control
   'and GetCapture <> UserControl.hWnd which means first time mouse move)
      RaiseEvent OnMouseEnter
      Call SetCapture(UserControl.hwnd)
   Else
   'Mouse Move
     RaiseEvent OnMouseMove(Button, Shift, x, y)

  End If

End Sub



Quote:
> k_zeon explained on 11/22/2009 :
>>>> Now if I scoll down and hover over a usercontrol that is half displayed
>>>> at the bottom and then move downwards to click the forward button the
>>>> ReleaseCapture event is not being fired until i reach the outside of
>>>> the hidden user control.
>>>> What I would like to happen is that as soon as I move the mouse over
>>>> the form to get to the Buttons , the Release is fired and does not wait
>>>> till it goes outside of the usercontrol.

>>> WindowFromPoint Function ()
>>> http://msdn.microsoft.com/en-us/library/ms633558(VS.85).aspx

>> Just tried that but i cannot get it to do what i need.

> Well, that's what you need to focus on, then.

>> It gives me the screen X Y position.

> No, it gives you a window handle, based on the screen position you pass
> it.  If you don't know the screen position, you'll probably want to figure
> that out first.  (GetCursorPos)

> --
> [.NET: It's About Trust!]



Sat, 12 May 2012 15:22:59 GMT  
 Need help with SetCapture & Release Capture API

Quote:
> Hi

> I have a user control to display a thumbnail. When the mouse moves over
> the thumbnail a blue square highlights the control and when it moves out
> of the control it goes back to default.
> All this works well except for one thing.

> I create an array of 50 usercontrols and use a Picture Control and Scoll
> bars to sroll the pics up and down. ie a Viewport.
> I have 2 buttons at the bottom. Back & Forward

> Now if I scoll down and hover over a usercontrol that is half displayed
> at the bottom and then move downwards to click the forward button the
> ReleaseCapture event is not being fired until i reach the outside of the
> hidden user control.
> What I would like to happen is that as soon as I move the mouse over the
> form to get to the Buttons , the Release is fired and does not wait till
> it goes outside of the usercontrol.

> I hope someone can point me in the right direction

Why not just use the TrackMouseEvent() function?
It saves having to faff around with capturing the mouse (the root cause
of your problems) and gives you a nice "mouse left" message.

--

i-Catcher Development Team

iCode Systems



Sat, 12 May 2012 18:05:12 GMT  
 Need help with SetCapture & Release Capture API
It happens that k_zeon formulated :

Quote:
> I have searched the internet for some code re WindowFromPoint Function()  or
> examples .

See http://vb.mvps.org/samples/WndPick/

Quote:
> I have found a few and tried them , but i have still been unable to make the
> ReleaseCatpure happen when i move out of the scrollport onto the Picture
> Container

It's pretty simple, really.  The concept is just:

  If WindowFromPoint() <> MyButton.hWnd Then ReleaseCapture

Quote:
> Below is some of the code i have placed in my usercontrol. (Contains a
> Picturebox,Label & Shape)

Well, that's just getting more complicated than a quick glance can work
out.  You're aware that labels and shapes are windowless, right?

Quote:
> When it gets to the white area (Picturebox) at the bottom , i am trying to
> release the capture

Then you'd change the test above to something like:

  If WindowFromPoint() = MyPicturebox.hWnd Then ReleaseCapture

Quote:
> I do this as a hobby as I love mucking around and making small applications.
> I would very much appreciate it if you could show me an example of what i am
> trying to acheive.

Become familiar with the APIs you're trying to use, before trying to
use them for a specific task.  Take a look at that sample I pointed to
above, and figure out how it's working.  That should let you transfer
that understanding to your own situation.

--
[.NET: It's About Trust!]



Sun, 13 May 2012 01:40:01 GMT  
 Need help with SetCapture & Release Capture API
Hi Dee

thanks. do you have an example of how to use TrackMouseEvent() function

Garry


Quote:

>> Hi

>> I have a user control to display a thumbnail. When the mouse moves over
>> the thumbnail a blue square highlights the control and when it moves out
>> of the control it goes back to default.
>> All this works well except for one thing.

>> I create an array of 50 usercontrols and use a Picture Control and Scoll
>> bars to sroll the pics up and down. ie a Viewport.
>> I have 2 buttons at the bottom. Back & Forward

>> Now if I scoll down and hover over a usercontrol that is half displayed
>> at the bottom and then move downwards to click the forward button the
>> ReleaseCapture event is not being fired until i reach the outside of the
>> hidden user control.
>> What I would like to happen is that as soon as I move the mouse over the
>> form to get to the Buttons , the Release is fired and does not wait till
>> it goes outside of the usercontrol.

>> I hope someone can point me in the right direction

> Why not just use the TrackMouseEvent() function?
> It saves having to faff around with capturing the mouse (the root cause of
> your problems) and gives you a nice "mouse left" message.

> --

> i-Catcher Development Team

> iCode Systems



Sun, 13 May 2012 02:52:38 GMT  
 Need help with SetCapture & Release Capture API
on 11/24/2009, k_zeon supposed :

Quote:
> do you have an example of how to use TrackMouseEvent() function

It occurs to me this link might be of use to you...

http://vb.mvps.org/samples/apixref.asp

--
[.NET: It's About Trust!]



Sun, 13 May 2012 04:15:57 GMT  
 Need help with SetCapture & Release Capture API
Hi

Just to let you all know that i managed to sort out the problem with the
TrackMouseEvent() function and Highlighting my usercontrol.

I dont know why this happens but here is what i i have found.

I created a simple user control. on this control I placed a picturebox and
in resize of usercontrol made the picturebox the same size as usercontrol.
Inside this i placed another picturebox which would hold my picture.
below this i added a label which would be the width of the usercontrol
(cosmetic appearance) , on this i placed another label to hold the movie
name and centre it. Also a Shape control that would be the height & width of
the usercontrol. This is what i would change colour to highlight my control.
I also had click/Dblclick/move events etc

I then used the TrackMouseEvent() function and set it to monitor the
usercontrol but this did not work as the MouseMove event of the usercontrol
did not fire.
(Because the picturebox was covering it.)
So i set the 1st Picturebox to be tracked and it appeared to work (ie my
control would be highlighted) except if I moved my mouse fast over a few of
my usercontrols they would all highlight.

I then went back to basics and got the TrackMouseEvent() function working
correctly ie highlighting my control.
I then added one object at a time until it did not work.

I found that if I had 2 picture boxes (one in the other ) it caused problems

If anyone is interested  in my code then let me know and i would be happy to
email an example

thanks

Garry



Quote:
> on 11/24/2009, k_zeon supposed :
>> do you have an example of how to use TrackMouseEvent() function

> It occurs to me this link might be of use to you...

> http://vb.mvps.org/samples/apixref.asp

> --
> [.NET: It's About Trust!]



Fri, 18 May 2012 03:14:05 GMT  
 
 [ 10 post ] 

 Relevant Pages 

1. New API-Guide & API-Toolshed Released

2. New API-Guide & API-Toolshed Released

3. New API-Guide & API-Toolshed Released

4. Need help- CREATING & RELEASING ARRAYS OF OBJECTS

5. SetCapture and ReleaseCapture API

6. SetCapture & ToolTipText

7. SetCapture API function

8. API call to capture and print screen needed

9. WinHelp releases Capture!

10. Release Capture

11. need help with releaseCapture API and send message API

 

 
Powered by phpBB® Forum Software