应用程序窗口闪烁而不是变为活动状

时间:2016-09-02 15:18:22

标签: windows user-interface microsoft-dynamics autoit

我的AutoIt脚本根据传递的参数激活Dynamics AX应用程序。我打开并最小化了各种AX应用程序。

大多数情况下,正确的应用程序(基于$partition参数)被激活并处于焦点,因此脚本会继续。但有时候(可能是3分之一)应用程序只是在任务栏中闪烁并且没有激活,因此脚本无法继续。

.Net应用程序通过Windows 2012 Server上的参数调用我的AutoIt脚本:

#include <MsgBoxConstants.au3>
#include <GuiListView.au3>

Local $partition = $CmdLine[1]
Local $axc       = $CmdLine[2]
Local $brand     = $CmdLine[3]
Local $sTerm     = $CmdLine[4]

;command line example
;GoToCustomerServicePage.exe "msl" "MSLtd" "MSUK" "LS14 6PN"

SearchForCust($partition, $axc, $brand, $sTerm)

Func SearchForCust($partition, $axc, $brand, $sTerm)
    ;Set the Title match mode
    Opt("WinTitleMatchMode", 2) ;1=start, 2=subStr, 3=exact, 4=advanced, -1 to -4=Nocase

    Local $custSer = StringUpper($partition) & "/Omnica MCR/Common/Customer Service"
    Local $exePath = "C:\Program Files (x86)\Microsoft Dynamics AX\60\Client\Bin\Ax32.exe \\zoom-sql2\axcshare\" & $axc & ".axc"
    Local $axTitle = "[TITLE:" & $partition & "; CLASS:AxMainFrame]"

    ; Wait 10 seconds for the window to appear.
    WinWait($axTitle, "", 10)

    ; Test if the window exists and display the results.
    If WinExists($axTitle, "") Then
    Else
        Run($exePath)
        WinWait($axTitle, "", 20)
    EndIf

    Local $hWnd = WinGetHandle($axTitle)

    WinActivate($hWnd)

    If WinActive($hWnd) Then
    Else
        WinWaitActive($hWnd, 5)
    EndIf

    ; Simulate clicking on the address bar
    Send("{F11}")

    ;Enter this into the address bar
    Send($custSer)
    Send("{ENTER}")

    ;Set the Brand
    Send($brand)
    Send("{ENTER}")

    ;send search term
    If $sTerm <> "unavailable" Then
        Send($sTerm)
        Send("{ENTER}")
    EndIf

EndFunc

1 个答案:

答案 0 :(得分:1)

试试这个:

Doc