[RESOLVED] Click through transparent form
Upon countless searches on the forums i came upon a post the outlines exactly what I'm trying to do :
http://www.vbforums.com/showthread.p...ansparent+form
I want to be able to click throuhg a transparent form so that the external application(s) beneath receive the mouse events instead of my app...
how ever this code was written for vb6 using api, I've converted all of it except I am un able to locate the Const Def of WS_EXSTYLE
This is the vb6 line of code:
VB Code:
SetWindowLong Me.hWnd, GWL_EXSTYLE, GetWindowLong(Me.hWnd, WS_EXSTYLE) Or WS_EX_TRANSPARENT
this is what I've converted it to
VB Code:
SetWindowLong(Me.Handle.ToInt32, GWL_EXSTYLE, GetWindowLong(Me.Handle.ToInt32, WS_EXSTYLE) Or WS_EX_TRANSPARENT)
how ever I can't find the const defition for WS_EXSTYLE
any ideas?
thanx
Re: Click through transparent form
WS_EXSTYLE is GWL_EXSTYLE
Re: Click through transparent form
hmm well then, that doesn't seem to work...
VB Code:
Public Class Form1
Inherits System.Windows.Forms.Form
Private Const GWL_EXSTYLE = (-20)
Private Const WS_EX_TRANSPARENT = &H20
Private Declare Function SetWindowLong Lib "user32" Alias "SetWindowLongA" (ByVal hwnd As Long, ByVal nIndex As Long, ByVal dwNewLong As Long) As Long
Private Declare Function GetWindowLong Lib "user32" Alias "GetWindowLongA" (ByVal hwnd As Long, ByVal nIndex As Long) As Long
#Region " Windows Form Designer generated code "
Private Sub Form1_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles MyBase.Load
SetWindowLong(sender.Handle.ToInt32, GWL_EXSTYLE, GetWindowLong(sender.Handle.ToInt32, GWL_EXSTYLE) Or WS_EX_TRANSPARENT)
End Sub
End Class
Re: Click through transparent form
Well, for one thing you need to convert your function calls and declarations to work within .NET. I suspect the reason it isn't working is that window handles need to be declared as IntPtr's, not Long Integers. I've been through and changed it, try this instead:
VB Code:
Public Class Form1
Inherits System.Windows.Forms.Form
Private Const GWL_EXSTYLE As Integer = (-20)
Private Const WS_EX_TRANSPARENT As Integer = &H20
Private Declare Function SetWindowLong Lib "user32" Alias "SetWindowLongA" (ByVal hwnd As IntPtr, ByVal nIndex As Integer, ByVal dwNewLong As Integer) As Integer
Private Declare Function GetWindowLong Lib "user32" Alias "GetWindowLongA" (ByVal hwnd As IntPtr, ByVal nIndex As Integer) As Integer
#Region " Windows Form Designer generated code "
Private Sub Form1_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles MyBase.Load
SetWindowLong(Me.Handle, GWL_EXSTYLE, GetWindowLong(Me.Handle, GWL_EXSTYLE) Or WS_EX_TRANSPARENT)
End Sub
End Class
Note also that you should use "Me.Handle" instead of "sender.Handle". Since sender is declared as an object I'm suprised the project even compiled; Object obviously doesn't have a Handle property and would need to be cast into a Form object anyway.
Re: Click through transparent form
Quote:
Originally Posted by Parallax
Well, for one thing you need to convert your function calls and declarations to work within .NET. I suspect the reason it isn't working is that window handles need to be declared as IntPtr's, not Long Integers. I've been through and changed it, try this instead:
VB Code:
Public Class Form1
Inherits System.Windows.Forms.Form
Private Const GWL_EXSTYLE As Integer = (-20)
Private Const WS_EX_TRANSPARENT As Integer = &H20
Private Declare Function SetWindowLong Lib "user32" Alias "SetWindowLongA" (ByVal hwnd As IntPtr, ByVal nIndex As Integer, ByVal dwNewLong As Integer) As Integer
Private Declare Function GetWindowLong Lib "user32" Alias "GetWindowLongA" (ByVal hwnd As IntPtr, ByVal nIndex As Integer) As Integer
#Region " Windows Form Designer generated code "
Private Sub Form1_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles MyBase.Load
SetWindowLong(Me.Handle, GWL_EXSTYLE, GetWindowLong(Me.Handle, GWL_EXSTYLE) Or WS_EX_TRANSPARENT)
End Sub
End Class
Note also that you should use "Me.Handle" instead of "sender.Handle". Since sender is declared as an object I'm suprised the project even compiled; Object obviously doesn't have a Handle property and would need to be cast into a Form object anyway.
Thanx, Works perfectly ;)
Re: Click through transparent form
No problem. Don't forget Thread Tools->Mark as Resolved if you're done. :thumb: