|
-
May 13th, 2005, 03:58 PM
#1
Thread Starter
Frenzied Member
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:
Private Sub Form_Load()
' frmClickTo.Show
FormTopMost Me
End Sub
'
Private Sub Form_MouseDown(Button As Integer, Shift As Integer, x As Single, Y As Single)
Dim iX As Integer
Dim iY As Integer
Dim Pos As PointAPI
Dim lHwnd As Long
GetCursorPos Pos
Me.Visible = False
DoEvents
lHwnd = WindowFromPoint(Pos.x, Pos.Y)
SetForegroundWindow lHwnd
SysSetFocus lHwnd
DoEvents
Select Case Button
Case vbLeftButton
' mouse_event MOUSEEVENTF_LEFTDOWN, Pos.X, Pos.Y, 0, 0
mouse_event MOUSEEVENTF_LEFTDOWN, 0, 0, 0, 0
' mouse_event MOUSEEVENTF_LEFTUP, 0, 0, 0, 0
Case vbRightButton
mouse_event MOUSEEVENTF_RIGHTDOWN, 0, 0, 0, 0
Case vbMiddleButton
mouse_event MOUSEEVENTF_MIDDLEDOWN, 0, 0, 0, 0
End Select
Me.Visible = True
End Sub
Private Sub Form_MouseUp(Button As Integer, Shift As Integer, x As Single, Y As Single)
Dim Pos As PointAPI
GetCursorPos Pos
Me.Visible = False
DoEvents
lHwnd = WindowFromPoint(Pos.x, Pos.Y)
SetForegroundWindow lHwnd
SysSetFocus lHwnd
DoEvents
'Debug.Print x
'Debug.Print Pos.x
'Debug.Print
'Debug.Print Y
'Debug.Print Pos.Y
Me.Visible = False
DoEvents
Select Case Button
Case vbLeftButton
mouse_event MOUSEEVENTF_LEFTUP, 0, 0, 0, 0
Case vbRightButton
mouse_event MOUSEEVENTF_RIGHTUP, 0, 0, 0, 0
Case vbMiddleButton
mouse_event MOUSEEVENTF_MIDDLEUP, 0, 0, 0, 0
End Select
Me.Visible = True
End Sub
-
May 13th, 2005, 04:51 PM
#2
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.
-
May 13th, 2005, 05:39 PM
#3
Thread Starter
Frenzied Member
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:
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:
'API functions
Public Declare Function GetCursorPos Lib "user32" (lpPoint As PointAPI) As Long
Public Declare Function SetCursorPos Lib "user32" (ByVal x As Long, ByVal Y As Long) As Long
Public Declare Function GetAsyncKeyState Lib "user32" (ByVal vKey As Long) As Integer
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)
'Mouse Event API constants
Public Const MOUSEEVENTF_LEFTDOWN = &H2
Public Const MOUSEEVENTF_LEFTUP = &H4
Public Const MOUSEEVENTF_MIDDLEDOWN = &H20
Public Const MOUSEEVENTF_MIDDLEUP = &H40
Public Const MOUSEEVENTF_RIGHTDOWN = &H8
Public Const MOUSEEVENTF_RIGHTUP = &H10
Public Type PointAPI
x As Long
Y As Long
End Type
Public Type eMouseState
Pos As PointAPI
LButton As Boolean
MButton As Boolean
RButton As Boolean
End Type
Public Enum eButtons
LeftButn = 1
RightBtn = 2
MidBtn = 4
End Enum
Public Type tClicked
Active As Boolean
Button As Integer
****ft As Integer
Pos As PointAPI
End Type
Public Declare Function WindowFromPoint Lib "user32" (ByVal xPoint As Long, _
ByVal yPoint As Long) As Long
Public Declare Function GetForegroundWindow Lib "user32" () As Long
Public Declare Function SetActiveWindow& Lib "user32" (ByVal hwnd As Long)
Public Declare Function SetForegroundWindow Lib "user32" (ByVal hwnd As Long) As Long
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.
-
May 13th, 2005, 05:50 PM
#4
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.
-
May 13th, 2005, 06:21 PM
#5
Thread Starter
Frenzied Member
Re: How to pass a Click through a form?
 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?
 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
-
May 16th, 2005, 12:07 AM
#6
Thread Starter
Frenzied Member
Re: How to pass a Click through a form?
-
Jul 8th, 2009, 08:23 AM
#7
Addicted Member
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
-
Jul 8th, 2009, 11:06 PM
#8
Frenzied Member
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!
-
Jul 9th, 2009, 02:39 AM
#9
Addicted Member
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.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|