Page 1 of 1

Getting the desktop windows

Posted: Mon Sep 12, 2005 1:48 am
by Jedive
I want to get the list of currently opened windows on the desktop. I am doing it with EnumWindows_(). The problem is that, instead of returning handles to the windows that I can see on the desktop, I get the handle of hundreds of windows. I guess that they are invisible windows or something created by the OS for different purposes. How can I get JUST the real Windows? I mean, I just want to get the windows that are listed on the taskbar.

Posted: Mon Sep 12, 2005 10:36 am
by lexvictory
not sure if this will work, but you can try it:

Code: Select all

procedure enumwindows(hwnd, lparam)
winplace.WINDOWPLACEMENT
getwindowplacement_(hwnd, @winplace)
if winplace\showCmd = #SW_HIDE
;do nothing
else
debug hwnd
endif
endprocedure

enumwindows_(@enumwindows(), 0)
and i emphasize the point that im not sure if it will work, this was wat i came up with from a quick search in my winapi help file!!! :shock:

Re: Getting the desktop windows

Posted: Mon Sep 12, 2005 12:16 pm
by PB

Code: Select all

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()

Posted: Mon Sep 12, 2005 12:36 pm
by fweil
Works good PB ...

I could not find a way to emulate the desktop button that minimizes all windows ... this seems to be that way.

But when I add a ShowWindow_() line to minimize all windows, it sometimes make a mess and explorer.exe burns the CPU until a kill it. I don't know exactly what is wrong there.

Posted: Mon Sep 12, 2005 12:49 pm
by PB
> But when I add a ShowWindow_() line to minimize all windows, it sometimes
> make a mess and explorer.exe burns the CPU until a kill it.

I did a "Show Desktop" app like that once. :) Do this:

Code: Select all

PostMessage_(FindWindow_("Shell_TrayWnd",0),#WM_COMMAND,419,0) ; 419 = #MIN_ALL
Note: This might leave some windows still open -- I had to then parse them
all (with a loop like the above), and minimize them manually.

You could also do it like this, which should minimize all windows by simulating
the Windows+D key combination to show the Desktop:

Code: Select all

keybd_event_(#VK_LWIN,0,0,0)
keybd_event_(#VK_D,0,0,0)
keybd_event_(#VK_D,0,#KEYEVENTF_KEYUP,0)
keybd_event_(#VK_LWIN,0,#KEYEVENTF_KEYUP,0)

Posted: Mon Sep 12, 2005 1:12 pm
by fweil
@PB ... I am a simpleton !!!

It so simple like this, and it works.

Thnx

Posted: Tue Sep 13, 2005 12:19 am
by Kale
You might like to check the source of this little tool i made, it has a handy 'get all the opened windows' procedure. :)

viewtopic.php?p=68261

Posted: Tue Sep 13, 2005 6:16 am
by lexvictory
would this work:

Code: Select all

postmessage_(#hwnd_broadcast, #wm_command, #sc_minimize, 0)
i dont know if it will work...