■ GetCursorPos API 함수를 선언하는 방법을 보여준다.
▶ 예제 코드 (C#)
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 |
using System.Runtime.InteropServices; #region 커서 위치 구하기 - GetCursorPos(mousePoint) /// <summary> /// 커서 위치 구하기 /// </summary> /// <param name="mousePoint">마우스 포인트</param> /// <returns>처리 결과</returns> [DllImport("user32")] [return: MarshalAs(UnmanagedType.Bool)] private static extern bool GetCursorPos(out MousePoint mousePoint); #endregion /// <summary> /// 마우스 포인트 /// </summary> [StructLayout(LayoutKind.Sequential)] public struct MousePoint { //////////////////////////////////////////////////////////////////////////////////////////////////// Field ////////////////////////////////////////////////////////////////////////////////////////// Public #region Field /// <summary> /// X /// </summary> public int X; /// <summary> /// Y /// </summary> public int Y; #endregion //////////////////////////////////////////////////////////////////////////////////////////////////// Constructor ////////////////////////////////////////////////////////////////////////////////////////// Public #region 생성자 - MousePoint(x, y) /// <summary> /// 생성자 /// </summary> /// <param name="x">X</param> /// <param name="y">Y</param> public MousePoint(int x, int y) { X = x; Y = y; } #endregion } |