AutoIt中的下拉列表项选择

时间:2013-09-16 06:22:44

标签: autoit

如何获取以下脚本来运行test.pdf文件?

$Form1 = GUICreate("Form1", 413, 305, 302, 218)
$Combo1 = GUICtrlCreateCombo("Make Selection", 184, 48, 153, 25, BitOR($CBS_DROPDOWN,$CBS_AUTOHSCROLL))
$Combo1 = GUICtrlSetData(-1, "test1|test2|test3")
GUISetState(@SW_SHOW)
While 1
  $nMsg = GUIGetMsg()
    Switch $nMsg
           Case $GUI_EVENT_CLOSE
          Exit
        Case $Combo1
          $nMsg2 = GUIGetMsg()
          Switch $nMsg2
        Case "test1"
          ShellExecute("C:\test.pdf")
          EndSwitch
    EndSwitch
WEnd

1 个答案:

答案 0 :(得分:1)

我会这样试试:

$Form1 = GUICreate("Form1", 413, 305, 302, 218)
$Combo1 = GUICtrlCreateCombo("Make Selection", 184, 48, 153, 25, BitOR($CBS_DROPDOWN,$CBS_AUTOHSCROLL))
GUICtrlSetData(-1, "test1|test2|test3")
GUISetState(@SW_SHOW)
While 1
  $nMsg = GUIGetMsg()
    Switch $nMsg
        Case $GUI_EVENT_CLOSE
          Exit
        Case $Combo1
          If GUICtrlRead($Combo1) = "Test2" Then
            ShellExecute("C:\test.pdf")
          EndIf
    EndSwitch
WEnd

这是因为GuiCtrlRead会返回所选的值。如果此值为“Test2”,则会使shell执行。

第二件事是你不应该这样做:

$Combo1 = GUICtrlSetData(-1, "test1|test2|test3")

因为这样你就覆盖了从CuiGrtlCreateCombo获得的句柄,你需要这个句柄才能使switch case语句正常工作。