屏幕截图应用程序(由GuyThiebaut从TeboScreen派生而来)

下载ScreenCapSetup - 37.52 KB 介绍 这个应用程序在后台运行,并接管打印屏幕按钮,允许以两种不同的方式捕捉屏幕: 捕捉屏幕:这是它所说的;它基本上会捕捉整个屏幕。捕获区域:按住鼠标左键,用户绘制一个矩形,指定希望捕获屏幕的哪一部分。用户可以选择三种方法中的一种来发送绘制矩形后面的区域(剪贴板、打印机、电子邮件)。一旦绘制完毕,矩形可以在将图像发送到所需目的地之前调整大小并在屏幕上移动。 背景 我的雇主最近从一个遗留的Telnet应用程序迁移到了一个Windows应用程序。legacy应用程序允许用户点击打印屏幕按钮,将他们

  

的会话屏幕发送到打印机。我们的许多用户都不是经验丰富的Windows用户,因此他们有必要能够轻松地捕获屏幕并将其发送到打印机,而不必破坏Windows环境。 在互联网上搜索了一些好的屏幕捕捉程序来完成这一任务后,我们发现大多数程序都很弱,而且代价昂贵。我知道这个项目应该不会给我带来太多麻烦;因此,我开始寻找一些开源软件来帮助我快速完成任务,并在代码项目TeboScreen上遇到了GuyThiebaut的“TeboScreen”应用程序 使用的代码 为了增强原始的TeboScreen,我关注了几件事: 在后台运行,并被激活时,打印屏幕按钮被按下支持双显示器,无论显示器是否有大小差异,自动发送屏幕捕获到三个设备:剪贴板,打印机,电子邮件的使用方便的最终用户 考虑到这一点,我将不再讨论原始项目中涉及的冗余细节。 运行在后台 我们所需要做的就是为主窗体所显示的事件添加一个处理程序: 隐藏,复制Code

private void ControlPanel_Shown(object sender, EventArgs e)
{
 this.Hide();
}

处理打印屏幕按钮 这需要根据这个讨论关键字编写一个程序集。 隐藏,收缩,复制Code

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Runtime.InteropServices;
using System.ComponentModel;
using System.Reflection;

namespace KeyHook
{
    public class KeyHooker
    {
        public static event EventHandler PrintScreenBtnEvent = null;

        [StructLayout(LayoutKind.Sequential)]
        public struct KBDLLHOOKSTRUCT
        {
            public int vkCode;
            public int scanCode;
            public int flags;
            public int time;

            public int extraInfo;
        }

        public delegate int HookProc(int nCode, int wParam, IntPtr ptrKBDLLHOOKSTRUCT);

        [DllImport("user32.dll", CharSet = CharSet.Auto, 
         CallingConvention = CallingConvention.StdCall, SetLastError = true)]
        public static extern IntPtr SetWindowsHookEx
        (int idHook, HookProc callBack, IntPtr hMod, int threadId);

        [DllImport("user32.dll", CharSet = CharSet.Auto, 
         CallingConvention = CallingConvention.StdCall, SetLastError = true)]
        public static extern int CallNextHookEx(IntPtr hhk, int nCode, int wParam, IntPtr lParam);

        private static IntPtr kbh_Handle;
        private static HookProc kbh_HookProc;

        private const int VK_SNAPSHOT = 0x2C;
        private const int WM_KEYDOWN = 0x0100;
        private const int WM_SYSKEYDOWN = 0x0104;
        private const int WH_KEYBOARD_LL = 13;

        private static int LowLevelKeyboardProc(int nCode, int wParam, IntPtr lParam)
        {
            if (nCode < 0)
            {
                CallNextHookEx(kbh_Handle, nCode, wParam, lParam);
                return 0;
            }

            if (wParam == WM_KEYDOWN)
            {
                IntPtr kbdll = lParam;
                KBDLLHOOKSTRUCT kbdllstruct = 
                    (KBDLLHOOKSTRUCT)Marshal.PtrToStructure(kbdll, typeof(KBDLLHOOKSTRUCT));

                if (kbdllstruct.vkCode == VK_SNAPSHOT)
                {
                    if (PrintScreenBtnEvent != null)
                        PrintScreenBtnEvent(null, new EventArgs());

                    return -1;
                }
            }

            return CallNextHookEx(kbh_Handle, nCode, wParam, lParam);
        }

        public static void HookKeyboard()
        {
            try
            {
                kbh_HookProc = LowLevelKeyboardProc;

                kbh_Handle = SetWindowsHookEx(WH_KEYBOARD_LL, kbh_HookProc, 
                   Marshal.GetHINSTANCE(Assembly.GetExecutingAssembly().GetModules()[0]), 0);

                if (kbh_Handle == IntPtr.Zero)
                {
                    throw new Win32Exception(Marshal.GetLastWin32Error());
                }
            }
            catch (Exception ex)
            {
                System.Diagnostics.Debug.WriteLine(String.Format("ERROR: {0}", ex.Message));
            }
        }
    }
}

为了实现这个,我添加了一个委托到KeyHooker类: 隐藏,复制Code

public static event EventHandler PrintScreenBtnEvent = null;

双显示器支持 为此,我必须查看System.Windows.Forms。屏幕类。下面是用于存储主监视器索引的代码片段。主监视器是TeboScreen应用程序所基于的,因此这个项目中主监视器的任何代码都是相同的。如果正在处理的监视器不是主监视器,我必须对代码进行调整。 隐藏,复制Code

private int GetPrimaryMonIdx()
{
    Screen[] sc;
        sc = Screen.AllScreens;
        int idx = 0;

        foreach (Screen s in sc)
        {
            if (s.Bounds.Left == System.Windows.Forms.Screen.PrimaryScreen.Bounds.Left)
                    break;
                else
                    idx++;
        }

    return (idx <= sc.Length) ? idx : 0;
}

退出程序 当主屏幕(从上面的屏幕截图)显示并有焦点时,按Ctrl-Alt-S,然后按X。 本文转载于:http://www.diyabc.com/frontweb/news176.html

原文地址:https://www.cnblogs.com/Dincat/p/13431015.html