Date: 02-16-2022
Return to Index
created by gbSnippets
'This code generates a list of the handle for all windows. Then, as the
'mouse moves around the screen, it draws the outline of the window found
'under the mouse. It creates a bitmap the size of the screen, on which the
'outline is drawn.
'Compiler Comments:
'This code compiles only in PBWin10. It can be converted to PBWin9
'by adjusting the pt argument in WindowFromPoint and PtInRect to pass
'pt.x and pt.y separately.
'Primary Code:
'The EnumChildWindows API is the basis for this code.
'Compilable Example: (Jose Includes)
#Compiler PBWin 9, PBWin 10
#Compile EXE
#Dim All
%Unicode=1
#Include "WIN32API.INC"
Type WindowList
hWnd As Dword
type As Asciiz * %Max_Path
class As Asciiz * %Max_Path
text As Asciiz * %Max_Path
R as Rect
End Type
%IDC_Graphic = 500
%IDC_Button = 501
Global hDlg, hWnd, hClipBoard, hGraphic As Dword
Global wList() As WindowList, iCount as Long
Function PBMain As Long
Local Count As Dword, w,h As Long
Desktop Get Size To w,h
Dialog New Pixels, 0, "",0,0,w,h, %WS_Popup Or %WS_Maximize To hDlg
Dialog Show Modal hDlg Call MainProc
End Function
CallBack Function MainProc As Long
Local i,w,h,Flag As Long, PS As Paintstruct, pt As PointAPI, temp$, hTemp As Dword
Select Case CbMsg
Case %WM_InitDialog
ReDim wList(10000)
keybd_event(%VK_SnapShot, 0, 0, 0) 'screen on clipboard
Dialog Get Size hDlg To w,h
Control Add Graphic, hDlg, %IDC_Graphic, "", 0,0,w,h
Graphic Attach hDlg, %IDC_Graphic, ReDraw
Graphic Width 4
Clipboard Get Bitmap To hClipboard
Graphic Copy hClipboard, 0
SetWindowPos(hDlg, %HWND_TOPMOST, 0, 0, 0, 0, %SWP_NoMove Or %SWP_NoSize) 'on Top
EnumerateChildren GetDeskTopWindow
ReDim Preserve wList(iCount)
For i = 0 to 25
temp$ = temp$ + $crlf + str$(wList(i).hwnd) + str$(wList(i).R.nLeft) + str$(wList(i).R.nTop) + str$(wList(i).R.nRight) + str$(wList(i).R.nBottom)
Next i
? temp$
Case %WM_MouseMove
hTemp = 0
GetCursorPos pt
hWnd = WindowFromPoint (pt)
ScreenToClient hDlg, pt
Graphic Copy hClipboard, 0
For i = 0 to UBound(wList)
If wList(i).hwnd = hDlg Then Iterate For
If wList(i).hwnd = hGraphic Then Iterate For
If wList(i).R.nRight = 1920 and wList(i).R.nBottom = 1080 Then Iterate For
If PtInRect(wList(i).R, pt) Then
Graphic Box (wList(i).R.nLeft,wList(i).R.nTop)-(wList(i).R.nRight,wList(i).R.nBottom),,%Blue
hTemp = wList(i).hwnd
Flag = 1 : Exit For
End If
Next i
Graphic Set Pos (0,0)
Graphic Print str$(hTemp) + Str$(pt.x) + Str$(pt.y) + Str$(hWnd)
Graphic ReDraw
Case %WM_LButtonUp
Dialog End hDlg
Case %WM_Destroy
End Select
End Function
Sub EnumerateChildren(hWndParent As Long)
Local hWndChild As Long, xRes As String
Incr iCount
hWndChild = GetWindow(hWndParent, %GW_CHILD OR %GW_HWNDFIRST)
Do While hWndChild <> 0
if IsWindowVisible (hWndChild) Then wList(iCount).hwnd = hWndChild 'save handle
GetWindowRect hWndChild, wList(iCount).R 'save bounding dimensions
EnumerateChildren hWndChild
hWndChild = GetWindow(hWndChild, %GW_HWNDNEXT)
Loop
End Sub
'gbs_01086
'Date: 03-10-2012
http://www.garybeene.com/sw/gbsnippets.htm