Collect from the network to make it easy for others
1 # region hide the System scroll bar 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: financialas (UnmanagedType. bool)] 10 private static extern bool ShowScrollBar (IntPtr hWnd, int wBar, bool bShow); 11 # endregion
1 # region get the cursor position on the screen 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 ("u Ser32.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 = GetForegroundWindow (); 20 Point p = new Point (); 21 22 // get the position of Caret on the screen Set 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