How can I query the location of the taskbar on secondary monitors?


A customer wanted to know how to get the location of the taskbar on secondary monitors. "I know that SHApp­Bar­Message will tell me the location of the taskbar on the primary monitor, but how do I get its location on secondary monitors?"

We asked the customer what their actual problem is, where they think that determining the taskbar location on secondary monitors is the solution. The customer was kind enough to explain.

Our application shows a small window, and sometimes users move it behind the taskbar. They then complain that they can't find it, and they have to move their taskbar out of the way in order to find it again. We want our window to automatically avoid the taskbar.

The solution to the customer's problem is to stop obsessing about the taskbar. Use the Get­Monitor­Info function to obtain the working area for the monitor the window is on. The window can then position itself inside the working area.

The working area is the part of the monitor that is not being used by the taskbar or other application bars. The customer was too focused on avoiding the taskbar and missed the fact that they needed to avoid other taskbar-like windows as well.

The customer was kind enough to write back to confirm that Get­Monitor­Info was working.

Comments (22)
  1. 12BitSlab says:

    More often than not, the simplest answer is the best.  Over thinking a problem happens far too often.

  2. Joshua says:

    My trick was maximizing (and not painting) a window. Easier to discover with poor documentation (dial-up and offline docs didn't know about Win95).

  3. Jimmy Queue says:

    This shows it's worth asking a question or two before answering. "We want our window to automatically avoid the taskbar." despite being what the guy said, isn't what he actually wanted to implement. It also saves you from answering next weeks email asking how to find the location of the flerpyderp bar on the Secondary monitor and so on..

  4. hagenp says:

    Good documentation tells you what to do to achieve a given task. Problem: It can (and does) usually not tell you, if the task itself is the correct approach to a real-world problem or if you should go down a different path altogether.

    Excellent people with lots of experience - like Raymond - can ask a customer about their real problem,, and then can point out "the proper way" to achieve what is needed.

    To "do the right thing", often you need to know much, much more knowledge and experience than you can read from an alphabetic command reference. But the time required to get to this level of proficiency is often regarded as unproductive (especially by 'streamlined' and 'efficient' organizations).

    Hm... Maybe the online documentation of SHApp­Bar­Message could have a note pointing to Get­Monitor­Info: "If your use case is XYZ, please use AbcDef instead"...?

  5. IanBoyd says:

    @hagenp I believe that is what this blog is. A collection of wisdom not contained in the SDK. Not everyone has access to edit the MSDN library at their will.

  6. Yuri says:

    Another 'Taskbar' tunnel vision problem I ran into:

    Management wanted a notification icon for our application. But they also asked for a convoluted workaround in case the app was virtualised in an environment without a taskbar. Had to show them the notification still appears to convince them to let go of the workaround.

  7. Antonio Rodríguez says:

    At last an story with a happy ending! Must be the Christmas spirit :-) . It's sad how many of the stories told by Raymond has an open (and probably wrong) end. But I'm affraid it's not the storyteller's blame...

  8. Myria says:

    Where can I report a UI bug related to monitors?  Specifically, that in some cases, the "identify" button in the resolution config dialog will show the wrong numbers on the monitors' screens.

  9. @Myria: What do you mean by wrong?  I have two monitors, but the display adapter initializes the one on the right first, so that one is always 1.  It might look wrong because I've told Windows to treat my left display as the primary, but that's not what the numbers describe.

    [That's not even what the numbers describe. The numbers are arbitrary. In retrospect, the monitors should have been labeled with shapes, or the numbers should be randomized at each run, to emphasize that the numbers don't mean anything. -Raymond]
  10. Fred says:

    @MNGoldenEagle

    Then there's the scenario where the user has physically swapped monitor 1 and monitor 2 without swapping cables.

  11. @hagenp says:

    SHAppBarMessage function (msdn.microsoft.com/.../bb762108(v=vs.85).aspx) ...

    ABM_GETTASKBARPOS (0x00000005) ... To retrieve the area of the screen not covered by both the taskbar and other app bars—the working area available to your application—, use the GetMonitorInfo function ...

    According to the wayback machine that's been there since mid-2013, so you got your wish.

  12. @@hagenp: That was probably when Raymond was actually dealing with this customer, since his articles seem to post about a year or so after he writes them (except for the topical ones).

  13. Myria says:

    @MNGoldenEagle: I have two monitors at different resolutions because they're physically different (even different brands).  The monitor on the left showed number 1 when I clicked Detect, but in the little display in the dialog, it was number 2.  I confirmed this by clicking the monitor icon there, and it showed the brand name of that monitor.

  14. cheong00 says:

    In the past, some folks suggest that Windows should be made so if multiple monitor is connected, we should be able to set one to display desktop and the other display start screen.

    I wonder if that would be implemented, what would Get­Monitor­Info() be return? Should we prepare for it to return something like (0,0,0,0) for work area in the future?

  15. Someone says:

    The monitor numbers (at the monitor icons in the dialog as also the big ones at clicking "Identify") are only connecting the monitor devices with the "Display" combobox just below the monitor icons. This is the only meaning.

    Also, I think the size of the monitor icon is related to the vertical/horizontal number of pixels, but completely unrelated to the physical size of the monitors.

  16. ender says:

    Speaking of taskbars and stuff hiding behind them, how do I find out which taskbar button is blinking when I'm using high-contrast mode with the taskbars set to auto-hide? The only indication that some button wants my attention is that some (but not necessary all) taskbars unhide, and won't hide again until I find and click that button (activate the program). For some reason the button neither blinks, nor it changes it's colour (in high contrast mode), so I'm left with clicking 10-30 taskbar buttons across my 4 monitors to get the taskbars to hide again.

  17. SimonRev says:

    In fairness to the asker -- he/she may have never encountered another desktop taskbar (they aren't tremendously common).  Knowing that there is a concept called the "work area" may or may not be obvious depending on your previous experience. To me that is one of those dark corners of the Windows API that I have personally explored, but I know there are thousands of such nooks that I haven't.

  18. Anon says:

    @IanBoyd

    It really is sad that Raymond hasn't been given open access to update the docs as he sees fit.

    Then again, the terrible software development culture we've created means he'd then be considered the sole person responsible for it.

  19. Anon says:

    @SimonRev

    I agree that people don't explore the nooks of the API randomly. But if you were explicitly working in that corner, how cowardly and short-sighted would it be to not learn anything about it?

  20. DWalker says:

    @Myria:  "Where can I report a UI bug related to monitors?"  Go to support.microsoft.com and your options are listed there.

  21. Marc K says:

    @DWalker: That's funny.  I highly doubt one of those support options will lead to connecting you to someone with the ability to fix a bug.  For something like that, you're going to likely need an expensive enterprise support agreement.

  22. John Doe says:

    I guess that, when considering whether a bug is really a bug to be fixed, some Offices are more relevant than others.

Comments are closed.

Skip to main content