■ SystemParametersInfo 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 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 |
using System.Runtime.InteropServices; using System.Runtime.Versioning; using System.Windows; #region 시스템 매개 변수 정보 처리하기 - SystemParametersInfo(action, parameter, rectangle, update) /// <summary> /// 시스템 매개 변수 정보 처리하기 /// </summary> /// <param name="action">액션</param> /// <param name="parameter">매개 변수</param> /// <param name="rectangle">사각형</param> /// <param name="update">업데이트</param> /// <returns>처리 결과</returns> [DllImport("user32", CharSet = CharSet.Auto)] [ResourceExposure(ResourceScope.None)] private static extern bool SystemParametersInfo(int action, int parameter, ref RECTANGLE rectangle, int update); #endregion /// <summary> /// 사각형 /// </summary> [StructLayout(LayoutKind.Sequential)] public struct RECTANGLE { //////////////////////////////////////////////////////////////////////////////////////////////////// Field ////////////////////////////////////////////////////////////////////////////////////////// Public #region Field /// <summary> /// 왼쪽 /// </summary> public int Left; /// <summary> /// 위쪽 /// </summary> public int Top; /// <summary> /// 오른쪽 /// </summary> public int Right; /// <summary> /// 아래쪽 /// </summary> public int Bottom; #endregion //////////////////////////////////////////////////////////////////////////////////////////////////// Property ////////////////////////////////////////////////////////////////////////////////////////// Public #region 크기 - Size /// <summary> /// 크기 /// </summary> public Size Size { get { return new Size ( Right - Left, Bottom - Top ); } } #endregion //////////////////////////////////////////////////////////////////////////////////////////////////// Constructor ////////////////////////////////////////////////////////////////////////////////////////// Public #region 생성자 - RECTANGLE(left, top, right, bottom) /// <summary> /// 생성자 /// </summary> /// <param name="left">왼쪽</param> /// <param name="top">위쪽</param> /// <param name="right">오른쪽</param> /// <param name="bottom">아래쪽</param> public RECTANGLE(int left, int top, int right, int bottom) { Left = left; Top = top; Right = right; Bottom = bottom; } #endregion #region 생성자 - RECTANGLE(source) /// <summary> /// 생성자 /// </summary> /// <param name="source">소스 사각형</param> public RECTANGLE(Rect source) { Left = (int)source.Left; Top = (int)source.Top; Right = (int)source.Right; Bottom = (int)source.Bottom; } #endregion //////////////////////////////////////////////////////////////////////////////////////////////////// Method ////////////////////////////////////////////////////////////////////////////////////////// Static //////////////////////////////////////////////////////////////////////////////// Public #region 사각형 구하기 - GetRectangle(x, y, width, height) /// <summary> /// 사각형 구하기 /// </summary> /// <param name="x">X</param> /// <param name="y">Y</param> /// <param name="width">너비</param> /// <param name="height">높이</param> /// <returns>사각형</returns> public static RECTANGLE GetRectangle(int x, int y, int width, int height) { return new RECTANGLE(x, y, x + width, y + height); } #endregion } |