tangxu
2024-10-22 7a0d1efa4784d176a32f182ecae671711e98ca92
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
#region Imports
 
using System;
using System.Runtime.InteropServices;
using System.Security;
 
#endregion
 
namespace DPumpHydr.WinFrmUI.RLT.Native
{
    #region WinCaretNative
 
    [SuppressUnmanagedCodeSecurity]
    internal sealed class WinCaret
    {
        [DllImport("User32.dll")]
        private static extern bool CreateCaret(IntPtr hWnd, int hBitmap, int nWidth, int nHeight);
 
        [DllImport("User32.dll")]
        private static extern bool SetCaretPos(int x, int y);
 
        [DllImport("User32.dll")]
        private static extern bool DestroyCaret();
 
        [DllImport("User32.dll")]
        private static extern bool ShowCaret(IntPtr hWnd);
 
        [DllImport("User32.dll")]
        public static extern bool HideCaret(IntPtr hWnd);
 
        private readonly IntPtr controlHandle;
 
        public WinCaret(IntPtr ownerHandle)
        {
            controlHandle = ownerHandle;
        }
 
        public bool Create(int width, int height)
        {
            return CreateCaret(controlHandle, 0, width, height);
        }
        public void Hide()
        {
            HideCaret(controlHandle);
        }
        public void Show()
        {
            ShowCaret(controlHandle);
        }
        public static bool SetPosition(int x, int y)
        {
            return SetCaretPos(x, y);
        }
        public static void Destroy()
        {
            DestroyCaret();
        }
    }
 
    #endregion
}