tags:

views:

43

answers:

3

My application pops up a custom dialog whenever new items are found in an RSS feed, the custom dialog starts off the bottom of the screen, raises up, pauses, and then drops back down.

I want the dialog to be on top of other windows (because the notices are important to me), so I set the TopMost property on the form to true. Problem is it is also on top of the task bar (which I don't want).

Is there a way to make the dialog be on top of other windows, but not the task bar?

(Please don't discuss whether or not I should do this. This is a custom application for my use only, and that is the way I want it to work. I have also added a setting to turn this functionality on/off, in case I don't want it to work like that anymore.)

A: 

Did you try

form.ShowInTaskbar = false;
vc 74
That is already set. The dialogs title does not appear in the task bar, the window itself is over or covering the task bar.
Tester101
A: 

The reason this is not going to work is because you don't know whether the top most window you want the popup to be over is going to be above or below the taskbar. Most of the time, an actual top most window will lie over the taskbar. You can't have a window underneath the taskbar and above the other window if the other window is already over the taskbar.

You can fiddle a little bit with SetWindowPos and see whether you maybe get a result you like, but this will get very difficult.

See http://msdn.microsoft.com/en-us/library/ms633545(VS.85).aspx for how SetWindowPos() works and http://www.pinvoke.net/default.aspx/user32.setwindowpos and http://www.pinvoke.net/default.aspx/Constants.SWP for how you can call this function from WinForms.

Pieter
So I'm pretty much hosed? Can I change the TopMost property at any time? for example could I have the dialog raise up, then set TopMost=true, pause with dialog on top, set TopMost=flase, then lower the dialog?
Tester101
That shouldn't be a problem no. I'd say: give it a try :).
Pieter
Is there any way to manipulate a forms z-index?
Tester101
You do this via SetWindowPos, but you can only do this relative to other Windows. You can e.g. get the handle of the taskbar via FindWindow("Shell_TrayWnd", null).
Pieter
+1  A: 

There's a good example of a popup above the taskbar here:
http://www.codeproject.com/KB/miscctrl/taskbarnotifier.aspx

If the user is dragging the window, you'll need to override the OnPaint event. The key is calling SetBounds() on the form, calculating the bounds from the form size and Screen.PrimaryScreen.WorkingArea, which excludes the taskbar from its height.

HTH,
James

James B
Was halfway through my answer when you posted this. Excellent example in the link there.
Thorin
Hate that... happens to me all the time : )
James B
This is a good link, but it doesn't really help me, due to the way my pop-up notification is designed. I guess if I find the time I could redesign to work similar to this example, but for now I can live with what I have.
Tester101
You don't need to redesign your app... if you study the example, you may be able to glean the elements you need for your code. Like I say, all you really need is a call to SetBounds(), using the Screen.PrimaryScreen.WorkingArea rectangle to determine the lower-right corner of the area above the taskbar. I'll try to put in some example code.
James B