码迷,mamicode.com
首页 > Windows程序 > 详细

C#打开任务栏程序窗口

时间:2014-10-16 02:19:21      阅读:332      评论:0      收藏:0      [点我收藏+]

标签:c#   .net   打开任务栏程序窗口   显示任务栏程序窗口   

本例实现使用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);
        }
    }


C#打开任务栏程序窗口

标签:c#   .net   打开任务栏程序窗口   显示任务栏程序窗口   

原文地址:http://blog.csdn.net/studentsky/article/details/40123709

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!