Detecting the Desktop / Taskbar

Technical support and scripting issues

Moderators: JRL, Dorian (MJT support)

Post Reply
User avatar
PepsiHog
Automation Wizard
Posts: 517
Joined: Wed Apr 08, 2009 4:19 pm
Location: Florida

Detecting the Desktop / Taskbar

Post by PepsiHog » Mon Jan 31, 2011 6:26 pm

v12 (Windows XP sp3)

Hello,

Need a way to detect the Taskbar. To be more specific, the entire bar at the bottom of the screen. I can use

>GetWindowHandle>Program Manager,res

to get the handle for the program manager, but what can I use to get the handle for the Taskbar? I can get the handle of the taskbar by writing a program that on left click or some other trigger it displays the handle.
But what escapes me is what is the name of the taskbar?

To try to resolve this I tried....

GetWindowNames>196662,title,cl (the current handle of the Taskbar)
mdl>%title% %cl%

And it comes back with " Shell_TrayWnd"
I did this to show that it has a space in the name.
But then I tried....

>GetWindowHandle> Shell_TrayWnd,out
Edit - That's because it's not showing a NAME, but rather the CLASS. oops. But I learned.

But it just comes back with %out% (no result) Same "no result" without the space.

If knowing what I am doing helps, I am playing around with writing a hide window program. Using some of the scripts that JRL and others have provided in this forum. Why? Well..... because I can (Thanks to some of you). And I get some practice and experience with new ideas.

Any ideas?

Thanks.
Last edited by PepsiHog on Tue Feb 01, 2011 6:20 am, edited 1 time in total.
Windows 7

PepsiHog. Yep! I drink LOTS of Pepsi (still..in 2024) AND enjoy programming. (That's my little piece of heaven!)

The immensity of the scope of possibilities within Macro Scheduler pushes the user beyond just macros!

User avatar
JRL
Automation Wizard
Posts: 3532
Joined: Mon Jan 10, 2005 6:22 pm
Location: Iowa

Post by JRL » Mon Jan 31, 2011 8:16 pm

Try this:
Edit - Added code in case the desired class name is the first handle encountered. Sorry I missed that possibility on the first posting.
Fixed to work with Win 7 and hopefully beyond.

Code: Select all

Let>kk=1
LibFunc>user32,GetDesktopWindow,hwnd
LibFunc>user32,GetWindow,GWres,hwnd,5
GetWindowNames>GWres,title,class
If>class=Shell_TrayWnd,Done
Let>Window_%kk%=%GWres%

Repeat>GWres
  Add>kk,1
  LibFunc>user32,GetWindow,GWres,%GWres%,2
  Let>Window_%kk%=%GWres%
  GetWindowNames>GWres,title,class
  If>class=Shell_TrayWnd,Done
Until>GWres=0

Label>Done
Let>hwnd=Window_%kk%
MDL>%CLASS% handle = %hwnd%
Last edited by JRL on Mon Jan 31, 2011 10:17 pm, edited 1 time in total.

User avatar
PepsiHog
Automation Wizard
Posts: 517
Joined: Wed Apr 08, 2009 4:19 pm
Location: Florida

Previous post

Post by PepsiHog » Mon Jan 31, 2011 9:55 pm

Thanks, JRL.

Hey,

So I studied this script. Will you let me know if I got it right, please?

From looking at the system windows in MS, it seems that 65556 is the top of all windows open. The beginning of ALL windows.

And then you simply cycle through them until you find the name that
the command GetWindowNames gave you for the taskbar.

And LibFunc provides the window handle.

How'd I do?

The only thing I have no idea about is... What is the parm 5?

Thanks again.

Edit - I realize now that the space in the result was the NAME(or lack of) and what I saw was the class. oops.
Windows 7

PepsiHog. Yep! I drink LOTS of Pepsi (still..in 2024) AND enjoy programming. (That's my little piece of heaven!)

The immensity of the scope of possibilities within Macro Scheduler pushes the user beyond just macros!

User avatar
JRL
Automation Wizard
Posts: 3532
Joined: Mon Jan 10, 2005 6:22 pm
Location: Iowa

Post by JRL » Tue Feb 01, 2011 1:02 am

How'd I do?
Perfect.
What is the parm 5?
Microsoft explains it better than I could.
http://msdn.microsoft.com/en-us/library ... 85%29.aspx

User avatar
PepsiHog
Automation Wizard
Posts: 517
Joined: Wed Apr 08, 2009 4:19 pm
Location: Florida

Thanks

Post by PepsiHog » Tue Feb 01, 2011 6:14 am

Thanks JRL!

I just added that link to my favorites.

And ofcourse, Thanks for the assist. :)
Windows 7

PepsiHog. Yep! I drink LOTS of Pepsi (still..in 2024) AND enjoy programming. (That's my little piece of heaven!)

The immensity of the scope of possibilities within Macro Scheduler pushes the user beyond just macros!

User avatar
Rain
Automation Wizard
Posts: 550
Joined: Tue Aug 09, 2005 5:02 pm
Contact:

Post by Rain » Fri Apr 22, 2011 10:13 pm

I can't get JRL's code to work in Windows 7. So this is what I came up with.
Taskbar must be located either at the bottom or top but it can be modified if the taskbar is located on the left or right side of the screen.

Code: Select all

GetScreenRes>ScreenWidth,ScreenHeight
Let>WIN_USEHANDLE=1

GetWindowHandle>User Promoted Notification Area,handle

Repeat>TaskbarWidth
Sub>handle,1
GetWindowSize>%handle%,TaskbarWidth,TaskbarHeight
Until>TaskbarWidth,ScreenWidth

Let>WIN_USEHANDLE=0
mdl>Taskbar Width: %TaskbarWidth%%CRLF%Taskbar Height: %TaskbarHeight%


User avatar
JRL
Automation Wizard
Posts: 3532
Joined: Mon Jan 10, 2005 6:22 pm
Location: Iowa

Post by JRL » Fri Apr 22, 2011 10:26 pm

Rain,
Thanks for the heads up. I recently purchased a Win 7 computer but I haven't done anything with it yet. I'll see if I can get it fired up before the end of summer :? then perhaps figure out what is wrong with the previously posted code when using Win 7. I know while reading On the MSDN site about API stuff they often mention Win 7 changes. Maybe they reworked the GetWindow function or maybe they renamed the task bar icon class.

In any case. Thank you for your post. I look forward to trying it.

User avatar
Rain
Automation Wizard
Posts: 550
Joined: Tue Aug 09, 2005 5:02 pm
Contact:

Post by Rain » Sat Apr 23, 2011 1:46 pm

You're welcome JRL. I'm glad I was able to figure out a workaround.

I think you will like Windows 7. I'm still a huge XP Pro fan but I'm glad I finally made the switch to Windows 7 Ultimate. The speed is awesome and large APPs load in an instant on my system, the same APPs took roughly 30-40 seconds to load in XP Pro.

User avatar
Rain
Automation Wizard
Posts: 550
Joined: Tue Aug 09, 2005 5:02 pm
Contact:

Post by Rain » Tue May 03, 2011 5:00 pm

There was a problem with my original example. This one should correct it.

Code: Select all

GetScreenRes>ScreenWidth,ScreenHeight
Let>WIN_USEHANDLE=1

GetWindowHandle>User Promoted Notification Area,handle
Add>handle,500
Repeat>TaskbarWidth
Sub>handle,1
GetWindowSize>%handle%,TaskbarWidth,TaskbarHeight
Until>TaskbarWidth,ScreenWidth

Let>WIN_USEHANDLE=0
mdl>Taskbar Width: %TaskbarWidth%%CRLF%Taskbar Height: %TaskbarHeight%


Post Reply
Sign up to our newsletter for free automation tips, tricks & discounts