상세 컨텐츠

본문 제목

WindowFromPoint - 위치에 따른 Window의 Handle값 취득

.NET/Windows API for .NET

by 클리엘 클리엘 2019. 8. 6. 16:08

본문

WindowFromPoint함수는 특정 위치에 있는 Window의 Handle을 반환하는 함 수 입니다.

Declare Function WindowFromPoint Lib "user32" Alias "WindowFromPoint" (ByVal lpPoint As Point) As Integer 

▶VB.NET 선언

[DllImport("user32.dll")] 
public static extern int WindowFromPoint(Point lpPoint); 

▶C# 선언

함수의 인수로는 Handle을 가져올 Window가 있는 위치를 Point로 지정합니다. 아래는 현재 Form의 X, Y위치를 가리키는 예제입니다.

Dim ptCursor As Point = New Point() 

ptCursor.X = Me.Location.X 
ptCursor.Y = Me.Location.Y

▶VB.NET

Point ptCursor = new Point(); 

ptCursor.X = this.Location.X; 
ptCursor.Y = this.Location.Y; 

▶C#

만일 Mouse Pointer가 위치한 지점을 선정하시려면 GetCursorPos사용합니다.

[Windows API for .NET] - GetCursorPos - Mouse Pointer의 현재위치 반환


위치에 대한 Point를 인수를 통하여 현재 Form의 Handle을 구하려면 함수를 다음과 같이 호출합니다.

Dim ptCursor As Point = New Point() 
ptCursor.X = Me.Location.X 
ptCursor.Y = Me.Location.Y 

SetWindowText(WindowFromPoint(ptCursor), "abc")

▶VB.NET 호출

Point ptCursor = new Point(); 
ptCursor.X = this.Location.X; 
ptCursor.Y = this.Location.Y; 

SetWindowText(WindowFromPoint(ptCursor), "abc"); 

▶C# 호출

관련글 더보기

댓글 영역