C# 最小化时将窗口向前移动
我想知道如何提出一个特定的窗口。 SetForegroundWindow在窗口未最小化时工作!!但是当最小化窗口时,SetForeGroundIndow不起作用 这是我的代码:C# 最小化时将窗口向前移动,c#,window,foreground,C#,Window,Foreground,我想知道如何提出一个特定的窗口。 SetForegroundWindow在窗口未最小化时工作!!但是当最小化窗口时,SetForeGroundIndow不起作用 这是我的代码: int IdRemoto = int.Parse(textBoxID.Text); Process[] processlist = Process.GetProcessesByName("AA_v3.3"); foreach (Process process in pr
int IdRemoto = int.Parse(textBoxID.Text);
Process[] processlist = Process.GetProcessesByName("AA_v3.3");
foreach (Process process in processlist)
{
if (!String.IsNullOrEmpty(process.MainWindowTitle))
{
if (IdRemoto.ToString() == process.MainWindowTitle)
SetForegroundWindow(process.MainWindowHandle);
}
}
[DllImport("user32.dll")]
private static extern bool SetForegroundWindow(IntPtr hWnd);
您可以结合已有的内容使用,下面是您的示例,稍作修改:
int IdRemoto = int.Parse(textBoxID.Text);
Process[] processlist = Process.GetProcessesByName("AA_v3.3");
foreach (Process process in processlist)
{
if (!String.IsNullOrEmpty(process.MainWindowTitle))
{
if (IdRemoto.ToString() == process.MainWindowTitle)
{
ShowWindow(process.MainWindowHandle, 9);
SetForegroundWindow(process.MainWindowHandle);
}
}
}
[DllImport("user32.dll")]
private static extern bool SetForegroundWindow(IntPtr hWnd);
[DllImport("user32.dll")]
private static extern bool ShowWindow(IntPtr hWind, int nCmdShow);
您可以使用API检查窗口是否最小化,然后使用恢复窗口:
public const int SW_RESTORE = 9;
[DllImport("user32.dll")]
public static extern bool IsIconic(IntPtr handle);
[DllImport("user32.dll")]
public static extern bool ShowWindow(IntPtr handle, int nCmdShow);
[DllImport("user32.dll")]
public static extern int SetForegroundWindow(IntPtr handle);
private void BringToForeground(IntPtr extHandle)
{
if (IsIconic(extHandle))
{
ShowWindow(extHandle, SW_RESTORE);
}
SetForegroundWindow(extHandle);
}