Page 1 of 1
Enumerating windows
Posted: Sat Aug 04, 2007 4:08 pm
by Antithesis
Hello. Could someone please explain to me how to use EnumWindows_() to list the currently open windows? I tried to do it the easy way with Droopy's lib, but it seems to have some sort of issue because any functions that return window names only return the first character of them.
Posted: Sat Aug 04, 2007 4:16 pm
by Trond
The EnumWindows function enumerates all top-level windows on the screen by passing the handle of each window, in turn, to an application-defined callback function. EnumWindows continues until the last top-level window is enumerated or the callback function returns FALSE.
BOOL EnumWindows(
WNDENUMPROC lpEnumFunc, // pointer to callback function
LPARAM lParam // application-defined value
);
Parameters
lpEnumFunc
Points to an application-defined callback function. For more information, see the EnumWindowsProc callback function.
lParam
Specifies a 32-bit, application-defined value to be passed to the callback function.
The EnumWindowsProc function is an application-defined callback function that receives top-level window handles as a result of a call to the EnumWindows or EnumDesktopWindows function.
BOOL CALLBACK EnumWindowsProc(
HWND hwnd, // handle to parent window
LPARAM lParam // application-defined value
);
Parameters
hwnd
Identifies a top-level window.
lParam
Specifies the application-defined value given in EnumWindows or EnumDesktopWindows.
Return Values
To continue enumeration, the callback function must return TRUE; to stop enumeration, it must return FALSE.
Code: Select all
; Enumerate all windows
Procedure EnumWindowsProc(hWnd, ID)
Debug hWnd
ProcedureReturn 1
EndProcedure
EnumWindows_(@EnumWindowsProc(), 0)
Code: Select all
; Get the title of a window
Procedure.s GetWindowText(hWnd)
Protected Buffer.s = Space(GetWindowTextLength_(hWnd))
GetWindowText_(hWnd, @Buffer, GetWindowTextLength_(hWnd)+SizeOf(Character))
ProcedureReturn Buffer
EndProcedure
Posted: Sat Aug 04, 2007 4:18 pm
by Kale
I use similar code here, but i only want the visible ones:
http://www.purebasic.fr/english/viewtopic.php?t=12314
Code: Select all
Procedure UpdateAndFilterNewWindows(hWindow, Unused)
CurrentWindowTitle.s = Space(1024)
GetWindowText_(hWindow, CurrentWindowTitle, 1024)
If CurrentWindowTitle <> "" And CurrentWindowTitle <> "Program Manager"
If IsWindowVisible_(hWindow)
Debug CurrentWindowTitle
EndIf
EndIf
ProcedureReturn #True
EndProcedure
EnumWindows_(@UpdateAndFilterNewWindows(), 0)
Posted: Sat Aug 04, 2007 4:53 pm
by Antithesis
Thank you very much!
Also could you tell me how to get the Text value of a control if it has one? What I want is write an windows live messenger conversation logger so I want to find the control that contains the conversation and get its text value and check if it changes...
Posted: Sat Aug 04, 2007 5:37 pm
by Trond
You can use the same code to get get the text from a control.
Posted: Sat Aug 04, 2007 5:43 pm
by Antithesis
Hmm I tried that but with no luck. I was hoping there's some other way. I think the problem is that the control I'm dealing with is some weird thing called DirectUIHWND which seems to contain the entire WLM chat window within itself.
Any suggestions?
Re: Enumerating windows
Posted: Mon Jun 11, 2012 5:10 pm
by SeregaZ
so any news about read and control DirectUIhwnd after 2007?
Re: Enumerating windows
Posted: Mon Jun 11, 2012 6:57 pm
by eJan
I have found nice code:
Code: Select all
; PB: http://www.purebasic.fr/english/viewtopic.php?p=103024#p103024
Procedure GetDesktopWindows()
h = GetWindow_(GetDesktopWindow_(), #GW_CHILD)
Repeat
If IsWindowVisible_(h) = #True
c$ = Space(999) : GetWindowText_(h, c$, 999)
If c$ <> ""
Debug "Handle = " + Str(h) + ", Caption = " + c$
EndIf
EndIf
h = GetWindow_(h, #GW_HWNDNEXT)
Until h = 0
EndProcedure
GetDesktopWindows()
Re: Enumerating windows
Posted: Mon Jun 11, 2012 7:10 pm
by srod
The EnumWindows function does not enumerate child windows.
This function is more reliable than calling the GetWindow function in a loop. An application that calls GetWindow to perform this task risks being caught in an infinite loop or referencing a handle to a window that has been destroyed.

Re: Enumerating windows
Posted: Tue Jun 12, 2012 6:37 am
by SeregaZ
eJan wrote:I have found nice code:
Code: Select all
; PB: http://www.purebasic.fr/english/viewtopic.php?p=103024#p103024
Procedure GetDesktopWindows()
h = GetWindow_(GetDesktopWindow_(), #GW_CHILD)
Repeat
If IsWindowVisible_(h) = #True
c$ = Space(999) : GetWindowText_(h, c$, 999)
If c$ <> ""
Debug "Handle = " + Str(h) + ", Caption = " + c$
EndIf
EndIf
h = GetWindow_(h, #GW_HWNDNEXT)
Until h = 0
EndProcedure
GetDesktopWindows()
how it is help to read items and choice one of them in this DirectUIhwnd window?
