找回密码
 加入
搜索
查看: 2937|回复: 1

[AU3基础] [已解决]求助:怎么获取下拉列表框选中项对应的设置值?(不是显示文字)

[复制链接]
发表于 2012-8-13 11:07:04 | 显示全部楼层 |阅读模式
本帖最后由 zxk123 于 2012-8-14 08:55 编辑

我想做个游戏后台自动按键程序,需要用游戏进程句柄,我就想用下拉列表框显示程序名为:notepad.exe的所有窗口名和,选中其中一个窗口名之后再把对应的句柄传给自动按键函数调用。
问题1:怎么获取下拉列表框选中项对应的设置值?(不是显示文字)
问题2:每次按下刷新按钮,列表都刷新,而不是追加?
#include <winapi.au3>
#include <GUIConstantsEx.au3>
Opt("GUIDataSeparatorChar", 0)

$CreateName = "程序列表"
$MGUI = GUICreate($CreateName, 300, 120)
$Combo1 = GUICtrlCreateCombo("", 10, 15, 160, 25, 0x0003)
$btn_ok = GUICtrlCreateButton("刷新",200,15,60)
$btn_run = GUICtrlCreateButton("退出",200,60,60)
GUISetState(@SW_SHOW)
while 1
  $msg = GUIGetMsg()
  Select
        Case $msg = $btn_ok
                $pList = ProcessList("notepad.exe")
                $xx = 0
                Dim $arP[$pList[0][0]][2] , $iPID
                If $pList[0][0] = 0 Then
                        MsgBox(0,"错误","没有运行notepad程序")
                Else
                        for $i = 1 to $pList[0][0] step + 1
                                $wList = WinList()
                                for $j = 1 to $wList[0][0]
                                        if $wList[$j][0] <> "" And $wList[$j][0] <> "Program Manager" And $wList[$j][0] <> $CreateName And BitAND(WinGetState($wList[$j][1]), 2) Then
                                                _WinAPI_GetWindowThreadProcessId($wlist[$j][1],$iPID)
                                                if not StringCompare($iPID,$pList[$i][1]) Then
                                                        $arP[$xx][0] = $wlist[$j][0]
                                                        $arP[$xx][1] = $pList[$i][1]
                                                        GUICtrlSetData($Combo1,$arP[$xx][0] & "    PID: " & $arP[$xx][1])
                                                ;MsgBox(0,"",$arP[$k][0]&"  IPD:"&$arP[$k][1])
                                                $xx=$xx+1
                                                EndIf
                                        EndIf
                                Next
                        Next
                EndIf
    Case $msg = $GUI_EVENT_CLOSE
                ExitLoop
    Case $msg = $btn_run
                 exitLoop
  EndSelect
WEnd
Func IsVisible($handle)
  If BitAnd( WinGetState($handle), 2 ) Then
    Return 1
  Else
    Return 0
  EndIf
EndFunc

本帖子中包含更多资源

您需要 登录 才可以下载或查看,没有账号?加入

×
发表于 2012-8-13 20:05:56 | 显示全部楼层
#include <winapi.au3>
#include <GUIConstantsEx.au3>
Opt("GUIDataSeparatorChar", 0)

$CreateName = "程序列表"
$MGUI = GUICreate($CreateName, 300, 120)
$Combo1 = GUICtrlCreateCombo("", 10, 15, 160, 25, 0x0003)
$btn_ok = GUICtrlCreateButton("刷新",200,15,60)
$btn_run = GUICtrlCreateButton("退出",200,60,60)
GUISetState(@SW_SHOW)
while 1
  $msg = GUIGetMsg()
  Select
        Case $msg = $btn_ok
                $pList = ProcessList("notepad.exe")
                $xx = 0
                Dim $arP[$pList[0][0]][2] , $iPID
                If $pList[0][0] = 0 Then
                        MsgBox(0,"错误","没有运行notepad程序")
                                        Else
                                                GUICtrlSetData($Combo1,"")
                        for $i = 1 to $pList[0][0] step + 1
                                $wList = WinList()
                                for $j = 1 to $wList[0][0]
                                        if $wList[$j][0] <> "" And $wList[$j][0] <> "Program Manager" And $wList[$j][0] <> $CreateName And BitAND(WinGetState($wList[$j][1]), 2) Then
                                                _WinAPI_GetWindowThreadProcessId($wlist[$j][1],$iPID)
                                                if not StringCompare($iPID,$pList[$i][1]) Then
                                                        $arP[$xx][0] = $wlist[$j][0]
                                                        $arP[$xx][1] = $pList[$i][1]
                                                        GUICtrlSetData($Combo1,$arP[$xx][0] & "    PID: " & $arP[$xx][1])
                                                ;MsgBox(0,"",$arP[$k][0]&"  IPD:"&$arP[$k][1])
                                                $xx=$xx+1
                                                EndIf
                                        EndIf
                                Next
                        Next
                                        EndIf
                                Case $msg = $Combo1
                                        $comboselect = StringRegExp(GUICtrlRead ( $Combo1 ), 'PID: (\d+)', 1)
                                        MsgBox(64,"已选择项PID为:",$comboselect[0])
                                        
    Case $msg = $GUI_EVENT_CLOSE
                ExitLoop
    Case $msg = $btn_run
                 exitLoop
  EndSelect
WEnd
Func IsVisible($handle)
  If BitAnd( WinGetState($handle), 2 ) Then
    Return 1
  Else
    Return 0
  EndIf
EndFunc

评分

参与人数 1金钱 +25 收起 理由
zxk123 + 25 谢谢指点,正则还不懂呢。

查看全部评分

您需要登录后才可以回帖 登录 | 加入

本版积分规则

QQ|手机版|小黑屋|AUTOIT CN ( 鲁ICP备19019924号-1 )谷歌 百度

GMT+8, 2024-4-27 15:41 , Processed in 0.084656 second(s), 28 queries .

Powered by Discuz! X3.5 Licensed

© 2001-2024 Discuz! Team.

快速回复 返回顶部 返回列表