Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

How to get handle to programs that is in taskbar?

Status
Not open for further replies.

feen

Programmer
Sep 9, 2004
4
0
0
LV
I need to get handle to all programs in taskbar for moving, resizing, etc them later.
I can get a list of all visible windows, but the problem is that program puts in the list also windows that aren't on the taskbar (for example if delphi isn't minimized, in the list can be found these: 'Unit1.pas', 'Form1', 'Delphi - Project [Running]').

I filter the list with this code:

if (title<>'') and
(IsWindowVisible(hwnd)=true) and
(IsWindowEnabled(hwnd)=true) and
(GetParent(hwnd)=0) and
(GetWindowLong(hwnd, GWL_EXSTYLE)<>WS_EX_TOOLWINDOW) and
(title<>'Program Manager') then ...

But this isn't working. Looks like delphi isn't parent for those windows (GetParent() always returns 0).

When I added this line to the IF:
... ((GetWindowLong(hWnd, GWL_HWNDPARENT) = 0)or(GetWindowLong(hWnd, GWL_HWNDPARENT) = GetDesktopWindow)) and ...
it filters out delphi forms, but adds to the list programs that are hidden in the tray.

Any ideas how to create/filter this list?
 
Have you checked the Windows API help for getting all top-level windows?

Cheers
 
I can get list of all top-level windows. Searched the help and just now found a little unnecessary thing in program's code: I used "(IsWindowVisible(hWnd)=true) or (IsIconic(hwnd))" instead of "(IsWindowVisible(hWnd)=true)". (Really don't know why I added IsIconic there.) And that allowed to add to the list programs from tray.

Here's the code that works:
if (title<>'') and
(title<>'Program Manager') and
(IsWindowVisible(hWnd)=true) and // <- removes programs hidden in tray
(IsWindowEnabled(hwnd)=true) and
((GetWindowLong(hWnd, GWL_HWNDPARENT) = 0) or
(GetWindowLong(hWnd, GWL_HWNDPARENT) = GetDesktopWindow)) and // <- removes windows that isn't visible on taskbar
(GetWindowLong(hWnd, GWL_EXSTYLE) and WS_EX_TOOLWINDOW = 0) then
begin
//add to list
end;


Those little and hard-to-find mistakes are so unbearable. [mad]
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top