1. 程式人生 > >C 利用鉤子控制滑鼠【月兒原創】

C 利用鉤子控制滑鼠【月兒原創】

C#利用鉤子控制滑鼠

作者:清清月兒

主頁:http://blog.csdn.net/21aspnet/           時間:2007.5.11

工作中有這樣的需求,某個控制元件panel的子控制元件textbox要實現只留滑鼠右鍵copy,注意同時還不能影響其它panel的子控制元件textbox,怎麼辦?
答案是隻有用鉤子,在codeporject上找到這麼一個鉤子。

如圖所示,第一個文字框只有copy功能。


UserActivityHook.cs

 

using  System;
using  System.Runtime.InteropServices;
using  System.Reflection;
using  System.Threading;
using  System.Windows.Forms;
using  System.ComponentModel;

namespace  gma.System.Windows
{
 
/// <summary>

 
/// This class allows you to tap keyboard and mouse and / or to detect their activity even when an 
 
/// application runes in background or does not have any user interface at all. This class raises 
 
/// common .NET events with KeyEventArgs and MouseEventArgs so you can easily retrieve any information you need.
 
/// </summary>

 public class UserActivityHook
 
{
  
Windows structure definitions

  
Windows function imports