【发布时间】:2020-01-16 21:22:30
【问题描述】:
我正在尝试将一个 UWP APP 窗口放在前面,并使窗口最大化。
我试过UWP APP窗口是否恢复,我的代码工作正常。但是如果窗口被最小化了,窗口就不会显示,仍然保持最小化状态。
我正在使用FindWindowByCaption(IntPtr.Zero, "Demo App") 来获取窗口的句柄。 Demo App 是 UWP APP 的显示名称。
简单代码如下:
class Program
{
[DllImport("user32.dll")]
static extern bool SetForegroundWindow(IntPtr hWnd);
[DllImport("user32.dll")]
static extern bool ShowWindow(IntPtr hWnd, int nCmdShow);
/// Find window by Caption only. Note you must pass IntPtr.Zero as the first parameter.
[DllImport("user32.dll", EntryPoint = "FindWindow", SetLastError = true)]
static extern IntPtr FindWindowByCaption(IntPtr ZeroOnly, string lpWindowName);
static void Main(string[] args)
{
IntPtr handle = FindWindowByCaption(IntPtr.Zero, "Demo App");
if (handle != IntPtr.Zero)
{
SetForegroundWindow(handle);
ShowWindow(handle, 3);
}
}
}
有什么好的建议吗?非常感谢。
【问题讨论】: