• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 523
  • Last Modified:

Check Taskbar State

I need to determine when the taskbar is hidden, and when its visible.

At current, I have a window for an app that snaps itself to the tasbar.  I have been able to code it so that it will re-snap to the appropriate location if the user unlocks and moves the tasbar on the screen.  However, when the auto-hide state of the tasbar is set and the tasbar hides, my window sits snapped to the bounding rectangle of the now invisible tasbar so it looks like its in the middle of no where.

What I want to be able to do is recieve notification somehow when the taskbar is brought into view, and when it slides out of view.  I wish to code my app so it will snap to the edge of the screen instead when the taskbar auto-hides.  I can handle the positioning code, but I am not sure about finding out when the taskbar hides or comes into view.  I know there is a way to determine if the auto-hide property is set, however that is only half the puzzle.  If I snap to screen edge when auto-hide is set, then when the tasbar comes into view it's system tray will be covered by my app unless I can find out that the taskbar is in view and redraw accordingly.

Thank You in advance.
0
r2far
Asked:
r2far
  • 4
  • 4
1 Solution
 
mahesh1402Commented:
For taskbar window you may retrieve handle for taskbar using ::FindWindow ("Shell_TrayWnd", NULL) and You can use ::IsWindowVisible() to determine window is visible or invisible.

HWND hSysTray = ::FindWindow ("Shell_TrayWnd", NULL) ;

if(::IsWindowVisible(hSysTray))
{
 ...
}

Once you got handle you may also use GetWindowRect() like functions to determine dimensions of taskbar window to determine its slide in-out.

Now about getting notifications about 'When' taskbar is hidden is i think you may put above code in seperate thread to watch for taskbar is hidden or not.

-MAHESH

0
 
mahesh1402Commented:
and here is useful to handle taskbar events....handle WM_SETTINGSCHANGE message..

When the taskbar changes size of position it will change the desktops workarea. This results in a WM_SETTINGSCHANGE message that is send to all top-
level windows. You can add a handler for this message to your main window.

When the message comes in, use SystemparametersInfo( SPI_GETWORKAREA... ) to get the work area, if it has changed react to the change as appropriate.
ALso Note that there are a lot of other causes for this message.

-MAHESH
0
 
mahesh1402Commented:
ie.
You may retrieve handle of taskbar window as said above using FindWindow("Shell_TrayWnd", .... then you may retreieve initial position of taskbar using GetWindowRect().. then you may trap WM_SETTINGSCHANGE.. in handler function of this message you may again retrieve position of taskbar to compare its changed or not to ensure event is occured due to taskbar change.

-MAHESH
0
VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

 
r2farAuthor Commented:
Well thanks to yoiur advice I now have 'half' the puzzle.  I can detect if the taskbar is hidden.  When the tasbar is hidden it still returns a rectangle the shows its dimensions when its shown (easy enough for me to work around).

The second half of this is not working yet however, WM_SETTINGSCHANGE does not get called when the user moves their mouse to the hidden taskbar to make it expand onto the screen.  I tried your suggestion of creating a thread to 'watch' the taskbar however it seems that the taskbar never flags itself as not being visible, even when auto-hiding.  I have also tried to hook it's child windows visibility but it all remains flagged as visible even when its off-screen.

They were great suggestions even if they dont seem to work, probably another 'microsoft quark' that the taskbar always says its visible.  Any other suggestions?  What would change if the taskbar is offscreen?  Perhaps the work area?  but then I need to support multiple monitors so how do i determine the current work area AND the current screen resolution for the monitor that the taskbar is located on?

Thank you for your valued input so far.  I am getting closer to a solution, but not there yet.
0
 
r2farAuthor Commented:
>> I can detect if the taskbar is hidden.

It seems this actually does not work.  *sigh.  But then if i could detect this, then the thread to detect if its hidden or not would have worked as well, which it didn't.  I made the mistake of flagging my draw code to draw in the 'taskbar hidden' location when I was testing the 'autohide detection' code.
0
 
mahesh1402Commented:
have you checked window position of taskbar when its in hidden state ? they have any significant value so that to recongnize its in hidden or autohide mode ?

-MAHESH
0
 
r2farAuthor Commented:
I have it working now.  You where correct on many accounts, I was using the rectangle from SHAppBarMessage(ABM_GETTASKBARPOS) to position the window but it always returns a rect as though the taskbar is always visible.  GetWindowRect(), as you said, returned the correct rectangle.  And as for hooking whether it is visible or not, checking window visibility did not work but I compared the taskbars rect with the last known rectangle for it and posting a message to the main thread if they do not match.

Thank you for all your help Mahesh.
0
 
r2farAuthor Commented:
One final note, with the seperate thread watching for taskbar changes I have no need for the WM_SETTINGCHANGE message.

I woulld give you 2 - A's for you help on this if i could.  This problem has been bugging me.
0

Featured Post

Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

  • 4
  • 4
Tackle projects and never again get stuck behind a technical roadblock.
Join Now