本例实现使用C#打开在Windows任务栏显示的某个窗口。
实验环境:
WindowsXP + VS2005 + .Net 2.0 + Winform测试程序。
注意:需要建立Winform程序进行测试。
代码:(转载请注明出处 http://blog.csdn.net/studentsky)
public partial class Form1 : Form { private const int SW_HIDE = 0; private const int SW_NORMAL = 1; private const int SW_MAXIMIZE = 3; private const int SW_SHOWNOACTIVATE = 4; private const int SW_SHOW = 5; private const int SW_MINIMIZE = 6; private const int SW_RESTORE = 9; private const int SW_SHOWDEFAULT = 10; [System.Runtime.InteropServices.DllImport("user32.dll", EntryPoint = "ShowWindow", SetLastError = true)] static extern bool ShowWindow(IntPtr hWnd, uint nCmdShow); /// <summary> /// 根据窗口标题查找窗体 /// </summary> /// <param name="lpClassName"></param> /// <param name="lpWindowName"></param> /// <returns></returns> [System.Runtime.InteropServices.DllImport("user32.dll", EntryPoint = "FindWindow")] private static extern IntPtr FindWindow(string lpClassName, string lpWindowName); public Form1() { InitializeComponent(); } private void button1_Click(object sender, EventArgs e) { IntPtr hWnd = FindWindow(null, "无标题 - 记事本"); ShowWindow(hWnd, SW_MAXIMIZE); } }
时间: 2024-10-04 11:58:00