zoukankan      html  css  js  c++  java
  • 如何获到其它进程鼠标选中的文字

    using System;
    using System.Collections.Generic;
    using System.ComponentModel;
    using System.Data;
    using System.Drawing;
    using System.Text;
    using System.Windows.Forms;
    using System.Runtime.InteropServices;
    
    namespace WindowsApplication1
    {
        public enum ShellEvents
        {
            HSHELL_WINDOWCREATED = 1,
            HSHELL_WINDOWDESTROYED = 2,
            HSHELL_ACTIVATESHELLWINDOW = 3,
            HSHELL_WINDOWACTIVATED = 4,
            HSHELL_GETMINRECT = 5,
            HSHELL_REDRAW = 6,
            HSHELL_TASKMAN = 7,
            HSHELL_LANGUAGE = 8,
            HSHELL_ACCESSIBILITYSTATE = 11
        }
        public partial class Form1 : Form
        {
    
           
            [DllImport("user32.dll")]
            public static extern int RegisterWindowMessageA(string lpName);
    
            [DllImport("user32.dll")]
            public static extern int DeregisterShellHookWindow(IntPtr handle);
    
            [DllImport("user32.dll")]
            public static extern int RegisterShellHookWindow(IntPtr handle);
    
            [DllImport("user32.dll")]
            public static extern IntPtr GetForegroundWindow();
    
            [DllImport("user32.dll")]
            public static extern int SetForegroundWindow(IntPtr handle);
    
            private int uMsgNotify;
            public IntPtr lastWindows;
    
            public Form1()
            {
                InitializeComponent();
            }
    
            private void button3_Click(object sender, EventArgs e)
            {
                SetForegroundWindow(lastWindows);
                System.Threading.Thread.Sleep(100);
                SendKeys.Send("^c");
                System.Threading.Thread.Sleep(100);
    
                IDataObject oData = Clipboard.GetDataObject();
                if (oData.GetDataPresent(DataFormats.Text))
                    this.textBox1.Text = (String)oData.GetData(DataFormats.Text);
                else
                    this.textBox1.Text = "Not Data";
    
            }
    
            private void Form1_Load(object sender, EventArgs e)
            {
                this.TopMost = true;
                uMsgNotify = RegisterWindowMessageA("SHELLHOOK");
                RegisterShellHookWindow(this.Handle);
            }
    
            protected override void WndProc(ref Message m)
            {
                if (m.Msg == uMsgNotify)
                {
                    switch (m.WParam.ToInt32())
                    {
                        case (int)ShellEvents.HSHELL_WINDOWACTIVATED:
                            IntPtr current = GetForegroundWindow();
                            Console.WriteLine("window activated:" + current.ToString());
                            if (current != IntPtr.Zero && current != this.Handle)
                                lastWindows = current;
                            break;
                        default:
                            break;
                    }
                }
                base.WndProc(ref m);
            }
    
            private void Form1_FormClosed(object sender, FormClosedEventArgs e)
            {
                DeregisterShellHookWindow(this.Handle);
            }
        }
    
    }

  • 相关阅读:
    struts 中 s:iterator 使用注意事项
    redmine 2.5.2 安装后邮件无法发送
    yum提示another app is currently holding the yum lock;waiting for it to exit
    UVA 11809 Floating-Point Numbers
    UVA 1587 Box
    UVA 1583 Digit Generator
    UVA 340 Master-Mind Hints
    UVA 401 Palindromes
    UVA 11175 From D to E and Back
    洛谷P3916 图的遍历
  • 原文地址:https://www.cnblogs.com/whisht/p/3750126.html
Copyright © 2011-2022 走看看