Results 1 to 17 of 17

Thread: Creating transparent user control with mouse events

  1. #1

    Thread Starter
    New Member
    Join Date
    Nov 2008
    Posts
    10

    Creating transparent user control with mouse events

    Hi,

    I've been struggling with this one for a while. I would like to create a usercontrol (activex/ocx) that is transparent but still registers the mousemove event in the transparent regions of the control.

    If you create a control and set backstyle to transparent then the mouse events do not fire in the transparent areas of the control.

    I have tried using windows api calls to set the control to be transparent (using SetLayeredWindowAttributes) but that doesn't seem to work on a user control...

    I need this control so that I can add a transparent control to the application but still track the mousemove and click events.

    Any help would be appreciated

    Lee

  2. #2
    PowerPoster joaquim's Avatar
    Join Date
    Apr 2007
    Posts
    3,966

    Re: Creating transparent user control with mouse events

    for test it...
    change the HitBahvior property to none... then tell me something...
    VB6 2D Sprite control

    To live is difficult, but we do it.

  3. #3

    Thread Starter
    New Member
    Join Date
    Nov 2008
    Posts
    10

    Re: Creating transparent user control with mouse events

    Set hitbehaviour to none and still nothing.

    Just to say, i'm embedding the activex control into excel once i've created it. Don't know if this alters anything?

  4. #4
    PowerPoster joaquim's Avatar
    Join Date
    Apr 2007
    Posts
    3,966

    Re: Creating transparent user control with mouse events

    ok.. i'm test it... but without resolts...
    my sugestion is using API functions for catch the mouse then i think that you can resolve the problem...
    i hope help you
    VB6 2D Sprite control

    To live is difficult, but we do it.

  5. #5
    PowerPoster joaquim's Avatar
    Join Date
    Apr 2007
    Posts
    3,966

    Re: Creating transparent user control with mouse events

    give some minutes... i think that i can resolve your problem
    VB6 2D Sprite control

    To live is difficult, but we do it.

  6. #6

    Thread Starter
    New Member
    Join Date
    Nov 2008
    Posts
    10

    Re: Creating transparent user control with mouse events

    Thanks, this is driving me mad!

    Out of interest, what api calls can i use?

  7. #7
    PowerPoster joaquim's Avatar
    Join Date
    Apr 2007
    Posts
    3,966

    Re: Creating transparent user control with mouse events

    ok.. almost finish...
    i put a timer for read the mouse position(until here normal), but now i must see if the mouse is in the UC(my problem here is that the mouse position is in screen and not in form ou UC)... heres the project try see if you can complete it...
    the colisionprecise funtion is for test if the mouse is in UC or not.... but like i said, i having problem to catch the mouse position in form....
    i hope help you more
    Attached Files Attached Files
    VB6 2D Sprite control

    To live is difficult, but we do it.

  8. #8

    Thread Starter
    New Member
    Join Date
    Nov 2008
    Posts
    10

    Re: Creating transparent user control with mouse events

    Thanks, I'll see if i can get it working...

  9. #9
    PowerPoster joaquim's Avatar
    Join Date
    Apr 2007
    Posts
    3,966

    Re: Creating transparent user control with mouse events

    Quote Originally Posted by LeeGarland
    Thanks, I'll see if i can get it working...
    for resolve the problem, i think these way:
    -i know the mouse position in screen(coord variable type);
    -i know the form position(extender.container.left and extender.container.top);
    -the i subtract the mouse position with form position(i think that these way i catch the mouse position in form);
    -then i test if the mouse position is in UC, by using my function.
    these is my thinking, but i cound't put it to work(i needed more time)... but try you
    VB6 2D Sprite control

    To live is difficult, but we do it.

  10. #10
    PowerPoster joaquim's Avatar
    Join Date
    Apr 2007
    Posts
    3,966

    Re: Creating transparent user control with mouse events

    finaly... i think that i resolve the problem
    in timer change the code for these:
    Code:
    Private Sub Timer1_Timer()
        Dim coord As POINT_TYPE ' receives coordinates of cursor
        Dim retval As Long ' return value
        retval = GetCursorPos(coord)
        Dim x As Long
        Dim y As Long
        x = coord.x * Screen.TwipsPerPixelX - Extender.Container.Left
        y = coord.y * Screen.TwipsPerPixelY - Extender.Container.Top    
        If CollisionPrecise(Extender.Left, Extender.Top, UserControl.Width, UserControl.Height, x, y, 1, 1) = True Then
            RaiseEvent MouseMove(x, y)
        End If
    End Sub
    then test it and tell me something(in these case you don't know what mouse button was clicked, but we are in good way)....
    i hope resolve your problem
    VB6 2D Sprite control

    To live is difficult, but we do it.

  11. #11

    Thread Starter
    New Member
    Join Date
    Nov 2008
    Posts
    10

    Re: Creating transparent user control with mouse events

    It doesn't seem to be working. I;ll have a look and let you know if i can get it going...

  12. #12
    PowerPoster joaquim's Avatar
    Join Date
    Apr 2007
    Posts
    3,966

    Re: Creating transparent user control with mouse events

    ok... heres the groupproject..
    Attached Files Attached Files
    VB6 2D Sprite control

    To live is difficult, but we do it.

  13. #13
    PowerPoster joaquim's Avatar
    Join Date
    Apr 2007
    Posts
    3,966

    Re: Creating transparent user control with mouse events

    it's working like you wanted?
    VB6 2D Sprite control

    To live is difficult, but we do it.

  14. #14

    Thread Starter
    New Member
    Join Date
    Nov 2008
    Posts
    10

    Re: Creating transparent user control with mouse events

    It is! Thankyou! Is there anyway of getting the mouseup working?

    Thankyou for your effort on this!

  15. #15
    PowerPoster joaquim's Avatar
    Join Date
    Apr 2007
    Posts
    3,966

    Re: Creating transparent user control with mouse events

    Quote Originally Posted by LeeGarland
    It is! Thankyou! Is there anyway of getting the mouseup working?

    Thankyou for your effort on this!
    and mousedown too
    Code:
    Private Declare Function GetCursorPos Lib "user32.dll" (lpPoint As POINT_TYPE) As Long
    
    'Event Declarations:
    Event MouseUp(Button As Integer, Shift As Integer, x As Single, y As Single) 'MappingInfo=UserControl,UserControl,-1,MouseUp
    Event MouseMove(x As Long, y As Long, Button As MouseButtons)
    Event MouseDown(Button As Integer, Shift As Integer, x As Single, y As Single) 'MappingInfo=UserControl,UserControl,-1,MouseDown
    
    Type POINT_TYPE
        x As Long
        y As Long
    End Type
    Private Declare Function GetAsyncKeyState Lib "user32" (ByVal vKey As Long) As Integer
    
    Enum MouseButtons
        None = -1
        Left = 0
        Right = 1
        Middle = 2
    End Enum
    
    Private Sub Timer1_Timer()
        Dim coord As POINT_TYPE ' receives coordinates of cursor
        Dim retval As Long ' return value
        retval = GetCursorPos(coord)
        Dim x As Long
        Dim y As Long
        Dim mousebutton As MouseButtons
        x = coord.x * Screen.TwipsPerPixelX - Extender.Container.Left
        y = coord.y * Screen.TwipsPerPixelY - Extender.Container.Top
        If GetAsyncKeyState(vbLeftButton) Then
            mousebutton = 0
        ElseIf GetAsyncKeyState(vbRightButton) Then
            mousebutton = 1
        ElseIf GetAsyncKeyState(vbMiddleButton) Then
            mousebutton = 2
        Else
            mousebutton = -1
        End If
        If CollisionPrecise(Extender.Left, Extender.Top, UserControl.Width, UserControl.Height, x, y, 1, 1) = True Then
            RaiseEvent MouseMove((x - Extender.Left), (y - Extender.Top), mousebutton)
        End If
    End Sub
    these code detect when the mouse button is pressed...
    VB6 2D Sprite control

    To live is difficult, but we do it.

  16. #16

    Thread Starter
    New Member
    Join Date
    Nov 2008
    Posts
    10

    Re: Creating transparent user control with mouse events

    Great thanks!

  17. #17
    PowerPoster joaquim's Avatar
    Join Date
    Apr 2007
    Posts
    3,966

    Re: Creating transparent user control with mouse events

    you wellcome
    VB6 2D Sprite control

    To live is difficult, but we do it.

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