C限制鼠標移動范圍_第1頁
C限制鼠標移動范圍_第2頁
C限制鼠標移動范圍_第3頁
C限制鼠標移動范圍_第4頁
C限制鼠標移動范圍_第5頁
全文預(yù)覽已結(jié)束

下載本文檔

版權(quán)說明:本文檔由用戶提供并上傳,收益歸屬內(nèi)容提供方,若內(nèi)容存在侵權(quán),請進行舉報或認領(lǐng)

文檔簡介

1、1 一個鼠標類#region 一個鼠標類     2    /*/ <summary>  3    / Mouse Control  4    / Made by Michael  5    / date 2008-0

2、1-30  6    / </summary>  7    class Mouse  8      9        internal const byte SM_MOUSEPRESENT = 19; 10  

3、;      internal const byte SM_CMOUSEBUTTONS = 43; 11        internal const byte SM_MOUSEWHEELPRESENT = 75; 12 13        inter

4、nal struct POINTAPI 14         15            internal int x; 16            internal int y; 

5、;17         18 19        internal struct RECT 20         21            internal int&#

6、160;left; 22            internal int top; 23            internal int right; 24           &

7、#160;internal int bottom; 25         26 27        System.Runtime.InteropServices.DllImport("user32.dll", EntryPoint = "SwapMouseButton") 28  

8、0;     internal extern static int SwapMouseButton(int bSwap); 29 30        System.Runtime.InteropServices.DllImport("user32", EntryPoint = "ClipCursor") 31 

9、;       internal extern static int ClipCursor(ref   RECT lpRect); 32 33        System.Runtime.InteropServices.DllImport("user32.dll", EntryPoint = &qu

10、ot;GetCursorPos") 34        internal extern static int GetCursorPos(ref   POINTAPI lpPoint); 35 36        System.Runtime.InteropServices.DllImport("user32.

11、dll", EntryPoint = "ShowCursor") 37        internal extern static bool ShowCursor(bool bShow); 38 39        System.Runtime.InteropServices.DllImport(&

12、quot;user32.dll", EntryPoint = "EnableWindow") 40        internal extern static int EnableWindow(int hwnd, int fEnable); 41 42        System

13、.Runtime.InteropServices.DllImport("user32.dll", EntryPoint = "GetWindowRect") 43        internal extern static int GetWindowRect(int hwnd, ref   RECT lpRect); 44

14、60;45        System.Runtime.InteropServices.DllImport("user32.dll", EntryPoint = "SetCursorPos") 46        internal extern static int SetCursorPos(int x,&#

15、160;int y); 47 48        System.Runtime.InteropServices.DllImport("user32.dll", EntryPoint = "GetSystemMetrics") 49        internal extern static int&

16、#160;GetSystemMetrics(int nIndex); 50 51        System.Runtime.InteropServices.DllImport("user32.dll", EntryPoint = "SetDoubleClickTime") 52        internal ext

17、ern static int SetDoubleClickTime(int wCount); 53 54        System.Runtime.InteropServices.DllImport("user32.dll", EntryPoint = "GetDoubleClickTime") 55      &#

18、160; internal extern static int GetDoubleClickTime(); 56 57        System.Runtime.InteropServices.DllImport("kernel32.DLL", EntryPoint = "Sleep") 58      &

19、#160; internal extern static void Sleep(int dwMilliseconds); 59 60        /得到鼠標相對與全屏的坐標,不是相對與你的Form的,且與你的分辨率有關(guān)系   61 62        public static int 

20、FullScreenPosition_X 63         64            get 65             66         

21、;       POINTAPI _POINTAPI = new POINTAPI(); 67 68                GetCursorPos(ref   _POINTAPI); 69 70    

22、0;           return _POINTAPI.x; 71             72         73 74        public&#

23、160;static int FullScreenPosition_Y 75         76            get 77             78    

24、0;           POINTAPI _POINTAPI = new POINTAPI(); 79 80                GetCursorPos(ref   _POINTAPI); 81 82

25、60;               return _POINTAPI.y; 83             84         85 86     &

26、#160;  /隱藏 顯示 鼠標   87        public static void Hide() 88         89            ShowCursor(false);&#

27、160;90         91 92        public static void Show() 93         94            ShowCu

28、rsor(true); 95         96 97        /將鼠標鎖定在你的Form里   不過你得將你的Form先鎖了,Form   Resize   就失效了  98        public

29、0;static void Lock(System.Windows.Forms.Form ObjectForm) 99        100            RECT _FormRect = new RECT();101102       &#

30、160;    GetWindowRect(ObjectForm.Handle.ToInt32(), ref   _FormRect);103104            ClipCursor(ref   _FormRect);105        106107  &#

31、160;     public static void UnLock()108        109            RECT _ScreenRect = new RECT();110111       

32、     _ScreenRect.top = 0;112            _ScreenRect.left = 0;113            _ScreenRect.bottom = System.Windows.Forms.Screen.

33、PrimaryScreen.WorkingArea.Bottom;114            _ScreenRect.right = System.Windows.Forms.Screen.PrimaryScreen.WorkingArea.Right;115116            ClipCursor(ref 

34、0; _ScreenRect);117        118119        /鼠標失效,不過失效的好像不只是鼠標,小心哦 120        public static void Disable(System.Windows.Forms.Form ObjectForm)121 &#

35、160;      122            EnableWindow(ObjectForm.Handle.ToInt32(), 0);123        124125        public static void&#

36、160;Enable(System.Windows.Forms.Form ObjectForm)126        127            EnableWindow(ObjectForm.Handle.ToInt32(), 1);128        129   

37、;     /   得到你的鼠標類型  130        public static string Type131        132            get133 &

38、#160;          134                if (GetSystemMetrics(SM_MOUSEPRESENT) = 0)135            

39、0;   136                    return "本計算機尚未安裝鼠標"137                138   

40、60;            else139                140                    

41、;if (GetSystemMetrics(SM_MOUSEWHEELPRESENT) != 0)141                    142                  &#

42、160;     return GetSystemMetrics(SM_CMOUSEBUTTONS) + "鍵滾輪鼠標"143                    144          

43、0;         else145                    146                   

44、     return GetSystemMetrics(SM_CMOUSEBUTTONS) + "鍵鼠標"147                    148           

45、0;    149            150        151152        /   設(shè)置鼠標雙擊時間153        public static void DoubleClickTime_Set(int MouseDoubleClickTime)154        155   

溫馨提示

  • 1. 本站所有資源如無特殊說明,都需要本地電腦安裝OFFICE2007和PDF閱讀器。圖紙軟件為CAD,CAXA,PROE,UG,SolidWorks等.壓縮文件請下載最新的WinRAR軟件解壓。
  • 2. 本站的文檔不包含任何第三方提供的附件圖紙等,如果需要附件,請聯(lián)系上傳者。文件的所有權(quán)益歸上傳用戶所有。
  • 3. 本站RAR壓縮包中若帶圖紙,網(wǎng)頁內(nèi)容里面會有圖紙預(yù)覽,若沒有圖紙預(yù)覽就沒有圖紙。
  • 4. 未經(jīng)權(quán)益所有人同意不得將文件中的內(nèi)容挪作商業(yè)或盈利用途。
  • 5. 人人文庫網(wǎng)僅提供信息存儲空間,僅對用戶上傳內(nèi)容的表現(xiàn)方式做保護處理,對用戶上傳分享的文檔內(nèi)容本身不做任何修改或編輯,并不能對任何下載內(nèi)容負責。
  • 6. 下載文件中如有侵權(quán)或不適當內(nèi)容,請與我們聯(lián)系,我們立即糾正。
  • 7. 本站不保證下載資源的準確性、安全性和完整性, 同時也不承擔用戶因使用這些下載資源對自己和他人造成任何形式的傷害或損失。

評論

0/150

提交評論