다른 명령
편집 요약 없음 |
편집 요약 없음 |
||
9번째 줄: | 9번째 줄: | ||
#include <WinAPI.au3> | #include <WinAPI.au3> | ||
; 윈도우 | ; 윈도우 핸들 얻기 | ||
Local $hWnd = WinGetHandle(" | Local $hWnd = WinGetHandle("Window Title") ; "Window Title"을 실제 윈도우 제목으로 변경 | ||
; 컨트롤 | ; 컨트롤 핸들 얻기 | ||
Local $hControl = ControlGetHandle($hWnd, "", " | Local $hControl = ControlGetHandle($hWnd, "", "[CLASS:Edit; INSTANCE:1]") ; 클래스와 인스턴스를 지정하여 컨트롤 핸들 가져오기 | ||
; 클래스 이름 버퍼 | ; 컨트롤 핸들 유효성 검사 | ||
If Not IsHWnd($hControl) Then | |||
MsgBox(16, "Error", "Could not get control handle.") | |||
Exit | |||
EndIf | |||
; 클래스 이름 버퍼 생성 | |||
Local $sClassName = DllStructCreate("char[256]") | Local $sClassName = DllStructCreate("char[256]") | ||
DllCall("user32.dll", "int", "GetClassName", "hwnd", $hControl, "ptr", DllStructGetPtr($sClassName), "int", 256) | DllCall("user32.dll", "int", "GetClassName", "hwnd", $hControl, "ptr", DllStructGetPtr($sClassName), "int", 256) | ||
; 클래스 이름 | ; 클래스 이름 가져오기 | ||
Local $sClass = DllStructGetData($sClassName, 1) | Local $sClass = DllStructGetData($sClassName, 1) | ||
ConsoleWrite("Class Name: " & $sClass & @CRLF) | ConsoleWrite("Class Name: " & $sClass & @CRLF) | ||
; 인스턴스 가져오기 | |||
Local $iInstance = _GetControlInstance($hWnd, $sClass) | |||
ConsoleWrite("Instance: " & $iInstance & @CRLF) | |||
; 함수: 주어진 핸들에서 클래스 이름의 인스턴스 번호 찾기 | |||
Func _GetControlInstance($hWnd, $sClassName) | |||
Local $iCount = 0 | |||
Local $hChild = _WinAPI_FindWindowEx($hWnd, 0, $sClassName, "") | |||
While $hChild | |||
$iCount += 1 | |||
If $hChild = $hControl Then Return $iCount | |||
$hChild = _WinAPI_FindWindowEx($hWnd, $hChild, $sClassName, "") | |||
WEnd | |||
Return 0 ; 인스턴스를 찾지 못한 경우 | |||
EndFunc | |||
</source> | </source> | ||
[[category:autoit]] | [[category:autoit]] |
2024년 11월 5일 (화) 19:19 판
Handle의 class instance 값 구하는 방법
- AutoIt에서 핸들을 통해 특정 컨트롤의 클래스 인스턴스 값을 구하려면 ControlGetHandle 또는 WinGetHandle을 사용해 윈도우나 컨트롤의 핸들을 얻은 후, DllCall을 통해 Windows API를 호출하여 인스턴스 값을 얻을 수 있습니다.
- 예를 들어, GetClassName 함수를 통해 컨트롤의 클래스 이름을 얻고, 이를 활용하여 인스턴스 값을 구할 수 있습니다.
- AutoIt에서 DllCall을 사용해 클래스 이름을 가져오는 예제
#include <WinAPI.au3> ; 윈도우 핸들 얻기 Local $hWnd = WinGetHandle("Window Title") ; "Window Title"을 실제 윈도우 제목으로 변경 ; 컨트롤 핸들 얻기 Local $hControl = ControlGetHandle($hWnd, "", "[CLASS:Edit; INSTANCE:1]") ; 클래스와 인스턴스를 지정하여 컨트롤 핸들 가져오기 ; 컨트롤 핸들 유효성 검사 If Not IsHWnd($hControl) Then MsgBox(16, "Error", "Could not get control handle.") Exit EndIf ; 클래스 이름 버퍼 생성 Local $sClassName = DllStructCreate("char[256]") DllCall("user32.dll", "int", "GetClassName", "hwnd", $hControl, "ptr", DllStructGetPtr($sClassName), "int", 256) ; 클래스 이름 가져오기 Local $sClass = DllStructGetData($sClassName, 1) ConsoleWrite("Class Name: " & $sClass & @CRLF) ; 인스턴스 가져오기 Local $iInstance = _GetControlInstance($hWnd, $sClass) ConsoleWrite("Instance: " & $iInstance & @CRLF) ; 함수: 주어진 핸들에서 클래스 이름의 인스턴스 번호 찾기 Func _GetControlInstance($hWnd, $sClassName) Local $iCount = 0 Local $hChild = _WinAPI_FindWindowEx($hWnd, 0, $sClassName, "") While $hChild $iCount += 1 If $hChild = $hControl Then Return $iCount $hChild = _WinAPI_FindWindowEx($hWnd, $hChild, $sClassName, "") WEnd Return 0 ; 인스턴스를 찾지 못한 경우 EndFunc