【发布时间】:2018-11-21 15:01:19
【问题描述】:
我有两个 WPF 应用程序。它们都有一个窗口,Topmost 属性设置为true。第一个应用程序的窗口是全屏窗口,第二个应用程序只占屏幕的一部分。重要的是,第二个应用程序无法激活(激活被以下代码阻止):
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);
}
当用户单击放置在第一个应用程序上的按钮时,我正在尝试将第二个应用程序置于前面。我试图通过使用SetForegroundWindow 和ShowWindow 来实现这一点,但它不起作用。有人有解决这个问题的办法吗?
【问题讨论】:
标签: c# wpf window pinvoke topmost