Code: Select all
GetClassName_ (window, ReAllocateMemory (0, 255), 255)
class$ = PeekS (MemoryID ())
Code: Select all
GetClassName_ (window, ReAllocateMemory (0, 255), 255)
class$ = PeekS (MemoryID ())
Code: Select all
#TH32CS_SNAPHEAPLIST = $1
#TH32CS_SNAPPROCESS = $2
#TH32CS_SNAPTHREAD = $4
#TH32CS_SNAPMODULE = $8
#TH32CS_SNAPALL = #TH32CS_SNAPHEAPLIST | #TH32CS_SNAPPROCESS | #TH32CS_SNAPTHREAD | #TH32CS_SNAPMODULE
#TH32CS_INHERIT = $80000000
#INVALID_HANDLE_VALUE = -1
#MAX_PATH = 260
#PROCESS32LIB = 9999
; List used to store processes on 'Gosub GetProcessList'...
Global NewList Process32.PROCESSENTRY32 ()
; Returns process name from window handle...
; IMPORTANT! You should 'Gosub GetProcessList' before calling this!
Procedure.s FindWindowProcessName (window)
ResetList (Process32 ())
While NextElement (Process32 ())
GetWindowThreadProcessId_ (window, @pid)
If pid = Process32 ()\th32ProcessID
exe$ = GetFilePart (PeekS (@Process32 ()\szExeFile))
LastElement (Process32 ())
EndIf
Wend
ProcedureReturn exe$
EndProcedure
; Returns Process ID from window handle...
Procedure.l FindWindowProcessID (window)
GetWindowThreadProcessId_ (window, @pid)
ProcedureReturn pid
EndProcedure
#TREEGADGET = 0
Global level
Procedure ListChildWindows (window, parameter)
*mem = ReAllocateMemory (0, 255)
GetClassName_ (window, *mem, 255)
class$ = PeekS (*mem)
*mem = ReAllocateMemory (0, 255)
GetWindowText_ (window, *mem, 255)
title$ = PeekS (*mem)
If title$ = ""
title$ = "Unnamed window"
EndIf
If FindString (LCase (class$), LCase ("MSTaskSwWClass"), 1)
title$ = "****** " + title$
EndIf
FreeMemory (*mem)
level = level + 1
AddGadgetItem (#TREEGADGET, -1, title$ + " [Window ID: " + Str (window) + "] [Class: " + class$ + "]", #Null, level)
EnumChildWindows_ (window, @ListChildWindows (), parameter + 1)
level = level - 1
ProcedureReturn #True
EndProcedure
Procedure ListWindows (window, parameter)
*mem = ReAllocateMemory (0, 255)
GetClassName_ (window, *mem, 255)
class$ = PeekS (*mem)
*mem = ReAllocateMemory (0, 255)
GetWindowText_ (window, *mem, 255)
title$ = PeekS (*mem)
If title$ = ""
title$ = "Unnamed window"
EndIf
FreeMemory (*mem)
level = level + 1
AddGadgetItem (#TREEGADGET, -1, title$ + " [Window ID: " + Str (window) + "] [Class: " + class$ + "] [Process " + Str (FindWindowProcessID (window)) + ": " + FindWindowProcessName (window) + "]", #Null, level)
EnumChildWindows_ (window, @ListChildWindows (), 1)
level = level - 1
ProcedureReturn #True
EndProcedure
Procedure WinHook (WindowID, Message, wParam, lParam)
If Message = #WM_SIZE
ResizeGadget (#TREEGADGET, 0, 0, WindowWidth (0), WindowHeight (0) - 25)
RedrawWindow_ (GadgetID (#TREEGADGET), #Null, #Null, #RDW_INVALIDATE)
ResizeGadget (1, 0, WindowHeight (0) - 25, WindowWidth (0), 25)
EndIf
ProcedureReturn #PB_ProcessPureBasicEvents
EndProcedure
Procedure GetWindowTree ()
ClearGadgetItems (#TREEGADGET)
level = level + 1
AddGadgetItem (#TREEGADGET, -1, "All windows...", #Null, level)
EnumWindows_ (@ListWindows (), 0)
level = level - 1
EndProcedure
OpenWindow (0, 0, 0, 800, 600, "All windows...", #PB_Window_SystemMenu | #PB_Window_ScreenCentered | #PB_Window_MinimizeGadget | #PB_Window_MaximizeGadget | #PB_Window_SizeGadget)
TreeGadget (#TREEGADGET, 0, 0, WindowWidth (0), WindowHeight (0) - 25)
Gosub GetProcessList
GetWindowTree ()
SetGadgetItemState (0, 0, #PB_Tree_Expanded)
ButtonGadget (1, 0, WindowHeight (0) - 25, WindowWidth (0), 25, "Update list...")
CreatePopupMenu (0)
MenuItem (1, "Copy")
SetWindowCallback (@WinHook ())
Repeat
Select WaitWindowEvent ()
Case #PB_Event_Menu
Select EventMenu ()
Case 1
SetClipboardText (GetGadgetItemText (0, GetGadgetState (0)) + Chr (13) + Chr (10))
EndSelect
Case #PB_Event_CloseWindow
End
Case #PB_Event_Gadget
Select EventGadget ()
Case 0
Select EventType ()
Case #PB_EventType_RightClick
DisplayPopupMenu (0, WindowID (0))
EndSelect
Case 1
Gosub GetProcessList
GetWindowTree ()
SetGadgetItemState (0, 0, #PB_Tree_Expanded)
EndSelect
EndSelect
ForEver
; -----------------------------------------------------------------------------
; Paste at bottom of your code...
; -----------------------------------------------------------------------------
End ; Leave this here!
GetProcessList:
ClearList (Process32 ())
; Add processes to Process32 () list...
If OpenLibrary (#PROCESS32LIB, "kernel32.dll")
snap = CallFunction (#PROCESS32LIB, "CreateToolhelp32Snapshot", #TH32CS_SNAPPROCESS, 0)
If snap
Proc32.PROCESSENTRY32
Proc32\dwSize = SizeOf (PROCESSENTRY32)
If CallFunction (#PROCESS32LIB, "Process32First", snap, @Proc32)
AddElement (Process32 ())
CopyMemory (@Proc32, @Process32 (), SizeOf (PROCESSENTRY32))
While CallFunction (#PROCESS32LIB, "Process32Next", snap, @Proc32)
AddElement (Process32 ())
CopyMemory (@Proc32, @Process32 (), SizeOf (PROCESSENTRY32))
Wend
EndIf
CloseHandle_ (snap)
EndIf
CloseLibrary (#PROCESS32LIB)
EndIf
Return