Results 1 to 9 of 9

Thread: How to pass a Click through a form?

  1. #1

    Thread Starter
    Frenzied Member longwolf's Avatar
    Join Date
    Oct 2002
    Posts
    1,343

    How to pass a Click through a form?

    I've made a form which 'appears' to be transparent, using screen capture and alpha blending.

    I want to make it so that if a user clicks my form, the mouse, and may be key clicks, pass through my form to what ever is underneath.

    I found some code on PSC that can do this, but I believe it will only work on Win2K and up.
    http://www.planet-source-code.com/vb...60484&lngWId=1

    I'd like this to work on Win98 and up.

    Here's what I've tried so far.
    I can add the API's if you need them

    VB Code:
    1. Private Sub Form_Load()
    2. '    frmClickTo.Show
    3.     FormTopMost Me
    4. End Sub
    5. '
    6. Private Sub Form_MouseDown(Button As Integer, Shift As Integer, x As Single, Y As Single)
    7.     Dim iX As Integer
    8.     Dim iY As Integer
    9.     Dim Pos As PointAPI
    10.     Dim lHwnd As Long
    11.  
    12.     GetCursorPos Pos
    13.     Me.Visible = False
    14.     DoEvents
    15.     lHwnd = WindowFromPoint(Pos.x, Pos.Y)
    16.     SetForegroundWindow lHwnd
    17.     SysSetFocus lHwnd
    18.  
    19.     DoEvents
    20.     Select Case Button
    21.         Case vbLeftButton
    22. '            mouse_event MOUSEEVENTF_LEFTDOWN, Pos.X, Pos.Y, 0, 0
    23.             mouse_event MOUSEEVENTF_LEFTDOWN, 0, 0, 0, 0
    24. '            mouse_event MOUSEEVENTF_LEFTUP, 0, 0, 0, 0
    25.         Case vbRightButton
    26.             mouse_event MOUSEEVENTF_RIGHTDOWN, 0, 0, 0, 0
    27.         Case vbMiddleButton
    28.             mouse_event MOUSEEVENTF_MIDDLEDOWN, 0, 0, 0, 0
    29.     End Select
    30.     Me.Visible = True
    31. End Sub
    32.  
    33. Private Sub Form_MouseUp(Button As Integer, Shift As Integer, x As Single, Y As Single)
    34.     Dim Pos As PointAPI
    35.    
    36.     GetCursorPos Pos
    37.     Me.Visible = False
    38.     DoEvents
    39.     lHwnd = WindowFromPoint(Pos.x, Pos.Y)
    40.     SetForegroundWindow lHwnd
    41.     SysSetFocus lHwnd
    42.  
    43.     DoEvents
    44. 'Debug.Print x
    45. 'Debug.Print Pos.x
    46. 'Debug.Print
    47. 'Debug.Print Y
    48. 'Debug.Print Pos.Y
    49.  
    50.     Me.Visible = False
    51.     DoEvents
    52.     Select Case Button
    53.         Case vbLeftButton
    54.             mouse_event MOUSEEVENTF_LEFTUP, 0, 0, 0, 0
    55.         Case vbRightButton
    56.             mouse_event MOUSEEVENTF_RIGHTUP, 0, 0, 0, 0
    57.         Case vbMiddleButton
    58.             mouse_event MOUSEEVENTF_MIDDLEUP, 0, 0, 0, 0
    59.     End Select
    60.     Me.Visible = True
    61. End Sub

  2. #2
    I'm about to be a PowerPoster! Joacim Andersson's Avatar
    Join Date
    Jan 1999
    Location
    Sweden
    Posts
    14,649

    Re: How to pass a Click through a form?

    I can't see why that wouldn't work on Win95 and above since all of the functions you're using has existed since then, well maybe except from SysSetFocus which I don't recognize at all. Do you have the specifics for that function?

    EDIT: However I have some other doubts about the code. Since you're hiding the Form in MouseDown I don't think you will get a MouseUp event.
    Last edited by Joacim Andersson; May 13th, 2005 at 04:55 PM.

  3. #3

    Thread Starter
    Frenzied Member longwolf's Avatar
    Join Date
    Oct 2002
    Posts
    1,343

    Re: How to pass a Click through a form?

    It's the code on PCS that would only work on Win2K and up.
    It uses SetLayeredWindowAttributes.
    I'm tying to avoid that problem.

    In my code I have tried calling both the mouse down and mouse up from my forms Form_MouseDown event.
    I've also tried leaving my form hidden till it's Form_MouseUp event files.
    So far nothing has worked

    Here's all I can give you on the SysSetFocus API.

    VB Code:
    1. Public Declare Function SysSetFocus Lib "user32" Alias "SetFocus" (ByVal hwnd As Long) As Long
    I don't know where I got it from.
    I was just tying to find some way to set the focus on what ever is below the mouse and my form.

    Here are all the api's from the module attached to the small test program I'm showing here.

    VB Code:
    1. 'API functions
    2. Public Declare Function GetCursorPos Lib "user32" (lpPoint As PointAPI) As Long
    3. Public Declare Function SetCursorPos Lib "user32" (ByVal x As Long, ByVal Y As Long) As Long
    4. Public Declare Function GetAsyncKeyState Lib "user32" (ByVal vKey As Long) As Integer
    5. Public Declare Sub mouse_event Lib "user32" (ByVal dwFlags As Long, ByVal dx As Long, ByVal dy As Long, ByVal cButtons As Long, ByVal dwExtraInfo As Long)
    6.  
    7. 'Mouse Event API constants
    8. Public Const MOUSEEVENTF_LEFTDOWN = &H2
    9. Public Const MOUSEEVENTF_LEFTUP = &H4
    10. Public Const MOUSEEVENTF_MIDDLEDOWN = &H20
    11. Public Const MOUSEEVENTF_MIDDLEUP = &H40
    12. Public Const MOUSEEVENTF_RIGHTDOWN = &H8
    13. Public Const MOUSEEVENTF_RIGHTUP = &H10
    14.  
    15. Public Type PointAPI
    16.     x As Long
    17.     Y As Long
    18. End Type
    19.  
    20. Public Type eMouseState
    21.     Pos As PointAPI
    22.     LButton As Boolean
    23.     MButton As Boolean
    24.     RButton As Boolean
    25. End Type
    26.  
    27. Public Enum eButtons
    28.     LeftButn = 1
    29.     RightBtn = 2
    30.     MidBtn = 4
    31. End Enum
    32.  
    33. Public Type tClicked
    34.     Active As Boolean
    35.     Button As Integer
    36.     ****ft As Integer
    37.     Pos As PointAPI
    38. End Type
    39.  
    40. Public Declare Function WindowFromPoint Lib "user32" (ByVal xPoint As Long, _
    41.                                                       ByVal yPoint As Long) As Long
    42.                                                      
    43. Public Declare Function GetForegroundWindow Lib "user32" () As Long
    44. Public Declare Function SetActiveWindow& Lib "user32" (ByVal hwnd As Long)
    45. Public Declare Function SetForegroundWindow Lib "user32" (ByVal hwnd As Long) As Long
    46. Public Declare Function SysSetFocus Lib "user32" Alias "SetFocus" (ByVal hwnd As Long) As Long

    I don't think you need the code for FormTopMost in the Form_Load() sub
    It's just the common TopMost api code.
    But I can post it you need it.

    For the tests I just made a new project.
    Set the form1 to about 1 inch square.
    Added the API modules and calls.

    For testing, F5 the code, move the form over a link or button in a web page, then click my form just above the link/button.

  4. #4
    I'm about to be a PowerPoster! Joacim Andersson's Avatar
    Join Date
    Jan 1999
    Location
    Sweden
    Posts
    14,649

    Re: How to pass a Click through a form?

    Ah, so the SysSetFocus is the regular SetFocus API only renamed... (since VB has a SetFocus method). However that call, to SysSetFocus doesn't work since you're passing a hWnd that doesn't belong to your process thread. So that call is pretty useless.

    Your Form will not recieve the MouseUp if you hide it.

  5. #5

    Thread Starter
    Frenzied Member longwolf's Avatar
    Join Date
    Oct 2002
    Posts
    1,343

    Re: How to pass a Click through a form?

    Quote Originally Posted by Joacim Andersson
    However that call, to SysSetFocus doesn't work since you're passing a hWnd that doesn't belong to your process thread. So that call is pretty useless.
    Yup, and it looks like SetActiveWindow has the same problem.
    Do you know another VB method or an API that can do it?


    Quote Originally Posted by Joacim Andersson
    Your Form will not recieve the MouseUp if you hide it.
    I know, I'm working on one problem at a time

  6. #6

    Thread Starter
    Frenzied Member longwolf's Avatar
    Join Date
    Oct 2002
    Posts
    1,343

    Re: How to pass a Click through a form?

    *** Bump ***

  7. #7
    Addicted Member
    Join Date
    Jan 2008
    Location
    Essex, UK
    Posts
    149

    Re: How to pass a Click through a form?

    I havent read the entire thread or the sample code but cant this be done using the below simple method:

    1. Make a form and set the forms transparency key to 'Fushia' colour in its properties
    2. Create a panel on the form and set the panels back colour to 'Fushia'
    3. Voila when the form is running it will appear transparent where the panel is or any other items set to 'Fushia' colour and allow you to click through the panel to any item under neath the form
    Development Enviroment: Visual Studio 2008, VB.NET

    Recommend Winspector, far better then SPY++
    http://www.windows-spy.com/

  8. #8
    Frenzied Member
    Join Date
    Mar 2009
    Posts
    1,182

    Re: How to pass a Click through a form?

    appolospb,

    A thread that is over 4 years old?

    Then your signature...

    >NET's been out since 2002 and yet people are still posting VB6 programming code .... Grrrrr !!!

    What do you expect? You are in a VB6 and NOT .NET forum! Don't want to see VB6 Code? Stay out of VB6 Forums! Simple!
    Option Explicit should not be an Option!

  9. #9
    Addicted Member
    Join Date
    Jan 2008
    Location
    Essex, UK
    Posts
    149

    Re: How to pass a Click through a form?

    VB5PRGRMR:

    Sorry, i wont try and help someone in future then mate ill just ignore them as they are using VB6. Your point is irrelevant. I was only browsing this result as it came up in a search for some code.
    Development Enviroment: Visual Studio 2008, VB.NET

    Recommend Winspector, far better then SPY++
    http://www.windows-spy.com/

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