首页 > Windows开发 > 详细

C#打开任务栏程序窗口

时间:2014-10-16 00:20:32      阅读:371      评论:0      收藏:0      [点我收藏+]

本例实现使用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#打开任务栏程序窗口

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

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!