Results 1 to 6 of 6

Thread: [RESOLVED] Click through transparent form

  1. #1

    Thread Starter
    Fanatic Member TokersBall_CDXX's Avatar
    Join Date
    Mar 2003
    Location
    America
    Posts
    571

    Resolved [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:
    1. SetWindowLong Me.hWnd, GWL_EXSTYLE, GetWindowLong(Me.hWnd, WS_EXSTYLE) Or WS_EX_TRANSPARENT

    this is what I've converted it to

    VB Code:
    1. 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
    Build your own personalized flash based chat room for your webpage for FREE! http://www.4computerheaven.com

  2. #2
    PowerPoster
    Join Date
    Feb 2002
    Location
    Canada, Toronto
    Posts
    5,803

    Re: Click through transparent form

    WS_EXSTYLE is GWL_EXSTYLE

  3. #3

    Thread Starter
    Fanatic Member TokersBall_CDXX's Avatar
    Join Date
    Mar 2003
    Location
    America
    Posts
    571

    Re: Click through transparent form

    hmm well then, that doesn't seem to work...

    VB Code:
    1. Public Class Form1
    2.     Inherits System.Windows.Forms.Form
    3.     Private Const GWL_EXSTYLE = (-20)
    4.     Private Const WS_EX_TRANSPARENT = &H20
    5.  
    6.     Private Declare Function SetWindowLong Lib "user32" Alias "SetWindowLongA" (ByVal hwnd As Long, ByVal nIndex As Long, ByVal dwNewLong As Long) As Long
    7.     Private Declare Function GetWindowLong Lib "user32" Alias "GetWindowLongA" (ByVal hwnd As Long, ByVal nIndex As Long) As Long
    8.  
    9.  
    10. #Region " Windows Form Designer generated code "
    11.  
    12.  
    13.     Private Sub Form1_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles MyBase.Load
    14.         SetWindowLong(sender.Handle.ToInt32, GWL_EXSTYLE, GetWindowLong(sender.Handle.ToInt32, GWL_EXSTYLE) Or WS_EX_TRANSPARENT)
    15.     End Sub
    16. End Class
    Build your own personalized flash based chat room for your webpage for FREE! http://www.4computerheaven.com

  4. #4
    Hyperactive Member
    Join Date
    Mar 2005
    Location
    Bath, England
    Posts
    411

    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:
    1. Public Class Form1
    2.     Inherits System.Windows.Forms.Form
    3.     Private Const GWL_EXSTYLE As Integer = (-20)
    4.     Private Const WS_EX_TRANSPARENT As Integer = &H20
    5.  
    6.     Private Declare Function SetWindowLong Lib "user32" Alias "SetWindowLongA" (ByVal hwnd As IntPtr, ByVal nIndex As Integer, ByVal dwNewLong As Integer) As Integer
    7.     Private Declare Function GetWindowLong Lib "user32" Alias "GetWindowLongA" (ByVal hwnd As IntPtr, ByVal nIndex As Integer) As Integer
    8.  
    9. #Region " Windows Form Designer generated code "
    10.  
    11.  
    12.     Private Sub Form1_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles MyBase.Load
    13.         SetWindowLong(Me.Handle, GWL_EXSTYLE, GetWindowLong(Me.Handle, GWL_EXSTYLE) Or WS_EX_TRANSPARENT)
    14.     End Sub
    15. 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.
    Last edited by Parallax; Jan 12th, 2006 at 07:03 PM.
    "Make it idiot-proof and someone will make a better idiot"

  5. #5

    Thread Starter
    Fanatic Member TokersBall_CDXX's Avatar
    Join Date
    Mar 2003
    Location
    America
    Posts
    571

    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:
    1. Public Class Form1
    2.     Inherits System.Windows.Forms.Form
    3.     Private Const GWL_EXSTYLE As Integer = (-20)
    4.     Private Const WS_EX_TRANSPARENT As Integer = &H20
    5.  
    6.     Private Declare Function SetWindowLong Lib "user32" Alias "SetWindowLongA" (ByVal hwnd As IntPtr, ByVal nIndex As Integer, ByVal dwNewLong As Integer) As Integer
    7.     Private Declare Function GetWindowLong Lib "user32" Alias "GetWindowLongA" (ByVal hwnd As IntPtr, ByVal nIndex As Integer) As Integer
    8.  
    9. #Region " Windows Form Designer generated code "
    10.  
    11.  
    12.     Private Sub Form1_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles MyBase.Load
    13.         SetWindowLong(Me.Handle, GWL_EXSTYLE, GetWindowLong(Me.Handle, GWL_EXSTYLE) Or WS_EX_TRANSPARENT)
    14.     End Sub
    15. 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
    Build your own personalized flash based chat room for your webpage for FREE! http://www.4computerheaven.com

  6. #6
    Hyperactive Member
    Join Date
    Mar 2005
    Location
    Bath, England
    Posts
    411

    Re: Click through transparent form

    No problem. Don't forget Thread Tools->Mark as Resolved if you're done.
    "Make it idiot-proof and someone will make a better idiot"

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