程序師世界是廣大編程愛好者互助、分享、學習的平台,程序師世界有你更精彩!
首頁
編程語言
C語言|JAVA編程
Python編程
網頁編程
ASP編程|PHP編程
JSP編程
數據庫知識
MYSQL數據庫|SqlServer數據庫
Oracle數據庫|DB2數據庫
 程式師世界 >> 編程語言 >> .NET網頁編程 >> C# >> C#入門知識 >> Api代碼收集

Api代碼收集

編輯:C#入門知識

收集自網絡,方便自己,方便他人 

 1     #region 隱藏系統滾動條
 2     protected override void WndProc(ref System.Windows.Forms.Message m)
 3     {
 4       ShowScrollBar(this.Handle, 3, false);//0:horizontal,1:vertical,3:both
 5       base.WndProc(ref m);
 6     }
 7 
 8     [DllImport("user32.dll")]
 9     [return: MarshalAs(UnmanagedType.Bool)]
10     private static extern bool ShowScrollBar(IntPtr hWnd, int wBar, bool bShow);
11     #endregion

 

 1     #region 得到光標在屏幕上的位置
 2    [DllImport("user32")]
 3     public static extern bool GetCaretPos(out Point lpPoint);
 4     [DllImport("user32.dll")]
 5     private static extern IntPtr GetForegroundWindow();
 6     [DllImport("user32.dll")]
 7     private static extern IntPtr GetFocus();
 8     [DllImport("user32.dll")]
 9     private static extern IntPtr AttachThreadInput(IntPtr idAttach, IntPtr idAttachTo, int fAttach);
10     [DllImport("user32.dll")]
11     private static extern IntPtr GetWindowThreadProcessId(IntPtr hWnd, IntPtr ProcessId);
12     [DllImport("kernel32.dll")]
13     private static extern IntPtr GetCurrentThreadId();
14     [DllImport("user32.dll")]
15     private static extern void ClientToScreen(IntPtr hWnd, ref Point p);
16 
17     private Point CaretPos()
18     {
19         IntPtr ptr = GetForegroundWindow();
20         Point p = new Point();
21 
22         //得到Caret在屏幕上的位置   
23       if (ptr.ToInt32() != 0)
24         {
25             IntPtr targetThreadID = GetWindowThreadProcessId(ptr, IntPtr.Zero);
26             IntPtr localThreadID = GetCurrentThreadId();
27 
28             if (localThreadID != targetThreadID)
29             {
30                 AttachThreadInput(localThreadID, targetThreadID, 1);
31                 ptr = GetFocus();
32                 if (ptr.ToInt32() != 0)
33                 {
34                     GetCaretPos(out   p);
35                     ClientToScreen(ptr, ref   p);
36                 }
37                 AttachThreadInput(localThreadID, targetThreadID, 0);
38             }
39         }
40         return p;
41     }
42     #endregion

 

  1. 上一頁:
  2. 下一頁:
Copyright © 程式師世界 All Rights Reserved