0

As described here I managed to have a Windows-Form one can click through.

My (in my opinion for this question most) relevant code parts read as follows:

First imports:

...
Imports System.Runtime.InteropServices
...

then definition and import of DLLs

...
Private InitialStyle As Integer
Dim PercentVisible As Decimal
...
<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
...

and finally using it

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

As mentioned, this code makes it possible to click throug a windows form, so the clicks reach the programm placed behind the windows form. In my opinion the feature is best described as color filter for parts of or the whole monitor.

Is there a possibility to modify the code in such a way, that only left clicks are transferred through the form? Right mouse clicks are needed to open a contextmenu or the like...

ahstax
  • 1
  • 4

1 Answers1

0

If you want to recieve mouse events, you'll have to remove &H20 from your window style like this

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

but this prevents all mouse event propagating throught your form. Now you can handle the event as you need. And you have to propagate the left mouse click related events all by yourself to other applications.

PavlinII
  • 1,061
  • 1
  • 7
  • 12
  • how would on do this, propagating mouse click related events to other applications? – ahstax Jul 24 '18 at 09:58
  • If YOU want to mess with theese windows messages than YOU have to deal with them. Start here to find the proper window handle https://stackoverflow.com/questions/280818/enumerating-windows-controls-of-another-application-from-net and than use SendMessage to propagate ALL related events. – PavlinII Jul 24 '18 at 11:45