How to query properties of the taskbar

Date:May 6, 2005 / year-entry #114
Orig Link:
Comments:    14
Summary:Occasionally, people want to query properties of the taskbar. I don't quite understand why; you should just get on with your life and let the taskbar get on with its life. After all, there might not even be a taskbar, as we discussed last time. But if you really want to know (perhaps you're collecting...

Occasionally, people want to query properties of the taskbar. I don't quite understand why; you should just get on with your life and let the taskbar get on with its life. After all, there might not even be a taskbar, as we discussed last time.

But if you really want to know (perhaps you're collecting usability data), here's how:

#include <stdio.h>
#include <windows.h>
#include <shellapi.h>

int __cdecl main(int argc, const char* argv[])
 APPBARDATA abd = { sizeof(abd) };
 UINT uState = (UINT)SHAppBarMessage(ABM_GETSTATE, &abd);
 printf("Taskbar on top? %s\n",
        (uState & ABS_ALWAYSONTOP) ? "yes" : "no");
 printf("Taskbar autohide? %s\n",
        (uState & ABS_AUTOHIDE) ? "yes" : "no");
 return 0;

This little program uses the ABM_GETSTATE message of the SHAppBarMessage function to get the "Always on top" and "Auto-hide" properties of the taskbar.

Since you're using the SHAppBarMessage function, if a future version of Windows changes the way it maintains the taskbar state (or perhaps even changes the name of the taskbar to something else), your program will still work because the SHAppBarMessage function will be kept in sync with whatever changes happen to the taskbar.

You can also use the ABM_SETSTATE message to change these states. Note that doing so from a program is discouraged; these state bits belong to the user's preferences. A program shouldn't be messing with the user's preferences. (Well, unless the whole point of the program is to change the user's preferences, of course. But the frequency with which I see this question makes me wonder whether there really are that many settings-tweaking programs out there. I suspect people are using this power for evil, not for good.)

And to stave off follow-up questions: These are the only two properties of the taskbar that are programmable. Exposing a programmable interface for something as highly visible as the taskbar is a very sensitive issue, because once you grant programmatic access to something, there is a very strong temptation for programs to start abusing it.

Comments (14)
  1. Mike Swaim says:

    One of the most common requests that I’ve seen was how to set the user’s display to a particular resolution. With some of them, I had a hard time convincing them how user hostile that was.

  2. grouse says:

    I wrote a Python script that toggles auto-hide, which I have on a keyboard shortcut (no, I do not want auto-hide on all the time, but I do want to be able to toggle it quickly), and which uses this interface.

  3. DaviE says:

    The most common reason that I’ve seen for wanting to know about the taskbar is to display notices in the lower right corner, usually after an automatic update or in response to clicking a tray icon. I’ve seen a lot of programs that don’t work correctly unless the user has this set up with the taskbar at the bottom and never hidden. I personally have my taskbar set up 3 rows high with auto-hide on and always on top, and I often get weird results. In fact, I can almost never see the tooltips for the tray icons.

  4. Anders says:

    Explorer is responsible for the wrong tooltip placement/z-order, not the app

  5. Betty says:

    I admit I have tried to screw around with the taskbar before, not in a distributed application but as an attempt to add some features. However I quickly found that I could not change anything i wanted to anyway (which is good in a way). Sadly I still have no nice way to reorder programs in my taskbar if i ever want to.

  6. DavidE says:

    Explorer is the app I’m talking about in this case.

  7. Dean Harding says:

    Well, you can have custom ‘notification’ dealys, like MSN Messenger, or Zone Alarm or something. These apps need to know where the tray icons are on the screen to ensure that the notifications are placed properly.

    Admitedly, you should be using the Shell ones wherever possible, but if you want to provide custom UI on them (like the ‘Block’ / ‘Allow’ buttons on Zone Alarm) then you have to write your own.

  8. ~Bob says:

    Betty: see TaskArrange for simple app to rearrange task bar buttons.

  9. GregM says:

    This utility allows you to change the order of items on your taskbar, by dragging them into position in a list.

  10. D. Philippe says:

    It looks like SHAppBarMessage() didn’t make it into the WinCE pared-down API, so I guess "whacking registry keys" is still the de facto correct way to change Taskbar settings in CE.

    (Keep in mind not all CE devices are Pocket PC. Our device is an industrial controller, so we don’t particularly care what a user’s shell settings are. In fact, we may eventually replace the shell entirely.)

  11. Jerry Pisk says:

    Dean, you don’t need to know where your icon is. If what you mean is the popup menu that is shown, with a delay, after a user click then Windows has a way of finding where the mouse pounter was at the time of the last message – GetMessagePos. That’s what those programs use.

  12. David Walker says:

    My taskbar is 2 rows high and never hidden. I don’t know if this is an app error or a Windows internal error, but when I’m running Microsoft SQL Server 2000 (Query Analyzer), and I’m looking at a query execution plan, and I hover over a part of it to get the details, there’s a tooltip with a long explanation (about 15 lines long) of what that "node" in the execution plan represents.

    Maybe because I have system fonts set to Custom/105%, and/or because the taskbar is 2 rows high, the bottom line of the multi-line description in Query Analyzer’s tooltip is usually hidden underneath my taskbar. Sometimes I can see the top third of the text on the last line, and sometimes none of it… Kinda hard to read, though.

  13. Dean Harding says:

    Jerry: I’m talking about custom notifications, which aren’t in response to user commands. Like with Zone Alarm when a new program tries to make a connection out, it pops up a notification next to its icon in the task bar saying "Program XYZ is trying to connect to a.b.c.d". It’s not a default Shell notification because they have extra UI on there which lets you allow it, block it, etc.

Comments are closed.

*DISCLAIMER: I DO NOT OWN THIS CONTENT. If you are the owner and would like it removed, please contact me. The content herein is an archived reproduction of entries from Raymond Chen's "Old New Thing" Blog (most recent link is here). It may have slight formatting modifications for consistency and to improve readability.

WHY DID I DUPLICATE THIS CONTENT HERE? Let me first say this site has never had anything to sell and has never shown ads of any kind. I have nothing monetarily to gain by duplicating content here. Because I had made my own local copy of this content throughout the years, for ease of using tools like grep, I decided to put it online after I discovered some of the original content previously and publicly available, had disappeared approximately early to mid 2019. At the same time, I present the content in an easily accessible theme-agnostic way.

The information provided by Raymond's blog is, for all practical purposes, more authoritative on Windows Development than Microsoft's own MSDN documentation and should be considered supplemental reading to that documentation. The wealth of missing details provided by this blog that Microsoft could not or did not document about Windows over the years is vital enough, many would agree an online "backup" of these details is a necessary endeavor. Specifics include:

<-- Back to Old New Thing Archive Index