[英]How to control windows application focus in .NET
I'm using pinvoke "user32.dll" to send my application to back (behind all other apps) so it sits on desktop and vice versa. 我正在使用pinvoke“ user32.dll”将我的应用程序发送回(在所有其他应用程序之后),因此它位于桌面上,反之亦然。 At the moment it just toggles - back/front.
目前,它只是切换-后/前。 Is there a way to detect if my app is at the back and bring it to front or if it's on front and send it to back?
有没有一种方法可以检测我的应用程序在后面,然后放在前面,还是在前面,然后再发送到后面? THanks.
谢谢。
You can detect if your window is the active window by calling 您可以通过调用以下命令来检测您的窗口是否为活动窗口
[DllImport("user32.dll")] static
static extern IntPtr GetForegroundWindow();
You used to be able to call 你以前可以打电话
[DllImport("user32.dll")]
[return: MarshalAs(UnmanagedType.Bool)]
static extern bool SetForegroundWindow(IntPtr hWnd);
to set your window to the foreground, but Microsoft changed it's functionality in Windows ME/2000 onwards (May have been XP?). 将窗口设置为前台,但是Microsoft更改了Windows ME / 2000及更高版本的功能(可能是XP?)。
There are various work arounds attempts for this issue, you may need to test a few to see which works for you. 有多种变通方法尝试解决此问题,您可能需要测试一些以查看哪种方法适合您。
http://www.tek-tips.com/faqs.cfm?fid=4262 http://www.tek-tips.com/faqs.cfm?fid=4262
http://markribau.org/blog/?p=7 http://markribau.org/blog/?p=7
I remember reading about a registry entry that can be set to allow SetForegroundWindow to work as desired, but it's a system wide setting. 我记得曾经读过一篇有关注册表项的信息,该注册表项可以设置为允许SetForegroundWindow根据需要工作,但这是系统范围的设置。
http://www.delphipages.com/forum/showthread.php?t=198261 http://www.delphipages.com/forum/showthread.php?t=198261
You can use SetWindowPos to place you window behind other windows or permanently on top if that helps 您可以使用SetWindowPos将窗口放置在其他窗口的后面或永久放置在顶部(如果有帮助)
http://www.pinvoke.net/default.aspx/user32.SetWindowPos http://www.pinvoke.net/default.aspx/user32.SetWindowPos
http://msdn.microsoft.com/en-us/library/ms633545(VS.85).aspx http://msdn.microsoft.com/en-us/library/ms633545(VS.85).aspx
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.