Getting the desktop windows

Windows specific forum
Jedive
User
User
Posts: 36
Joined: Sun Jun 29, 2003 11:56 am
Location: Spain

Getting the desktop windows

Post 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.
==Jedive==
MacBook Core Duo 2Ghz, 2GB, Intel GMA950, Leopard
Celeron M 1.5, 512MB, Intel 915GM, WinXP/DX9, Ubuntu
lexvictory
Addict
Addict
Posts: 1027
Joined: Sun May 15, 2005 5:15 am
Location: Australia
Contact:

Post 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:
Demonio Ardente

Currently managing Linux & OS X Tailbite
OS X TailBite now up to date with Windows!
PB
PureBasic Expert
PureBasic Expert
Posts: 7581
Joined: Fri Apr 25, 2003 5:24 pm

Re: Getting the desktop windows

Post 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()
I compile using 5.31 (x86) on Win 7 Ultimate (64-bit).
"PureBasic won't be object oriented, period" - Fred.
fweil
Enthusiast
Enthusiast
Posts: 725
Joined: Thu Apr 22, 2004 5:56 pm
Location: France
Contact:

Post 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.
My avatar is a small copy of the 4x1.8m image I created and exposed at 'Le salon international du meuble à Paris' january 2004 in Matt Sindall's 'Shades' designers exhibition. The original laminated print was designed using a 150 dpi printout.
PB
PureBasic Expert
PureBasic Expert
Posts: 7581
Joined: Fri Apr 25, 2003 5:24 pm

Post 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)
I compile using 5.31 (x86) on Win 7 Ultimate (64-bit).
"PureBasic won't be object oriented, period" - Fred.
fweil
Enthusiast
Enthusiast
Posts: 725
Joined: Thu Apr 22, 2004 5:56 pm
Location: France
Contact:

Post by fweil »

@PB ... I am a simpleton !!!

It so simple like this, and it works.

Thnx
My avatar is a small copy of the 4x1.8m image I created and exposed at 'Le salon international du meuble à Paris' january 2004 in Matt Sindall's 'Shades' designers exhibition. The original laminated print was designed using a 150 dpi printout.
Kale
PureBasic Expert
PureBasic Expert
Posts: 3000
Joined: Fri Apr 25, 2003 6:03 pm
Location: Lincoln, UK
Contact:

Post 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
--Kale

Image
lexvictory
Addict
Addict
Posts: 1027
Joined: Sun May 15, 2005 5:15 am
Location: Australia
Contact:

Post by lexvictory »

would this work:

Code: Select all

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

Currently managing Linux & OS X Tailbite
OS X TailBite now up to date with Windows!
Post Reply