Sign in to follow this  
Followers 0
chun914

WinGetHandle with same class name/ different title

3 posts in this topic

i like the get a handle with given classname....

case like this..

there may be 4 possible win title

with title contain a user input number ( telephone number )

Title: ABC - 12345678 [old] - MMM - Active

Class: AfxFrameOrView70u

Title: 12345678 [old] - MMM - Active

Class: AfxFrameOrView70u

Title: ABC - 12345678 - MMM - Active

Class: AfxFrameOrView70u

Title: 12345678 - MMM - Active

Class: AfxFrameOrView70u

there will be more than one windows opend...with the same classname...but differ telephone number.

So,, the question is . how can i get handel to the windows i want.

if i use

$handle = WinGetHandle("classname = AfxFrameOrView70u")

afraid it may get handle of other win.

can i get handle with both title contain the "12345678" and all classname = AfxFrameOrView70u ??

i may be possible that other application having the wintitle contain "12345678"

Share this post


Link to post
Share on other sites



#2 ·  Posted (edited)

You going to have to make it conditional based on information you know that is in the text of the window or the title.

Here's the concept I'm thinking of... but as I said, it requires you to know something about what you're looking for.

$GetWin = _WinGetHandleByExe('notepad.exe', 'Untitled')
MsgBox(64, 'Info', 'Handle: ' & $GetWin & @CR & 'Title: ' & WinGetTitle(HWnd($GetWin)))

$GetWin = _WinGetHandleByExe('notepad.exe', '', 'www')
MsgBox(64, 'Info', 'Handle: ' & $GetWin & @CR & 'Title: ' & WinGetTitle(HWnd($GetWin)))

Func _WinGetHandleByExe($sExe, $sTitle = '', $sText = '')
    Local $aPlist = ProcessList($sExe)
    Local $aWList = WinList(), $sHold
    For $iCC = 1 To UBound($aWList, 1) - 1
        For $xCC = 1 To UBound($aPList, 1) - 1
            If WinGetProcess($aWList[$iCC][1]) = $aPList[$xCC][1] Then
                If $sTitle Then
                    If StringInStr($aWList[$iCC][0], $sTitle) Then
                        Return $aWList[$iCC][1]
                    EndIf
                ElseIf $sText Then
                    If StringInStr(WinGetText($aWList[$iCC][0]), $sText) Then
                        Return $aWList[$iCC][1]
                    EndIf
                Else
                    If BitAND(WinGetState($aWList[$iCC][1]), 2) Then Return $aWList[$iCC][1]
                EndIf
            EndIf
        Next
    Next
    Return SetError(1, 0, '')
EndFunc
Edited by SmOke_N

[center]Common sense plays a role in the basics of understanding AutoIt... If you're lacking in that, do us all a favor, and step away from the computer.[/center]

Share this post


Link to post
Share on other sites

You going to have to make it conditional based on information you know that is in the text of the window or the title.

Here's the concept I'm thinking of... but as I said, it requires you to know something about what you're looking for.

$GetWin = _WinGetHandleByExe('notepad.exe', 'Untitled')
MsgBox(64, 'Info', 'Handle: ' & $GetWin & @CR & 'Title: ' & WinGetTitle(HWnd($GetWin)))

$GetWin = _WinGetHandleByExe('notepad.exe', '', 'www')
MsgBox(64, 'Info', 'Handle: ' & $GetWin & @CR & 'Title: ' & WinGetTitle(HWnd($GetWin)))

Func _WinGetHandleByExe($sExe, $sTitle = '', $sText = '')
    Local $aPlist = ProcessList($sExe)
    Local $aWList = WinList(), $sHold
    For $iCC = 1 To UBound($aWList, 1) - 1
        For $xCC = 1 To UBound($aPList, 1) - 1
            If WinGetProcess($aWList[$iCC][1]) = $aPList[$xCC][1] Then
                If $sTitle Then
                    If StringInStr($aWList[$iCC][0], $sTitle) Then
                        Return $aWList[$iCC][1]
                    EndIf
                ElseIf $sText Then
                    If StringInStr(WinGetText($aWList[$iCC][0]), $sText) Then
                        Return $aWList[$iCC][1]
                    EndIf
                Else
                    If BitAND(WinGetState($aWList[$iCC][1]), 2) Then Return $aWList[$iCC][1]
                EndIf
            EndIf
        Next
    Next
    Return SetError(1, 0, '')
EndFunc

WOOHOO ,, it works very well... as it can handle by EXE , no problem for other application having same title.

thanks soooooo much

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!


Register a new account

Sign in

Already have an account? Sign in here.


Sign In Now
Sign in to follow this  
Followers 0