[DllImport("user32.dll", EntryPoint="FindWindow")]
public static extern int FindWindow (
string lpClassName,
string lpWindowName
);[DllImport("user32.dll", EntryPoint="SetForegroundWindow")]
public static extern int SetForegroundWindow (
int hwnd
);
void btn_click(object sender, EventArgs e)
{
int hwnd = FindWindow(null, "我的电脑");
SetForegroundWindow(hwnd);
}
public static extern int FindWindow (
string lpClassName,
string lpWindowName
);[DllImport("user32.dll", EntryPoint="SetForegroundWindow")]
public static extern int SetForegroundWindow (
int hwnd
);
void btn_click(object sender, EventArgs e)
{
int hwnd = FindWindow(null, "我的电脑");
SetForegroundWindow(hwnd);
}
[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 = FindWindow(null, Title);
if (hWnd != IntPtr.Zero)
{
bool isIcon = IsIconic(hWnd);
if ( !isIcon )
{
SetForegroundWindow(hWnd);
}
else
{
OpenIcon(hWnd);
}
}
}