【问题标题】:Check if WinList() contains a certain title检查 WinList() 是否包含某个标题
【发布时间】:2018-02-17 12:17:04
【问题描述】:

我使用WinList() 列出所有打开的窗口以在 AutoIt 中获取窗口标题和 -handle。

我想检查结果数组是否包含特定标题。做这个的最好方式是什么?没有WinList().Contains("TitleName") 或类似的东西。

Local $aList = WinList()    ;Gets a list of Window Titles and IDs

【问题讨论】:

    标签: autoit


    【解决方案1】:

    好的,我现在知道了:

    For $i = 1 To $aList[0][0]
        If $aList[$i][0] = "Title/String you search for" Then
            MsgBox($MB_SYSTEMMODAL, "", "MessageBox shows this text if title is in list.")
        EndIf
    Next
    

    【讨论】:

    • 如果For...To...Step...Next 应该在第一次匹配后停止,则使用ExitLoop(在MsgBox() 之后)。
    【解决方案2】:

    您也可以使用与您所写内容类似的内容。

    #include <Array.au3>
    Opt("WinDetectHiddenText", 0) ;0=don't detect, 1=do detect
    Opt("WinSearchChildren", 0) ;0=no, 1=search children also
    Opt("WinTextMatchMode", 1) ;1=complete, 2=quick
    Opt("WinTitleMatchMode", 1) ;1=start, 2=subStr, 3=exact, 4=advanced, -1 to -4=Nocase
    Local $title = 'AutoIt Help (v3.3.14.2)'
    Local $aList = WinList()
    ;~ _ArrayDisplay($aList)
    Local $iIndex = _ArraySearch($aList,$title)
    WinActivate($aList[$iIndex][1], '')
    

    【讨论】:

      【解决方案3】:

      窗口存在吗?

      我正在列出所有打开的窗口……我想检查……是否包含特定的标题。最好的方法是什么?

      根据Documentation - Function Reference - WinExists()

      检查指定的窗口是否存在。

      示例。

      Global Const $g_sWndTitle = 'Window title here'
      
      If WinExists($g_sWndTitle) Then WinFlash($g_sWndTitle)
      

      检索窗口句柄、-text 和 -title

      手柄

      "... 获取窗口标题和-handle ..."

      根据Documentation - Function Reference - WinGetHandle()

      检索窗口的内部句柄。

      例子:

      Global Const $g_sWndTitle = 'Window title here'
      Global       $g_hWnd
      
      If WinExists($g_sWndTitle) Then
      
          $g_hWnd = WinGetHandle($g_sWndTitle)
          WinFlash($g_hWnd)
      
      EndIf
      

      文字

      根据Documentation - Function Reference - WinGetText()

      从窗口中检索文本。

      例子:

      Global Const $g_sWndTitle = 'Window title here'
      
      If WinExists($g_sWndTitle) Then
      
          WinFlash($g_sWndTitle)
          ConsoleWrite(WinGetText($g_sWndTitle) & @CRLF)
      
      EndIf
      

      标题

      同样,WinGetTitle()

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 2014-05-26
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2011-04-02
        • 2020-08-11
        • 2018-04-17
        • 2022-01-05
        相关资源
        最近更新 更多