GUICtrlCreateCombo地一项为空[已解决]
本帖最后由 yikang8888 于 2010-12-22 15:48 编辑如下代码运行后Combo的第一项为空的,请高手帮忙解决一下,谢谢了
#include <GUIConstantsEx.au3>
#include <ButtonConstants.au3>
#include <ComboConstants.au3>
Local $test, $iNICIndex
$test = _UpCmpLanNameIDInfo()
; 创建“网卡选择”窗口
Local $hNICWnd, $hOKButton, $hIfTable
$hNICWnd = GUICreate("测试" & " - 网卡选择", 404, 118)
GUICtrlCreateLabel("检测到本机安装有多个网络适配器,请选择用于更新的网卡。", 16, 16, 340, 24)
$hIfTable = GUICtrlCreateCombo("", 16, 48, 372, 12 * $test, BitOR($GUI_SS_DEFAULT_COMBO, $CBS_DROPDOWNLIST))
For $i = 2 To $test
GUICtrlSetData(-1,$test[$i])
Next
$hOKButton = GUICtrlCreateButton("确定(&O)", 165, 80, 76, 22, $BS_DEFPUSHBUTTON)
; 窗口事件
GUISetState(@SW_SHOW)
While 1
Switch GUIGetMsg()
Case $hOKButton, $GUI_EVENT_CLOSE
$iNICIndex = GUICtrlRead($hIfTable)
MsgBox(0, 0, $iNICIndex)
ExitLoop
EndSwitch
WEnd
Func _UpCmpLanNameIDInfo()
;======================================================
;
; 函数名称: _UpCmpLanNameIDInfo()
; 详细信息: 获取系统所有网卡名称和ID信息
; 返回值说明:
; 以二维数组方式返回.例如 $info=_UpCmpLanNameIDInfo()
; $info 第一块网卡的名称
; $info 第二块网卡的名称
; $info 第一块网卡的ID
; $info 第二块网卡的ID
; 其他网卡信息依次类推。。。
; 作者: viplight (viplight@qq.com)
; QQ: 530417369
;======================================================
Local $colItems = ""
Local $strComputer = "localhost"
Local $objWMIService
Local $wbemFlagReturnImmediately = 0x10
Local $wbemFlagForwardOnly = 0x20
Local $UpCmprAdapterID = 0
Local $UpCmprAdapterHostName = ""
Local $UpCmpLanNameID
$UpCmpLanNameID = 0
$objWMIService = ObjGet("winmgmts:\\" & $strComputer & "\root\CIMV2")
$colItems = $objWMIService.ExecQuery("SELECT * FROM Win32_TSNetworkAdapterListSetting", "WQL", _
$wbemFlagReturnImmediately + $wbemFlagForwardOnly)
If IsObj($colItems) Then
For $objItem In $colItems
$UpCmpLan = $objItem.Description
$UpCmpID = $objItem.NetworkAdapterID
$UpCmprAdapterID += 1
$UpCmpLanNameID = $UpCmprAdapterID
$UpCmpLanNameID[$UpCmprAdapterID] = $UpCmpLan
$UpCmpLanNameID[$UpCmprAdapterID] = $UpCmpID
Next
EndIf
Return $UpCmpLanNameID
EndFunc ;==>_UpCmpLanNameIDInfo 帮顶......................... 本帖最后由 yhxhappy 于 2010-12-17 21:48 编辑
你的代码在我的笔记本上一个网上都找不到了,我只好做了一个数组演示
#include <GUIConstantsEx.au3>
#include <ButtonConstants.au3>
#include <ComboConstants.au3>
Local $test, $iNICIndex
;Local $test = _UpCmpLanNameIDInfo()
Local $test
$test = 4
$test = "网卡1"
$test = "网卡2"
$test = "网卡3"
; 创建“网卡选择”窗口
Local $hNICWnd, $hOKButton, $hIfTable, $txt = ""
$hNICWnd = GUICreate("测试" & " - 网卡选择", 404, 118)
GUICtrlCreateLabel("检测到本机安装有多个网络适配器,请选择用于更新的网卡。", 16, 16, 340, 24)
$hIfTable = GUICtrlCreateCombo("", 16, 48, 372, 12, BitOR($GUI_SS_DEFAULT_COMBO, $CBS_DROPDOWNLIST))
For $i = 2 To $test
$txt &= $test[$i] & "|"
Next
If $txt <> "" then GUICtrlSetData($hIfTable, $txt, $test[$test]) ;此处的 $test[$test] 表示默认选中最后一项,如果想默认选中第一项,则使用 $test
$hOKButton = GUICtrlCreateButton("确定(&O)", 165, 80, 76, 22, $BS_DEFPUSHBUTTON)
; 窗口事件
GUISetState(@SW_SHOW)
While 1
Switch GUIGetMsg()
Case $hOKButton, $GUI_EVENT_CLOSE
$iNICIndex = GUICtrlRead($hIfTable)
MsgBox(0, 0, $iNICIndex)
ExitLoop
EndSwitch
WEnd
Func _UpCmpLanNameIDInfo()
;======================================================
;
; 函数名称: _UpCmpLanNameIDInfo()
; 详细信息: 获取系统所有网卡名称和ID信息
; 返回值说明:
; 以二维数组方式返回.例如 $info=_UpCmpLanNameIDInfo()
; $info 第一块网卡的名称
; $info 第二块网卡的名称
; $info 第一块网卡的ID
; $info 第二块网卡的ID
; 其他网卡信息依次类推。。。
; 作者: viplight (viplight@qq.com)
; QQ: 530417369
;======================================================
Local $colItems = ""
Local $strComputer = "localhost"
Local $objWMIService
Local $wbemFlagReturnImmediately = 0x10
Local $wbemFlagForwardOnly = 0x20
Local $UpCmprAdapterID = 0
Local $UpCmprAdapterHostName = ""
Local $UpCmpLanNameID
$UpCmpLanNameID = 0
$objWMIService = ObjGet("winmgmts:\\" & $strComputer & "\root\CIMV2")
$colItems = $objWMIService.ExecQuery("SELECT * FROM Win32_TSNetworkAdapterListSetting", "WQL", _
$wbemFlagReturnImmediately + $wbemFlagForwardOnly)
If IsObj($colItems) Then
For $objItem In $colItems
$UpCmpLan = $objItem.Description
$UpCmpID = $objItem.NetworkAdapterID
$UpCmprAdapterID += 1
$UpCmpLanNameID = $UpCmprAdapterID
$UpCmpLanNameID[$UpCmprAdapterID] = $UpCmpLan
$UpCmpLanNameID[$UpCmprAdapterID] = $UpCmpID
Next
EndIf
Return $UpCmpLanNameID
EndFunc ;==>_UpCmpLanNameIDInfo
谢谢,{:face (258):} 感谢大家的帮助 呵呵学习一下。。
页:
[1]