C# 最小化或在后台运行时还原Windows 10计算器
我正在使用C#尝试在最小化或在后台运行时还原Windows 10计算器。我正在尝试以下代码,但它不起作用C# 最小化或在后台运行时还原Windows 10计算器,c#,restore,C#,Restore,我正在使用C#尝试在最小化或在后台运行时还原Windows 10计算器。我正在尝试以下代码,但它不起作用 if (calcrunning == true & calcresponding == false) { MessageBox.Show("Running but suspended or minimized "); //RunCalculator(); IntPtr calcwindo
if (calcrunning == true & calcresponding == false)
{
MessageBox.Show("Running but suspended or minimized ");
//RunCalculator();
IntPtr calcwindow = FindWindowByCaption(IntPtr.Zero, "Calculator");
//ResumeProcess(calcwindow.Handle);
//ShowWindow(calcwindow, SW_MINIMIZE);
//ResumeThread(calcwindow);
//calc.Start();
ShowWindow(calcwindow, SW_SHOW);
ShowWindow(calcwindow, SW_RESTORE);
SetForegroundWindow(calcwindow);
}
[DllImport("user32.dll")]
private static extern bool SetForegroundWindow(IntPtr hWnd);
[DllImport("user32.dll", EntryPoint = "FindWindow", SetLastError = true)]
static extern IntPtr FindWindowByCaption(IntPtr ZeroOnly, string lpWindowName);
[DllImport("user32.dll")]
[return: MarshalAs(UnmanagedType.Bool)]
static extern bool ShowWindow(IntPtr hWnd, uint nCmdShow);
[DllImport("kernel32.dll")]
static extern int ResumeThread(IntPtr hThread);
有什么想法吗?SetForegroundWindow仅在未最小化计算器时有效。它失败是因为它是一款现代应用程序吗?UWP的应用程序生命周期非常清楚挂起状态。在桌面系列中,UWP应用程序在最小化或Windows进入低功耗状态时暂停 一个微软正在倾听建议的地方。强烈建议您投票表决。文档非常清楚地说明了使用限制。一般来说,您不能将任意窗口放在前面。添加以下内容:
[DllImport("user32.dll")]
private static extern bool ShowWindowAsync(IntPtr hWnd, int nCmdShow);
SetForegroundWindow(calcwindow);
ShowWindowAsync(calcwindow, SW_SHOWNORMAL);
它把它放在前台,即使它被最小化