.NET/Windows API for .NET

GetClassName - Window의 Class이름 구하기

클리엘 2019. 8. 5. 17:09
728x90

GetClassName은 지정된 Window의 Class이름을 가져오는 함수입니다.

Declare Function GetClassName Lib "user32" Alias "GetClassNameA" (ByVal hwnd As Integer, ByVal lpClassName As String, ByVal nMaxCount As Integer) As Integer

- VB.NET 선언

[DllImport("user32")]
public static extern int GetClassName(int hwnd, StringBuilder lpClassName, int nMaxCount);

- C# 선언

 

선언 GetClassName함수의 첫번째 인수는 Class이름을 구할 Window의 Handle을 넘겨줍니다. 두번째 인수에서는 실제 Class이름을 가져와 저장할 String변수를 지정하고 마지막 세번째 인수에서 Class이름을 가져올 최대 길이를 지정합니다.

예를 들어 현재의 Window에서 Class이름을 가져 오려면 함수는 다음과 같이 선언될 수 있습니다.

Dim sClass As String = Space(100)
GetClassName(Me.Handle, sClass, 100)

- VB.NET 호출

StringBuilder sClass = new StringBuilder(100);
GetClassName((int)this.Handle, sClass, 100);

- C# 호출

 

함수를 위와 같이 선언하고 나면 변수 sClass에 Class의 이름이 저장됩니다.

이 함수가 성공적으로 수행되면 가져온 Class이름의 길이를 반환하고 그렇지 않으면 0을 반환합니다.

728x90