-1

Using the code i've retrieved from here : VB.net Click through form , i finally get "the click through of form" working but i'm still confused how to disable the click through.

Imports System.Runtime.InteropServices

Public Class Form1

Private InitialStyle As Integer
Dim PercentVisible As Decimal

Private Sub Form_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
    InitialStyle = GetWindowLong(Me.Handle, -20)
    PercentVisible = 0.8

    SetWindowLong(Me.Handle, -20, InitialStyle Or &H80000 Or &H20)

    SetLayeredWindowAttributes(Me.Handle, 0, 255 * PercentVisible, &H2)

    Me.BackColor = Color.Red
    Me.TopMost = True
End Sub

<DllImport("user32.dll", EntryPoint:="GetWindowLong")> Public Shared Function GetWindowLong(ByVal hWnd As IntPtr, ByVal nIndex As Integer) As Integer
End Function

<DllImport("user32.dll", EntryPoint:="SetWindowLong")> Public Shared Function SetWindowLong(ByVal hWnd As IntPtr, ByVal nIndex As Integer, ByVal dwNewLong As Integer) As Integer
End Function

<DllImport("user32.dll", EntryPoint:="SetLayeredWindowAttributes")> Public Shared Function SetLayeredWindowAttributes(ByVal hWnd As IntPtr, ByVal crKey As Integer, ByVal alpha As Byte, ByVal dwFlags As Integer) As Boolean
End Function

End Class

i know the disable is probably within these 2 codes, but i can't get it working, any kind of help will be greatly appreciated :

Public Sub BlaButton_click (blah blah) handles bla bla
        SetWindowLong(Me.Handle, -20, InitialStyle Or &H80000 Or &H20)
        SetLayeredWindowAttributes(Me.Handle, 0, 255 * PercentVisible, &H2)
End Sub
Community
  • 1
  • 1
user3098326
  • 219
  • 1
  • 2
  • 10
  • Using a Const declaration for magic numbers is generally wise. You wouldn't have accidentally used -16 that way and probably would have seen that you reset the style by only using InitialStyle. – Hans Passant Jul 25 '14 at 17:16

1 Answers1

0

Okay i've solved it myself, i just need to erase some parameters.

The code before

SetWindowLong(Me.Handle, -20, InitialStyle Or &H80000 Or &H20)
SetLayeredWindowAttributes(Me.Handle, 0, 255 * PercentVisible, &H2)

i just need to remove the "WS_EX.Transparent" value , in this case the value is &H20, so i removed "Or &H20"

and the other thing is to remove the "PercentVisible" multiplier, i removed "* PercentVisible"

The code after

SetWindowLong(Me.Handle, -20, InitialStyle  Or &H80000)
SetLayeredWindowAttributes(Me.Handle, 0, 255, &H2)

then it works like charm now.

user3098326
  • 219
  • 1
  • 2
  • 10