简体   繁体   English

转到非活动窗口

[英]Bring to front inactive window

I've got two WPF applications. 我有两个WPF应用程序。 Both of them has a window with Topmost property set to true . 他们两个都有一个Topmost属性设置为true的窗口。 Window of first application is a full-screen window and second app takes only part of the screen. 第一个应用程序的窗口是全屏窗口,第二个应用程序仅占据部分屏幕。 The important thing is also that, the second application can't be activated (activation was blocked by following code): 同样重要的是,第二个应用程序无法激活(以下代码阻止了激活):

private const int GWL_EXSTYLE = -20;
private const int WS_EX_NOACTIVATE = 0x08000000;

[DllImport("user32.dll")]
public static extern IntPtr SetWindowLong(IntPtr hWnd, int nIndex,int dwNewLong);
[DllImport("user32.dll")]
public static extern int GetWindowLong(IntPtr hWnd,int nIndex);

protected override void OnSourceInitialized(EventArgs e)
{
    WindowInteropHelper helper = new WindowInteropHelper(window);
    SetWindowLong(helper.Handle, GWL_EXSTYLE, GetWindowLong(helper.Handle, GWL_EXSTYLE) | WS_EX_NOACTIVATE);
}

I'm trying to bring to front second application, when user click on button which is placed on first application. 当用户单击放置在第一个应用程序上的按钮时,我试图将第二个应用程序置于前面。 I tried to achieve this by using SetForegroundWindow and ShowWindow , but it's not working. 我试图通过使用SetForegroundWindowShowWindow实现此目的,但是它不起作用。 Do someone have any solution for this problem? 有人对此问题有解决方案吗?

Try 尝试

yourSpecificWindow.Activate();

if that doesnt do the trick, also include 如果那不能解决问题,还包括

yourSpecificWindow.TopMost = true;
yourSpecificWindow.Focus();

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM