Hello,
I'm asking here mostly because this is one of the best places I know of to ask WinAPI questions. I'm doing this in C++ but I can provide FreePascal code if it is imperative (I was considering switching because it might be easier to prototype with, anyway).
Basically the issues I am having have to do with the poorly documented behavior of EnumWindows and the accessibility window event hooks (SetWinEventHook).
For example when using EnumWindows with the checks below, I can (for the most part) enumerate all windows on the desktop that have some visible presence, whether or not they are minimized:
LStyle := GetWindowLong(HWnd, GWL_STYLE);
if LStyle and (WS_BORDER or WS_VISIBLE) <> (WS_BORDER or WS_VISIBLE) then
exit;
Unfortunately with the advent of Windows 10 there are "background applications" which are most commonly Windows Store apps. If a compatible application is closed they will be suspended similar to an Android application's lifecycle. They will sometimes show up in the EnumWindows listing and match the given criteria despite having no interactable desktop presence (they are not minimized nor are they in the tray). I attempted to figure out if I could cross reference the process list and check for suspended applications (Task Manager seems to be able to tell) but wasn't able to find anything. Does anyone have any suggestions?
With the accessibility hooks, I am interested in updates of the desktop, so I decided to hook the event range EVENT_OBJECT_CREATE to EVENT_OBJECT_DESTROY using SetWinEventHook. There are similar problems with this as with EnumWindows.
if not (event = EVENT_OBJECT_CREATE and
idObject = OBJID_WINDOW and
idChild = INDEXID_CONTAINER) then
exit;
LStyle := GetWindowLong(HWnd, GWL_STYLE);
if LStyle and (WS_BORDER) <> (WS_BORDER) then
exit;
WS_VISIBLE is never set, even though it should be as far as I know, but this difference mostly doesn't matter. What does matter is that while simple applications like File Explorer windows will send EVENT_OBJECT_CREATE and EVENT_OBJECT_DESTROY lots of other applications do not, e.g. an already opened Windows Store app does not send these events when resumed or suspended, and multiwindow applications like Firefox do not send them when creating new windows.
Does anyone have any suggestions? As far as I know the only relevant documentation is the documentation for the functions I am using, so any pointers are welcome. I've started Spy++ to try to investigate window properties that I could select based on, and this got me the values to use with EnumWindows, but the current issues are a nonstarter that I can't get around.
If sample code would be helpful I can whip something up. Since I was mostly planning to do it anyway I will edit this when I get it done.
Thanks in advance,
guest.