开发者

Window shown in background

At some users of my application, some WPF Windows will be shown behind the Shellwindow. This occurs only o开发者_C百科n some places. The Shellwindow does not has set Topmost. I hope someone could give me a tip, what I can do to prevent this.

Thanks.

Best Regards, thomas


There are only three scenarios that I know of where one of your windows could lose the focus and disappear behind the window of another app:

  • a program calling SetForegroundWindow() to shove one of its windows into the foreground. Windows has specific counter-measures against this since ~Win98, a user interface crime that was committed too often. It only permits this if it hasn't detected any input events in the active window for a while. It will blink the taskbar button otherwise. Of course, programmers have found counter-counter-measures. A version of Windows Update started doing this roughly two years ago. Luckily the programmer that was responsible for that was taken outside and shot.

  • the self-inflicted kind, triggered by for a short time having none of your windows being capable of receiving the focus. The Windows window manager is forced to find another window to give the focus to. That may well be a 'shell window', whatever is handy. You get this most typically when displaying a dialog and either hiding your main window or disabling it yourself. And showing it again when the dialog is closed. That's too late, there's a fraction of a second where no window can get the focus. It doesn't repeat well btw, not in the least because it depends what other window might be available.

  • displaying a toplevel non-owned window on a thread. Such a window cannot have any Z-order relationship with the other windows in your app and only has the desktop window as the parent. Where it competes with any other window, including windows owned by Explorer. Getting it shown on top of other windows is a crap-shoot, one that usually works but sometimes doesn't. Especially painful for the user when it is a message box.


You can set the Window.Owner of secondary windows to the main window to avoid child windows appearing behind the main window. I am assuming this is what you mean by the shell window.

Here are some consequences of doing this (from the documentation):

  • If an owner window is minimized, all its owned windows are minimized as well.
  • If an owned window is minimized, its owner is not minimized.
  • If an owner window is maximized, both the owner window and its owned windows are restored.
  • An owner window can never cover an owned window.
  • Owned windows that were not opened using ShowDialog are not modal. The user can still interact with the owner window.
  • If you close an owner window, its owned windows are also closed.
  • If an owned window was opened by its owner window using Show, and the owner window is closed, the owned window's Closing event is not raised.
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜