日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當(dāng)前位置: 首頁 > 人文社科 > 生活经验 >内容正文

生活经验

一个鼠标类( Using C# and Win32API)

發(fā)布時(shí)間:2023/11/27 生活经验 31 豆豆
生活随笔 收集整理的這篇文章主要介紹了 一个鼠标类( Using C# and Win32API) 小編覺得挺不錯(cuò)的,現(xiàn)在分享給大家,幫大家做個(gè)參考.
作者:網(wǎng)際浪子 ??????出處:網(wǎng)絡(luò)


namespace ClassLibrary.Hardware
{
// 原創(chuàng) Using C# and Win32API ( 最近我把所有的Win32API看了1遍 很是過癮 )

public class Mouse
{
 internal const byte SM_MOUSEPRESENT = 19;
 internal const byte SM_CMOUSEBUTTONS = 43;
 internal const byte SM_MOUSEWHEELPRESENT = 75;

 internal struct POINTAPI
 {
  internal int x;
  internal int y;
 }

 internal struct RECT
 {
  internal int left ;
  internal int top ;
  internal int right ;
  internal int bottom ;
 }

 [System.Runtime.InteropServices.DllImport("user32.dll" , EntryPoint="SwapMouseButton")]
 internal extern static int SwapMouseButton ( int bSwap );

 [System.Runtime.InteropServices.DllImport("user32" , EntryPoint="ClipCursor")]
 internal extern static int ClipCursor(ref RECT lpRect);

 [System.Runtime.InteropServices.DllImport( "user32.dll" , EntryPoint="GetCursorPos" )]
 internal extern static int GetCursorPos( ref POINTAPI lpPoint );

 [System.Runtime.InteropServices.DllImport("user32.dll", EntryPoint="ShowCursor")]
 internal extern static bool ShowCursor ( bool bShow ) ;

 [System.Runtime.InteropServices.DllImport( "user32.dll" , EntryPoint = "EnableWindow" )]
 internal extern static int EnableWindow( int hwnd , int fEnable );

 [System.Runtime.InteropServices.DllImport("user32.dll" , EntryPoint="GetWindowRect")] 
 internal extern static int GetWindowRect( int hwnd , ref RECT lpRect ) ;

 [System.Runtime.InteropServices.DllImport("user32.dll" , EntryPoint="SetCursorPos")] 
 internal extern static int SetCursorPos ( int x , int y ) ;

 [System.Runtime.InteropServices.DllImport("user32.dll" , EntryPoint="GetSystemMetrics")]
 internal extern static int GetSystemMetrics( int nIndex );

 [System.Runtime.InteropServices.DllImport("user32.dll" , EntryPoint="SetDoubleClickTime")]
 internal extern static int SetDoubleClickTime ( int wCount );

 [System.Runtime.InteropServices.DllImport("user32.dll" , EntryPoint="GetDoubleClickTime")]
 internal extern static int GetDoubleClickTime() ;

 [System.Runtime.InteropServices.DllImport("kernel32.DLL", EntryPoint="Sleep")]
 internal extern static void Sleep ( int dwMilliseconds ) ;

 //得到鼠標(biāo)相對(duì)與全屏的坐標(biāo),不是相對(duì)與你的Form的,且與你的分辨率有關(guān)系

 public static int FullScreenPosition_X
 {
  get
  {
  POINTAPI _POINTAPI = new POINTAPI();

  GetCursorPos ( ref _POINTAPI );
  
  return _POINTAPI.x;
  }
 }
 
 public static int FullScreenPosition_Y
 {
  get
  {
  POINTAPI _POINTAPI = new POINTAPI();

  GetCursorPos ( ref _POINTAPI );
  
  return _POINTAPI.y;
  }
 }

 // 隱藏 顯示 鼠標(biāo)

 public static void Hide()
 {
  ShowCursor( false ) ;
 }
 
 public static void Show()
 {
  ShowCursor( true ) ;
 }

 // 將鼠標(biāo)鎖定在你的Form里 不過你得將你的Form先鎖了,Form Resize 就失效了

 public static void Lock( System.Windows.Forms.Form ObjectForm )
 {
  RECT _FormRect = new RECT ();
 
  GetWindowRect( ObjectForm.Handle.ToInt32() , ref _FormRect );
 
  ClipCursor( ref _FormRect );
 }
 
 public static void UnLock()
 {
  RECT _ScreenRect = new RECT ();
 
  _ScreenRect.top = 0;
  _ScreenRect.left = 0;
  _ScreenRect.bottom = System.Windows.Forms.Screen.PrimaryScreen.WorkingArea.Bottom;
  _ScreenRect.right = System.Windows.Forms.Screen.PrimaryScreen.WorkingArea.Right;
  
  ClipCursor( ref _ScreenRect );
 }

 // 鼠標(biāo)失效,不過失效的好像不只是鼠標(biāo),小心哦

 public static void Disable( System.Windows.Forms.Form ObjectForm )
 {
  EnableWindow( ObjectForm.Handle.ToInt32() , 0 ) ;
 }

 public static void Enable( System.Windows.Forms.Form ObjectForm )
 {
  EnableWindow( ObjectForm.Handle.ToInt32() , 1 ) ;
 }

 // 鼠標(biāo)自己移動(dòng) 很想動(dòng)畫哦 參數(shù)是2個(gè)控件的handle
 // 看這個(gè)方法前,先用涼水擦把臉。。。 反正我寫的時(shí)候 頭暈

 public static void Move ( int From_Handle_ToInt32 , int To_Handle_ToInt32 )
 {
  RECT rectFrom = new RECT () ;
  RECT rectTo = new RECT () ;
  
  int i ;
 
  GetWindowRect( From_Handle_ToInt32 , ref rectFrom ) ;
  GetWindowRect( To_Handle_ToInt32 , ref rectTo ) ;

  if ( ( rectFrom.left + rectFrom.right ) / 2 - ( rectTo.left + rectTo.right ) / 2 > 0 )
  {
  for ( i = ( rectFrom.left + rectFrom.right ) / 2 ; i >= ( rectTo.left + rectTo.right ) / 2 ; i-- )
  {
   SetCursorPos ( i , ( rectFrom.top + rectFrom.bottom ) / 2) ;
   Sleep ( 1 ) ;
  }
  }
  else
  {
  for ( i = ( rectFrom.left + rectFrom.right ) / 2 ; i <= ( rectTo.left + rectTo.right ) / 2 ; i++ )
  {
   SetCursorPos ( i , ( rectFrom.top + rectFrom.bottom ) / 2) ;
   Sleep ( 1 ) ;
  }
  }

  if ( ( rectFrom.top + rectFrom.bottom ) / 2 - ( rectTo.top + rectTo.bottom ) / 2 > 0 )
  {
  for ( i = ( rectFrom.top + rectFrom.bottom ) / 2 ; i >= ( rectTo.top + rectTo.bottom ) / 2 ; i-- )
  {
   SetCursorPos ( ( rectTo.left + rectTo.right ) / 2 , i ) ;
   Sleep ( 1 ) ;
  }
  }
  else
  {
  for ( i = ( rectFrom.top + rectFrom.bottom ) / 2 ; i <= ( rectTo.top + rectTo.bottom ) / 2 ; i++ )
  {
   SetCursorPos ( ( rectTo.left + rectTo.right ) / 2 , i ) ;
   Sleep ( 1 ) ;
  }
  }
 }
 
 // 得到你的鼠標(biāo)類型

 public static string Type
 {
  get
  {
  if ( GetSystemMetrics( SM_MOUSEPRESENT ) == 0 )
  {
   return "本計(jì)算機(jī)尚未安裝鼠標(biāo)" ;
  }
  else
  {
   if ( GetSystemMetrics( SM_MOUSEWHEELPRESENT ) != 0 )
   {
   return GetSystemMetrics( SM_CMOUSEBUTTONS ) + "鍵滾輪鼠標(biāo)" ;
   }
   else
   {
   return GetSystemMetrics( SM_CMOUSEBUTTONS ) + "鍵鼠標(biāo)" ;
   }
  }
  }
 }

 // 設(shè)置鼠標(biāo)雙擊時(shí)間
 
 public static void DoubleClickTime_Set( int MouseDoubleClickTime )
 {
  SetDoubleClickTime( MouseDoubleClickTime );
 }
 
 public static string DoubleClickTime_Get()
 {
  return GetDoubleClickTime().ToString() ;
 }

 // 設(shè)置鼠標(biāo)默認(rèn)主鍵 我是沒有見過誰左手用鼠標(biāo)

 public static void DefaultRightButton()
 {
  SwapMouseButton ( 1 ) ;
 }
 
 public static void DefaultLeftButton()
 {
  SwapMouseButton ( 0 ) ;
 }
}
}

總結(jié)

以上是生活随笔為你收集整理的一个鼠标类( Using C# and Win32API)的全部內(nèi)容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網(wǎng)站內(nèi)容還不錯(cuò),歡迎將生活随笔推薦給好友。

主站蜘蛛池模板: 国产精品国产三级国产三级人妇 | 国产一级片免费在线观看 | 福利毛片| 中文字幕线人 | 国产成人一区二区三区 | 一区二区三区日韩 | 91精品国产91久久久久久久久久久久 | 饥渴少妇勾引水电工av | 一区二区不卡免费视频 | 亚洲色图网友自拍 | 欧美专区在线视频 | 欧美一二三 | 中国毛片视频 | 成人免费看片98欧美 | 国产一级二级视频 | 国产欧美又粗又猛又爽 | 手机在线观看毛片 | 国产午夜精品免费一区二区三区视频 | 日韩视频一区二区三区在线播放免费观看 | 天堂√| 久久久久亚洲av无码专区首jn | 欧美一区二区三区在线视频 | 熟女丝袜一区 | 三级91 | 男女免费网站 | 99自拍视频在线观看 | 亚洲成人二区 | 亚洲视频不卡 | 九九精品视频免费 | 无码久久精品国产亚洲av影片 | 一区精品视频在线观看 | 都市激情亚洲综合 | 天天插伊人 | 欧洲一级片 | 亚洲最黄网站 | 色哟哟欧美精品 | 蜜桃av噜噜一区二区三区麻豆 | 99久久久无码国产精品性波多 | 欧美一区二区三区视频在线 | 欧美午夜精品久久久久久浪潮 | 男人的亚洲天堂 | 日韩精品人妻一区二区中文字幕 | 天天爽天天摸 | 免费人成在线观看网站 | 亚洲拍拍视频 | 91在线视频国产 | 久久成人视屏 | 小视频在线看 | 亚洲国产精品18久久久久久 | 九九热最新| 男女草逼网站 | 女同动漫免费观看高清完整版在线观看 | 性欧美极品另类 | 少妇无套内谢免费视频 | 欧美大肥婆大肥bbbbb | 97se综合 | 欧美人妻一区二区 | 91国内精品久久久久 | 亚洲精品在线一区二区 | 日本欧美成人 | 亚洲综合五月天 | 日本乱码一区二区 | 玩偶姐姐在线观看免费 | 天堂在线观看视频 | 久久国产激情视频 | 日本人和亚洲人zjzjhd | 日韩高清一二三区 | 久久99精品久久只有精品 | 国产一级视频在线播放 | 日韩在线观看免费高清 | 人妻丰满熟妇av无码区 | 色图视频| 丝袜在线视频 | 欧美在线二区 | 青青久久久 | 精品日韩中文字幕 | 色宗合| 射进来av影视 | 亚洲欧洲日本精品 | 欧美一级黄色网 | 欧美黄页网站 | av夜夜操 | av资源免费 | 19韩国主播青草vip | 国产亚洲精品美女久久久久 | 五月天久久综合 | 息与子五十路翔田千里 | 三级网站在线播放 | 日韩欧美在线视频免费观看 | 中文字幕在线导航 | 国产一级不卡毛片 | 婷婷去俺也去 | 99在线精品免费视频 | 中文字幕精品三区 | 亚洲永久免费观看 | 天海翼一区二区三区 | 大肉大捧一进一出好爽动态图 | 日本一区二区高清不卡 | 久久网一区二区 |