2 应用最常见的问题
我开发了 2 个应用程序,第一个使用 Win32 API,第二个使用 C# WPF。 我有一个问题,2 个应用程序必须位于最顶层,但第二个应用程序(在 C# 中)必须比第一个应用程序更位于最顶层,问题是第二个应用程序从自动启动运行,然后总是比第一个应用程序启动得更快,而第一个应用程序则更多排名第一的比排名第二的?
我怎样才能在最上面进行第二个应用程序? 或者,当已经有最顶层且位于第一个应用程序下时,我如何在最顶层显示第二个应用程序?
谁能帮助我吗? 问候,
I developed 2 applications one in Win32 API and second in C# WPF.
I have a problem, 2 applications must be top most, but second (in C#) must be stroger top most than first application, problem is second application is run from autostart then will be always faster launched than first application, and first application is more top most than second?
How i can do second application more top most?
Or how i can show second application on topmost when already have top most and this is under first application?
Can anyone help me?
Greetings,
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
来自 http://msdn.microsoft.com/en- us/library/system.windows.window.topmost.aspx:
在 Topmost 属性设置为 true 的窗口组中,当前激活的窗口是最上面的窗口。
因此,激活您想要成为顶部顶部顶部的窗口:-) ...
编辑:我同意 Pieter 的观点,即这样做几乎总是一个坏主意(从用户手中夺取控制权)。这就是为什么微软不会竭尽全力为您提供工具来完成您想做的事情。我会给你一个无罪推论,而不是告诉你“不要这样做”
From http://msdn.microsoft.com/en-us/library/system.windows.window.topmost.aspx:
In the group of windows that have Topmost property is set to true, the window that is currently activated is the topmost window.
So activate the window that you want to be the top-top-topmost :-) ...
EDIT: I agree with Pieter that doing this is something that is almost always a bad idea (taking control from the user). This is why MS does not go out of its way to give you tools to do stuff like you want to do. I'll give you the benefit of the doubt and not tell you "do not do this"
这不是您应该做的事情。
无论一个应用程序还是另一个应用程序位于顶部,您都希望将其留给用户。
但是,还有一些选择。
使用
FindWindow
,可以找到最先启动的窗口的窗口句柄。然后,当您拥有此句柄时,可以使用SetWindowPos
以确保您的窗口位于您找到的其他窗口的顶部。您可以使用 SetWindowPos 的 z 排序参数来实现此目的。注意:这些都是 PInvoke 方法。将 PInvoke 用于
FindWindow
和SetWindowPos
从 C# 调用这些方法。This is not something you should want to do.
Whether one application or the other is on top, is something you want to leave to the user.
However, there are options.
Using
FindWindow
, you can find the window handle of the window that was started first. Then, when you have this handle, you can useSetWindowPos
to ensure that your window is on top of the other window you've found. You use the z-ordering arguments ofSetWindowPos
to achieve this.Note: these are both PInvoke methods. Use the PInvoke for
FindWindow
andSetWindowPos
to call these methods from C#.我只看到一种方法。第二个应用程序应首先监视,直到第一个应用程序启动。之后,您应该从第二个应用程序中删除最顶层的样式并将其收回。此操作使第二个应用程序名列前茅。它并不优雅,但很有效
I see only one way. Second app should monitor first untill first app lunched. After that, you should remove top most style from second app and take it back. This action brings second app top most. It's not elegant but it works