I have a 99% transparent window that kept OnTop that covers the whole screen.
now i mouse move over that window and what i need is, the WindowFromPoint() should detect the windows under this window insted of detecting this window only.
is this posible?
i dont want to 100% transparent the window since if i click that will goto the windows under that. so i really need to detect the windows from point while the clicks should also not go to them.
This should work, when you click on the form then it will determine the window behind it. Have fun!
Private Type POINT_TYPE
X As Long
Y As Long
Private Declare Function GetWindowLong Lib "user32" Alias "GetWindowLongA" (ByVal hWnd As Long, ByVal nIndex As Long) As Long
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 GetCursorPos Lib "user32.dll" (lpPoint As POINT_TYPE) As Long
Private Declare Function WindowFromPoint Lib "user32.dll" (ByVal xPoint As Long, ByVal yPoint As Long) As Long
Private Declare Function GetWindowTextLength Lib "user32.dll" Alias "GetWindowTextLengthA" (ByVal hWnd As Long) As Long
Private Declare Function GetWindowText Lib "user32.dll" Alias "GetWindowTextA" (ByVal hWnd As Long, ByVal lpString As String, ByVal nMaxCount As Long) As Long
Private Declare Function SetLayeredWindowAttributes Lib "user32" (ByVal hWnd As Long, ByVal crKey As Long, ByVal bAlpha As Byte, ByVal dwFlags As Long) As Long
Private Declare Function SetWindowPos Lib "user32" (ByVal hWnd As Long, ByVal hWndInsertAfter As Long, ByVal X As Long, ByVal Y As Long, ByVal cx As Long, ByVal cy As Long, ByVal wFlags As Long) As Long
Private Const GWL_EXSTYLE As Long = (-20)
Private Const WS_EX_TRANSPARENT As Long = &H20&
Private Const WS_EX_LAYERED As Long = &H80000
Private Const LWA_ALPHA As Long = &H2
Private Const SWP_NOMOVE As Long = 2
Private Const SWP_NOSIZE As Long = 1
Private Const FLAGS = SWP_NOMOVE Or SWP_NOSIZE
Private Const HWND_TOPMOST As Long = -1
Private Const HWND_NOTOPMOST As Long = -2
Private Sub TranslucentForm(Frm As Form, TranslucenceLevel As Integer)
' 0 = completely transparent, 255 = completely opaque
SetWindowLong Frm.hWnd, GWL_EXSTYLE, WS_EX_LAYERED
SetLayeredWindowAttributes Frm.hWnd, 0, TranslucenceLevel, LWA_ALPHA
Private Sub Form_Load()
TranslucentForm Me, 80 ' make form semi-transparent
SetWindowPos Me.hWnd, HWND_TOPMOST, 0, 0, 0, 0, FLAGS ' set form always on-top
ClickThru Me, False ' disable click-thru form
Private Sub ClickThru(Frm As Form, bEnabled As Boolean)
If bEnabled = True Then ' enable click-thru form
SetWindowLong Frm.hWnd, GWL_EXSTYLE, GetWindowLong(Frm.hWnd, GWL_EXSTYLE) Or WS_EX_TRANSPARENT
Else ' disable click thru
SetWindowLong Frm.hWnd, GWL_EXSTYLE, GetWindowLong(Frm.hWnd, GWL_EXSTYLE) And Not WS_EX_TRANSPARENT
Private Sub Form_MouseDown(Button As Integer, Shift As Integer, X As Single, Y As Single)
' Display the text of whatever window the mouse clicks.
' Note that this could be a control on a program window.
Dim mousepos As POINT_TYPE ' coordinates of the mouse cursor
Dim wintext As String
Dim slength As Long ' receive title bar text and its length
Dim hWnd As Long ' handle to the window found at the point
Dim retval As Long ' return value
ClickThru Me, True
' Determine the window the mouse cursor is over.
retval = GetCursorPos(mousepos) ' get the location of the mouse
hWnd = WindowFromPoint(mousepos.X, mousepos.Y) ' determine the window that's there
If hWnd = 0 Then ' error or no window at that point
Debug.Print "No window exists at that location."
ClickThru Me, False
' Display that window's title bar text
slength = GetWindowTextLength(hWnd) ' get length of title bar text
wintext = Space(slength + 1) ' make room in the buffer to receive the string
slength = GetWindowText(hWnd, wintext, slength + 1) ' get the text
wintext = Left(wintext, slength) ' extract the returned string from the buffer
Debug.Print "Window text: "; wintext
ClickThru Me, False