如何获到其它进程鼠标选中的文字
2013-07-02 15:02
260 查看
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); } } }
相关文章推荐
- 如何获到其它进程鼠标选中的文字
- 如何获取鼠标选中的文字
- 如何获取页面上鼠标选中的文字
- 如何设置其它进程中listctrl控件CHECKBOX的选中状态
- 如何让鼠标移入div不选中div中的文字,鼠标也改变样式
- html body标签的几个属性 禁用鼠标右键,禁用鼠标选中文字等
- [转]当鼠标点击ListView下面的空白区域时,如何使ListView的原item选项仍然为选中状态
- 如何使鼠标单击ITEM单元格时黑色选中色变为其他颜色?
- DX,DevExpress中的RichEditControl如何替换选中的文字
- IE浏览器控件页面如何在选中的文本框输入焦点输入文字
- 获取鼠标选中文字 MFC
- 鼠标滑过选中文字
- 用css改变鼠标选中文字的样式
- html 在一个超链接上面,鼠标移动上去时,也显示一串文字,如何实现
- (vb6小技巧)鼠标在文本框一按下就选中所有文字
- 禁止鼠标多次点击选中div中的文字
- 鼠标选中的文字分享到微博
- 新浪微博插入话题后部分文字选中的js实现(控制鼠标指针位置/自动选择指定文本)
- Xshell用鼠标选中一段文字后自动换行的问题
- 如何得到其它进程的启动命令行参数