views:

238

answers:

4

When our app is started programatically (either through custom action in MSI installer or when starting a new instance) in Windows Vista (also happens in Windows 7 Beta) it won't appear in the taskbar and isn't focused. Alt-tabbing to it will make it appear in the taskbar properly and stay there.

What causes this? I've seen this in some other apps before as well, but not sure why. Out app is .NET WinForms app. Never see this happen in XP, only Vista and 7

Edit: Well, it seems like the only time this happens reproducibly is when it's run by the installer, I believe there's other times it occurs, but I might just be crazy. The launching code is a bit complex to post because we handle various command line launch parameters and it launches a signin form before actually launching the main app etc.

Has anyone had to deal with this scenario before and worked it out?

A: 

Never see this happen in XP, only Vista and 7

Maybe it's a bug in Vista...?

What happens if you call SetForegroundWindow() (or equivalent in .Net)?

Edit

I did of course mean "BringWindowToTop()".

Or do both.

Jimmy J
Bug in Vista or not, the end user doesn't care whose fault it is, it happens in our app (and some others that I can't remember) but not 90% of apps out there, so in the user's eyes it's our bug.
Davy8
A: 

Well, one solution is to use a hack like this. That's really not what it's for.

Usually the decision of whether a window will be in the taskbar or not is based on the border styles it uses. The article I linked to provides a bit more detail. The article's comment about the window having an owner or not is quite possible highly relevant to your issue, since the window might somehow be getting a different owner when launched by the installer.

That article is in VB but it's all based around API calls so the info it provides is pretty language independent.

Brian
+1  A: 

The usual reason for this is that your main application window doesn't have the window styles that let Windows know it's a main application window (rather than a tool window or a dialog box). So Windows is having to guess based on how the app was started, etc.

Use Spy++ to complare the window styles (especially extended styles) if your window to that of some other window that doesn't have this problem. Are you missing the WS_EX_APPWINDOW style? Are any other styles/extended styles different from other top level windows?

John Knoeller
A: 

We had this same problem and fixed it by setting the form property showintaskbar property to true.

Weird that all windows os's dont run apps in the same way!

ToughPal