本帖最后由 happytc 于 2012-5-16 06:30 编辑
这么久了,还没有人回答呀
我又来热心一把
#include <WindowsConstants.au3>
#Include <WinAPI.au3>
#Include <WinAPIEx.au3>
Local $hGui, $Button, $hCtrl, $iInstance
$hGui = GUICreate("Get Instance", 500, 300)
$Button = GUICtrlCreateButton("Button", 10, 10, 100, 30)
$hCtrl = GUICtrlGetHandle($Button)
GUISetState()
$iInstance = _GetInstance($hCtrl)
If Not @error Then MsgBox(0, "Get instance: ", "Instance: " & $iInstance)
Func _GetInstance($hWnd)
Local $aList, $sText, $iID = 0
$sText = _WinAPI_GetClassName($hWnd)
If Not $sText Then
SetError(-1, 0, -1)
Return
EndIf
$aList = _WinAPI_EnumChildWindows(_WinAPI_GetAncestor($hWnd, $GA_ROOT), 0)
If @error Then
SetError(-2, 0, -2)
Return
EndIf
For $i = 1 To $aList[0][0]
If $aList[$i][1] = $sText Then $iID += 1
If $aList[$i][0] = $hWnd Then ExitLoop
Next
If Not $iID Then
SetError(-3, 0, -3)
Return
EndIf
Return $iID
EndFunc
|