메뉴 여닫기
개인 메뉴 토글
로그인하지 않음
만약 지금 편집한다면 당신의 IP 주소가 공개될 수 있습니다.

Handle의 class instance 값 구하는 방법: 두 판 사이의 차이

데브카페
편집 요약 없음
편집 요약 없음
9번째 줄: 9번째 줄:
#include <WinAPI.au3>
#include <WinAPI.au3>


; 윈도우 핸들을 구합니다.
; 윈도우 핸들 얻기
Local $hWnd = WinGetHandle("창 제목") ; "창 제목"을 실제 프로그램 창 제목으로 변경하세요.
Local $hWnd = WinGetHandle("Window Title") ; "Window Title"을 실제 윈도우 제목으로 변경


; 컨트롤 핸들을 구합니다.
; 컨트롤 핸들 얻기
Local $hControl = ControlGetHandle($hWnd, "", "컨트롤 ID") ; "컨트롤 ID"를 실제 컨트롤의 ID로 변경하세요.
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>


* 코드 설명
<pre>
1. 윈도우 및 컨트롤 핸들 가져오기:
• WinGetHandle로 윈도우 핸들을 가져옵니다.
• ControlGetHandle로 특정 컨트롤의 핸들을 가져옵니다.
2. 클래스 이름 가져오기:
• GetClassName 함수를 호출하여 컨트롤의 클래스 이름을 sClassName 버퍼에 저장합니다.
• DllStructGetData를 사용하여 버퍼에서 클래스 이름을 추출합니다.
</pre>


[[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

Comments