【已解决】如何点击组合列表框中的项后执行其他任务
本帖最后由 dnvplj 于 2016-10-23 10:01 编辑请问各位朋友,如何点击组合列表框中的“本地连接”后,显示“Realtek PCIe GBE”和“01-01-01-01-01-01”;点击“无线连接”后,显示“Family Controller”和“02-02-02-02-02-02”#include <ButtonConstants.au3>
#include <ComboConstants.au3>
#include <EditConstants.au3>
#include <GUIConstantsEx.au3>
#include <WindowsConstants.au3>
Global $Set_1, $Set_2, $Set_3, $Set_4, $Set_5, $Set_6
$Form1 = GUICreate("Form1", 615, 438, 192, 124)
$Combo2 = GUICtrlCreateCombo("", 20, 80, 340, 23, BitOR($CBS_DROPDOWN, $CBS_AUTOHSCROLL))
$Label1 = GUICtrlCreateLabel("本地网卡:", 20, 150, 66, 17)
$Label2 = GUICtrlCreateLabel("", 86, 150, 330, 21)
$Label3 = GUICtrlCreateLabel("MAC地址:", 20, 190, 70, 17)
$Label4 = GUICtrlCreateLabel("", 86, 190, 306, 17)
_Setini()
GUISetState(@SW_SHOW)
While 1
$nMsg = GUIGetMsg()
Switch $nMsg
Case $GUI_EVENT_CLOSE
Exit
EndSwitch
WEnd
Func _Setini()
Local $Set_1 = IniRead(@ScriptDir & "\Soft.ini", "Network", "Network1|NAdapter", "")
Local $Set_2 = IniRead(@ScriptDir & "\Soft.ini", "Network", "Network2|NAdapter", "")
Local $Set_3 = IniRead(@ScriptDir & "\Soft.ini", "Network", "Network1|HAddress", "")
Local $Set_4 = IniRead(@ScriptDir & "\Soft.ini", "Network", "Network2|HAddress", "")
Local $Set_5 = IniRead(@ScriptDir & "\Soft.ini", "Network", "Network1|Name", "")
Local $Set_6 = IniRead(@ScriptDir & "\Soft.ini", "Network", "Network2|Name", "")
GUICtrlSetData($Combo2, $Set_5 & "|" & $Set_6, $Set_5)
GUICtrlSetData($Label2, $Set_1)
GUICtrlSetData($Label4, $Set_3)
EndFunc ;==>_Setini配置文件
Network1|NAdapter=Realtek PCIe GBE
Network1|HAddress=01-01-01-01-01-01
Network1|Name=本地连接
Network2|NAdapter=Family Controller
Network2|HAddress=02-02-02-02-02-02
Network2|Name=无线连接 回复 1# dnvplj #include <ButtonConstants.au3>
#include <ComboConstants.au3>
#include <EditConstants.au3>
#include <GUIConstantsEx.au3>
#include <WindowsConstants.au3>
Global $Set_1, $Set_2, $Set_3, $Set_4, $Set_5, $Set_6
$Form1 = GUICreate("Form1", 615, 438, 192, 124)
$Combo2 = GUICtrlCreateCombo("", 20, 80, 340, 23, BitOR($CBS_DROPDOWN, $CBS_AUTOHSCROLL))
$Label1 = GUICtrlCreateLabel("本地网卡:", 20, 150, 66, 17)
$L_NAptr = GUICtrlCreateLabel("", 86, 150, 330, 21)
$Label3 = GUICtrlCreateLabel("MAC地址:", 20, 190, 70, 17)
$L_MAC = GUICtrlCreateLabel("", 86, 190, 306, 17)
_Setini()
GUISetState(@SW_SHOW)
While 1
$nMsg = GUIGetMsg()
Switch $nMsg
Case $GUI_EVENT_CLOSE
Exit
Case $Combo2
_Setini(GUICtrlRead($Combo2))
EndSwitch
WEnd
Func _Setini($key = Default)
Local $Set_1 = IniRead(@ScriptDir & "\Soft.ini", "Network", "Network1|NAdapter", "Realtek PCIe GBE")
Local $Set_2 = IniRead(@ScriptDir & "\Soft.ini", "Network", "Network2|NAdapter", "01-01-01-01-01-01")
Local $Set_3 = IniRead(@ScriptDir & "\Soft.ini", "Network", "Network1|HAddress", "本地连接")
Local $Set_4 = IniRead(@ScriptDir & "\Soft.ini", "Network", "Network2|HAddress", "Family Controller")
Local $Set_5 = IniRead(@ScriptDir & "\Soft.ini", "Network", "Network1|Name", "02-02-02-02-02-02")
Local $Set_6 = IniRead(@ScriptDir & "\Soft.ini", "Network", "Network2|Name", "无线连接")
GUICtrlSetData($Combo2, '')
If IsKeyword($key) Or $key == '本地连接' Then
GUICtrlSetData($Combo2, $Set_3 & "|" & $Set_6, $Set_3)
GUICtrlSetData($L_NAptr, $Set_1)
GUICtrlSetData($L_MAC, $Set_2)
Else
GUICtrlSetData($Combo2, $Set_3 & "|" & $Set_6, $Set_6)
GUICtrlSetData($L_NAptr, $Set_4)
GUICtrlSetData($L_MAC, $Set_5)
EndIf
EndFunc ;==>_Setini 本帖最后由 dnvplj 于 2016-10-21 22:39 编辑
回复 2# Alam
朋友您好,感谢你的回复,现在的问题是:
1、下拉框里显示了MAC地址项,应显“本地连接”。
2、只能切换一次,第二次没有变化。
3、配置文件里的“本地连接”不是固定的,有可能是“本地连接2”或“本地连接3等”,此项我忘说了,对不起。 回复 3# dnvplj
是不是都没运行测试过我2楼的代码啊?
我个人更愿意这样去实现你的目的:
首先,把INI配置文件的内容修改一下,我设想中的 Netwok.ini ,其内容应该是这样的.[本地连接]
Adapter=Realtek PCIe GBE
MAC=01-01-01-01-01-01
[本地连接2]
Adapter=Realtek PCIe XXX
MAC=01-01-0f-01-05-01
[无线连接]
Adapter=Family Controller
MAC=02-02-02-02-02-02最后,主程序的关键函数是这样实现功能的:While 1
$nMsg = GUIGetMsg()
Switch $nMsg
Case $GUI_EVENT_CLOSE
Exit
Case $Combo2
_Setini()
EndSwitch
WEnd
Func _Setini()
Local $sConnModes = '', $sINI = @ScriptDir & '\Network.ini'
Local $sDefault, $sSections
$sSections = IniReadSectionNames($sINI)
If @error Then Return SetError(1)
For $i = 1 To $sSections
$sConnModes &= $sSections[$i] & '|'
Next
$sConnModes = StringTrimRight($sConnModes, 1)
$sDefault = GUICtrlRead($Combo2)
If $sDefault == '' Then $sDefault = $sSections
GUICtrlSetData($Combo2, '')
GUICtrlSetData($Combo2, $sConnModes, $sDefault)
GUICtrlSetData($L_NAptr, IniRead($sINI, $sDefault, 'Adapter', 'no match'))
GUICtrlSetData($L_MAC, IniRead($sINI, $sDefault, 'MAC', 'no match'))
EndFunc ;==>_Setini这样,以后维护只要修改好INI的内容就可以了. 本帖最后由 dnvplj 于 2016-10-22 16:55 编辑
回复 4# Alam
配置文件(本地连接)不是固定的,是几,不确定,能否按1楼的配置文件,帮我完善他吗?再次感谢给予指教。 回复 5# dnvplj
抱歉,你给出的示例代码中,不必要的定义实在不少,我看花眼了,所以在2楼搞错了读你配置文件的"意向值",
但该代码在无配置文件时,运行测试显示的结果无误,所以我坚持代码的正确性并无视了你3楼的要求,给出了4楼的新建议.
现在已经按你要求再次修改了自定义函数,希望顺利.
最后,希望你花点时间,对比下,1楼,2楼,以及这楼的代码, 从中找出你在3楼的疑问吧.#include <ButtonConstants.au3>
#include <ComboConstants.au3>
#include <EditConstants.au3>
#include <GUIConstantsEx.au3>
#include <WindowsConstants.au3>
$Form1 = GUICreate("Form1", 615, 438, 192, 124)
$Combo2 = GUICtrlCreateCombo("", 20, 80, 340, 23, BitOR($CBS_DROPDOWN, $CBS_AUTOHSCROLL))
$Label1 = GUICtrlCreateLabel("本地网卡:", 20, 150, 66, 17)
$L_NAptr = GUICtrlCreateLabel("", 86, 150, 330, 21)
$Label3 = GUICtrlCreateLabel("MAC地址:", 20, 190, 70, 17)
$L_MAC = GUICtrlCreateLabel("", 86, 190, 306, 17)
_Setini()
GUISetState(@SW_SHOW)
While 1
$nMsg = GUIGetMsg()
Switch $nMsg
Case $GUI_EVENT_CLOSE
Exit
Case $Combo2
_Setini(GUICtrlRead($Combo2))
EndSwitch
WEnd
Func _Setini($key = Default)
Local $Set_1 = IniRead(@ScriptDir & "\Soft.ini", "Network", "Network1|NAdapter", "Realtek PCIe GBE")
Local $Set_2 = IniRead(@ScriptDir & "\Soft.ini", "Network", "Network2|NAdapter", "Family Controller")
Local $Set_3 = IniRead(@ScriptDir & "\Soft.ini", "Network", "Network1|HAddress", "01-01-01-01-01-01")
Local $Set_4 = IniRead(@ScriptDir & "\Soft.ini", "Network", "Network2|HAddress", "02-02-02-02-02-02")
Local $Set_5 = IniRead(@ScriptDir & "\Soft.ini", "Network", "Network1|Name", "本地连接")
Local $Set_6 = IniRead(@ScriptDir & "\Soft.ini", "Network", "Network2|Name", "无线连接")
GUICtrlSetData($Combo2, '')
If IsKeyword($key) Or $key == $Set_5 Then
GUICtrlSetData($Combo2, $Set_5 & "|" & $Set_6, $Set_5)
GUICtrlSetData($L_NAptr, $Set_1)
GUICtrlSetData($L_MAC, $Set_3)
Else
GUICtrlSetData($Combo2, $Set_5 & "|" & $Set_6, $Set_6)
GUICtrlSetData($L_NAptr, $Set_2)
GUICtrlSetData($L_MAC, $Set_4)
EndIf
EndFunc ;==>_Setini 热心人,代码老长了 感谢@Alam朋友,耐心解达问题,问题解决了,再次感谢。
页:
[1]