Date: 02-16-2022
Return to Index
created by gbSnippets
'Compiler Comments:
'This code compiles only in PBWin10. It can be converted to PBWin9
'by adjusting the pt argument in WindowFromPoint 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
x1 As Long
x2 As Long
x3 As Long
x4 As Long
End Type
%IDC_Graphic = 500
%IDC_Button = 501
Global hDlg, hWnd, hClipBoard 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 w,h As Long, PS As Paintstruct, pt As PointAPI
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
Clipboard Get Bitmap To hClipboard
Graphic Copy hClipboard, 0
SetWindowPos(hDlg, %HWND_TOPMOST, 0, 0, 0, 0, %SWP_NoMove Or %SWP_NoSize) 'on Top
EnumChildWindows(GetDesktopWindow, CodePtr(ParentCallback), 0&)
ReDim Preserve wList(iCount)
? "Count = " + str$(iCount)
Case %WM_MouseMove
GetCursorPos pt
hWnd = WindowFromPoint (pt)
ScreenToClient hDlg, pt
Graphic Copy hClipboard, 0
Graphic Set Pos (0,0)
Graphic Print Str$(pt.x) + Str$(pt.y) + Str$(hWnd)
Graphic Box (pt.x-50,pt.y-50)-(pt.x+50,pt.y+50),,%Blue
Graphic ReDraw
Case %WM_LButtonUp
Dialog End hDlg
Case %WM_Destroy
End Select
End Function
Function ParentCallback (ByVal hWndChild As Long, lRaram As Long) As Long
Local szClass, szText As Asciiz * %MAX_PATH, lRes as Long
lRes = GetClassName(hWndChild, szClass, SizeOf(szClass))
lRes = GetWindowText(hWndChild, szText, SizeOf(szText))
Incr iCount
wList(iCount).type = "child"
wList(iCount).class = szClass
wList(iCount).text = szText
lRes = EnumChildWindows(hWndChild, CodePtr(ChildCallback), 0&)
Function = 1
End Function
Function ChildCallback (ByVal hWndChild As Long, lRaram As Long) As Long
Local szClass, szText As Asciiz * %MAX_PATH, lRes As Long
lRes = GetClassName(hWndChild, szClass, SizeOf(szClass))
lRes = GetWindowText(hWndChild, szText, SizeOf(szText))
Incr iCount
wList(iCount).type = "parent"
wList(iCount).class = szClass
wList(iCount).text = szText
Function = 1
End Function
'gbs_01087
'Date: 03-10-2012
http://www.garybeene.com/sw/gbsnippets.htm