110,499
社区成员
发帖
与我相关
我的任务
分享
[System.Runtime.InteropServices.DllImport("user32.dll")]
private static extern IntPtr FindWindow(string strclassName, string strWindowName);
[System.Runtime.InteropServices.DllImport("user32.dll")]
private static extern bool OpenIcon(IntPtr hWnd);
[System.Runtime.InteropServices.DllImport("user32.dll")]
private static extern bool IsIconic(IntPtr hWnd);
[System.Runtime.InteropServices.DllImport("user32.dll")]
private static extern int SetForegroundWindow(IntPtr hWnd);
void FindAndOpenWindow(string Title)
{
IntPtr hWnd = (IntPtr ) FindWindow(null, Title);
if (hWnd != IntPtr.Zero)
{
bool isIcon = IsIconic(hWnd);
if ( !isIcon )
{
SetForegroundWindow(hWnd);
}
else
{
OpenIcon(hWnd);
}
}
}