Api代码收集_.NET_编程开发_程序员俱乐部

中国优秀的程序员网站程序员频道CXYCLUB技术地图
热搜:
更多>>
 
您所在的位置: 程序员俱乐部 > 编程开发 > .NET > Api代码收集

Api代码收集

 2014/5/20 11:09:43  KnightY  博客园  我要评论(0)
  • 摘要:收集自网络,方便自己,方便他人1#region隐藏系统滚动条2protectedoverridevoidWndProc(refSystem.Windows.Forms.Messagem)3{4ShowScrollBar(this.Handle,3,false);//0:horizontal,1:vertical,3:both5base.WndProc(refm);6}78[DllImport("user32.dll")]9[return:MarshalAs(UnmanagedType.Bool
  • 标签:API 代码

收集自网络,方便自己,方便他人 

 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

 

发表评论
用户名: 匿名