반응형

매크로 대상이 되는 창의 위치를 가져오는 방법.

user32.dll의 GetWindowRect 함수를 이용한다.

1) 코드

앞의 글(프로세스 목록 얻어내기)에서 추출한 윈도 핸들을 GetWindowRect 함수의 인자로 넣어 좌표를 요청한다.

 

        [StructLayout(LayoutKind.Sequential)]
        public struct RECT
        {
            public int Left;        // x position of upper-left corner
            public int Top;         // y position of upper-left corner
            public int Right;       // x position of lower-right corner
            public int Bottom;      // y position of lower-right corner
        }
        [DllImport("user32.dll")]
        [return: MarshalAs(UnmanagedType.Bool)]
        static extern bool GetWindowRect(IntPtr hWnd, out RECT lpRect);
        
        
       GetWindowRect(_winHandle, out rct);  //
       Debug.WriteLine(string.Format("Left: {0}, Right: {1}, Top: {2}, Bottom: {3}", rct.Left, rct.Right, rct.Top, rct.Bottom));

 

2) 출력

728x90
반응형
  • 네이버 블러그 공유하기
  • 네이버 밴드에 공유하기
  • 페이스북 공유하기
  • 카카오스토리 공유하기