用户注册



邮箱:

密码:

用户登录


邮箱:

密码:
记住登录一个月忘记密码?

发表随想


还能输入:200字
云代码 - c#代码库

Windows活动窗口截图

2016-08-14 作者: 小章举报

[c#]代码库

//Form1.cs

using System;
using System.Collections;
using System.Collections.Generic;
using System.Diagnostics;
using System.Runtime.InteropServices;
using System.Windows.Forms;

namespace WindowScreenshot
{
    public partial class Form1 : Form
    {
        Dictionary<int, string> Apps = null;
        List<int> pl = new List<int>();

        public Form1()
        {
            InitializeComponent();
        }

        [DllImport("User32.dll", EntryPoint = "FindWindow")]
        private static extern IntPtr FindWindow(string lpClassName, string lpWindowName);

        private void GetWindowScreenshotByName(PictureBox PB)
        {
            IntPtr handle = IntPtr.Zero;
            try
            {
                PB.Image = null;
                handle = new IntPtr(pl[comboBox1.SelectedIndex]);
                //handle = FindWindow(null, winTitle);
                PB.Image = PrtWnd.PrtWindow(handle);
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
            }
        }

        private void button1_Click(object sender, EventArgs e)
        {
            comboBox1.Items.Clear();
            pl.Clear();
            try
            {
                Apps = PrtWnd.FindAllApps(this.Handle.ToInt32());
                foreach (string app in Apps.Values)
                    comboBox1.Items.Add(app);
                pl.AddRange(Apps.Keys);
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
            }
        }

        private void comboBox1_SelectedIndexChanged(object sender, EventArgs e)
        {
            GetWindowScreenshotByName(pictureBox1);
        }

        private void Form1_Load(object sender, EventArgs e)
        {
            try
            {
                Apps = PrtWnd.FindAllApps(this.Handle.ToInt32());
                foreach (string app in Apps.Values)
                    comboBox1.Items.Add(app);
                pl.AddRange(Apps.Keys);
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
            }
        }
    }
}

[源代码打包下载]




网友评论    (发表评论)


发表评论:

评论须知:

  • 1、评论每次加2分,每天上限为30;
  • 2、请文明用语,共同创建干净的技术交流环境;
  • 3、若被发现提交非法信息,评论将会被删除,并且给予扣分处理,严重者给予封号处理;
  • 4、请勿发布广告信息或其他无关评论,否则将会删除评论并扣分,严重者给予封号处理。


扫码下载

加载中,请稍后...

输入口令后可复制整站源码

加载中,请稍后...