Code : Tout sélectionner
; read the text contents of all (known) window classes (debug tool)
; ----------------------------------------------------
; known classes:
; --------------
; v syslistview32
; v systreeview32
; v static
; v button
; v combobox
; v listbox
; * ToolbarWindow32
; -
; structures
Structure window
window.l
title.s
class.s
parent.l
EndStructure
; globals
Global NewList win.window()
Global NewList win1.window()
Global parent.l
; read treeview
Procedure readsystreeview32(hTreeView)
Define TVItem.TV_ITEM
Buffer = AllocateMemory(100)
GetWindowThreadProcessId_(hTreeView, @ProcID)
hProc = OpenProcess_(#PROCESS_VM_OPERATION | #PROCESS_VM_READ | #PROCESS_VM_WRITE, 0, ProcID)
Result = VirtualAllocEx_(hProc, 0, SizeOf(TV_ITEM), #MEM_RESERVE | #MEM_COMMIT, #PAGE_READWRITE)
TVItem\mask = #TVIF_TEXT | #TVIF_HANDLE
TVItem\pszText = Result +400
TVItem\cchTextMax = 100
If hTreeView
For i = 0 To SendMessage_(hTreeView, #TVM_GETCOUNT, 0, 0)-1
hItem = SendMessage_(hTreeView, #TVM_GETNEXTITEM, #TVGN_ROOT, 0)
For ii.l = 0 To i-1
hItem2 = SendMessage_(hTreeView, #TVM_GETNEXTITEM, #TVGN_CHILD, hItem)
Repeat
If hItem2 = #Null : hItem2 = SendMessage_(hTreeView, #TVM_GETNEXTITEM, #TVGN_NEXT, hItem) : EndIf
If hItem2 = #Null : hItem = SendMessage_(hTreeView, #TVM_GETNEXTITEM, #TVGN_PARENT, hItem) : EndIf
Until hItem2 <> #Null
hItem = hItem2
Next ii
TVItem\hItem = hItem
WriteProcessMemory_(hProc, Result, @TVItem, SizeOf(TV_ITEM), 0)
SendMessage_(hTreeView, #TVM_GETITEM, 0, Result)
ReadProcessMemory_(hProc, Result +400, Buffer, MemorySize(Buffer), 0)
Debug "("+Str(i)+")"+PeekS(Buffer)
Next i
EndIf
VirtualFreeEx_(hProc, Result, 0, #MEM_RELEASE)
CloseHandle_(hProc)
EndProcedure
; read listview
Procedure readsyslistview32(listview)
count=SendMessage_(listview, #LVM_GETITEMCOUNT, 0, 0);
Debug("listview: " + Str(listview))
Debug("Row count: " + Str(count))
lvi.LVITEM
*_lvi.LVITEM
item.s=Space(512)
subitem.s=Space(512)
GetWindowThreadProcessId_(listview, @pid)
process=OpenProcess_(#PROCESS_VM_OPERATION|#PROCESS_VM_READ|#PROCESS_VM_WRITE|#PROCESS_QUERY_INFORMATION, #False, pid)
*_lvi=VirtualAllocEx_(process, #Null, SizeOf(LVITEM), #MEM_COMMIT, #PAGE_READWRITE)
*_item=VirtualAllocEx_(process, #Null, 512, #MEM_COMMIT, #PAGE_READWRITE)
*_subitem=VirtualAllocEx_(process, #Null, 512, #MEM_COMMIT, #PAGE_READWRITE)
lvi\cchTextMax=512
For i=0 To count-1
lvi\iSubItem=0
lvi\pszText=*_item
WriteProcessMemory_(process, *_lvi, @lvi, SizeOf(LVITEM), #Null)
SendMessage_(listview, #LVM_GETITEMTEXT, i, *_lvi)
lvi\iSubItem=1
lvi\pszText=*_subitem
WriteProcessMemory_(process, *_lvi, @lvi, SizeOf(LVITEM), #Null)
SendMessage_(listview, #LVM_GETITEMTEXT, i, *_lvi)
ReadProcessMemory_(process, *_item, item, 512, #Null)
ReadProcessMemory_(process, *_subitem, subitem, 512, #Null)
Debug("Row: " + Str(i))
Debug("Item: " + item)
Debug("Subitem: " + subitem)
Next
VirtualFreeEx_(process, *_lvi, 0, #MEM_RELEASE)
VirtualFreeEx_(process, *_item, 0, #MEM_RELEASE)
VirtualFreeEx_(process, *_subitem, 0, #MEM_RELEASE)
CloseHandle_(process)
EndProcedure
;List top-level windows' children (called by ListWindows)...
Procedure ListChildWindows (window, parameter)
mem = AllocateMemory (255)
GetClassName_ (window, mem, 255)
class$ = PeekS (mem)
mem = ReAllocateMemory (mem, 255)
GetWindowText_ (window, mem, 255)
title$ = PeekS (mem)
FreeMemory (mem)
Debug Str(window)+" / "+title$+" / "+class$ +" / "+ Str(parent)
AddElement(win())
win()\window = window
win()\title = title$
win()\class = class$
win()\parent = parent
EnumChildWindows_ (window, @ListChildWindows (), parameter + 1)
ProcedureReturn #True
EndProcedure
; List top-level windows...
Procedure ListWindows (window, parameter)
mem = AllocateMemory (255)
GetClassName_ (window, mem, 255)
class$ = PeekS (mem)
mem = ReAllocateMemory (mem, 255)
GetWindowText_ (window, mem, 255)
title$ = PeekS (mem)
FreeMemory (mem)
AddElement(win())
win()\window = window
win()\title = title$
win()\class = class$
win()\parent = 0
parent=window
EnumChildWindows_ (window, @ListChildWindows (), 1)
ProcedureReturn #True
EndProcedure
; list all windows in listicongadget
Procedure listallwindows()
EnumWindows_ (@ListWindows (), 0)
ResetList(win())
While NextElement(win())
If Listsize(win1())=0
AddElement(win1())
win1()\title = win()\title
win1()\class = win()\class
win1()\window= win()\window
win1()\parent= win()\parent
Else
dubbel=0
ResetList(win1())
While NextElement(win1())
If win1()\window = win()\window
dubbel=1
DeleteElement(win())
LastElement(win1())
EndIf
Wend
If dubbel=0
AddElement(win1())
win1()\title = win()\title
win1()\class = win()\class
win1()\window= win()\window
win1()\parent= win()\parent
EndIf
EndIf
Wend
ClearList(win1())
ClearGadgetItems(0)
;ClearGadgetItemList(0)
ResetList(win())
While NextElement(win())
AddGadgetItem(0, -1, Chr(34)+win()\title+Chr(34)+Chr(10)+Chr(34)+win()\class+Chr(34)+Chr(10)+Str(win()\window)+Chr(10)+Str(win()\parent))
;If IsWindowVisible_(win()\window)
If win()\parent=0
SetGadgetItemColor(0, ListIndex(win()), #PB_Gadget_FrontColor, RGB(0,0,255))
Else
Select win()\class
Case "SysListView32", "SysTreeView32", "Static", "Button", "ComboBox", "ListBox", "ToolbarWindow32"
SetGadgetItemColor(0, ListIndex(win()), #PB_Gadget_FrontColor, RGB(0,255,0))
Default
SetGadgetItemColor(0, ListIndex(win()), #PB_Gadget_FrontColor, RGB(255,0,0))
EndSelect
EndIf
;Else
; SetGadgetItemColor(0, ListIndex(win()), #PB_Gadget_FrontColor, RGB(0,0,0)) ;Color [, Column])
;EndIf
Wend
EndProcedure
Enumeration 0
#g_list
#g_Refresh
#g_Draw
#g_Items
EndEnumeration
;{ main loop
If OpenWindow(0, 10, 10, 660, 560, "Windows", #PB_Window_SystemMenu|#PB_Window_ScreenCentered)
;If CreateGadgetList(WindowID(0))
ListIconGadget(#g_list, 10, 10, 640, 500, "Title", 200, #PB_ListIcon_FullRowSelect)
AddGadgetColumn(#g_list, 2, "Class", 200)
AddGadgetColumn(#g_list, 3, "WindowID", 100)
AddGadgetColumn(#g_list, 4, "ParentID", 100)
ButtonGadget(#g_Refresh, 10, 510, 60, 20, "Refresh")
ButtonGadget(#g_Draw, 70, 510, 60, 20, "Draw")
ButtonGadget(#g_Items, 130,510, 60, 20, "Items")
DisableGadget(#g_Draw, #True)
DisableGadget(#g_Items, #True)
listallwindows()
Repeat
wevent=WaitWindowEvent()
If wevent=#PB_Event_Gadget
Select EventGadget()
Case #g_list
gad = GetGadgetState(0)
SelectElement(win(), gad)
If win()\parent=0
DisableGadget(2, #False)
Else
DisableGadget(2, #True)
EndIf
Select win()\class
Case "SysListView32", "Static", "Button", "ComboBox", "ListBox", "ToolbarWindow32"
DisableGadget(3, #False)
Case "SysTreeView32"
DisableGadget(3, #False)
Default
DisableGadget(3, #True)
EndSelect
Case #g_Refresh
listallwindows()
Case #g_Draw
gad = GetGadgetState(0)
SelectElement(win(), gad)
window = win()\window
title.s = win()\title
class.s = win()\class
GetWindowRect_(window, @r.Rect)
sx = r\left
sy = r\top
width = r\right-r\left
height= r\bottom-r\top
dc = GetWindowDC_(win()\window)
If CreateImage(0, width, height, 32)
StartDrawing(ImageOutput(0))
col1 = GetBkColor_(dc)
Box(0, 0, width, height, col1)
While NextElement(win())
If win()\parent = window
GetWindowRect_(win()\window, @r.Rect)
dc = GetWindowDC_(win()\window)
col = GetBkColor_(dc)
Box(r\left-sx, r\top-sy, r\right-r\left, r\bottom-r\top, RGB(0,0,0))
Box(r\left-sx+1, r\top-sy+1, r\right-r\left-2, r\bottom-r\top-2, col)
If Len(win()\class)
DrawText((r\left-sx)+((r\right-r\left)/2)-(TextWidth(win()\class)/2), (r\top-sy)+((r\bottom-r\top)/2)-(TextHeight(win()\class)/2), win()\class)
EndIf
Else
LastElement(win())
EndIf
Wend
StopDrawing()
wi.Windowinfo
GetWindowInfo_(window, @wi)
If OpenWindow(1, sy, sx, width, height, "", #PB_Window_BorderLess|#PB_Window_ScreenCentered)
;SetWindowLong_(WindowID(1), #GWL_STYLE, wi\dwstyle)
;SetWindowPos_(WindowID(1), #HWND_TOPMOST, sx, sy, WindowWidth(1), WindowHeight(1), #SWP_FRAMECHANGED) ;
StartDrawing(WindowOutput(1))
DrawImage(ImageID(0), 0, 0)
StopDrawing()
Repeat
wevent=WaitWindowEvent()
Until wevent=#PB_Event_CloseWindow
wevent=0
CloseWindow(1)
EndIf
EndIf
Case #g_Items
gad = GetGadgetState(0)
SelectElement(win(), gad)
Select win()\class
Case "SysListView32"
readsyslistview32(win()\window)
Case "SysTreeView32"
readsystreeview32(win()\window)
Case "Button", "Static"
mem = AllocateMemory (255)
GetClassName_ (win()\window, mem, 255)
Debug PeekS(mem)
mem = ReAllocateMemory (mem, 255)
GetWindowText_ (win()\window, mem, 255)
Debug PeekS(mem)
FreeMemory (mem)
Case "ComboBox"
items = SendMessage_(win()\window, #CB_GETCOUNT, 0, 0)
If items
For a = 0 To items-1
len = SendMessage_(win()\window, #CB_GETLBTEXTLEN, a, 0)
str$ = Space(len+1)
SendMessage_(win()\window, #CB_GETLBTEXT, a, @str$)
Debug str$
Next
EndIf
Case "ListBox"
items = SendMessage_(win()\window, #LB_GETCOUNT, 0, 0)
If items
For a = 0 To items-1
len = SendMessage_(win()\window, #LB_GETTEXTLEN, a, 0)
str$ = Space(len+1)
SendMessage_(win()\window, #LB_GETTEXT, a, @str$)
Debug str$
Next
EndIf
Case "ToolbarWindow32"
items = SendMessage_(win()\window, #TB_BUTTONCOUNT, 0, 0)
If items
EndIf
Default
EndSelect
EndSelect
EndIf
Until wevent=#PB_Event_CloseWindow
;EndIf
EndIf
;}
;{ The end
End
;}