。。。。。。。。。。。。。。。。。。。。。。。。
本帖最后由 jscpu 于 2010-11-21 16:51 编辑。。。。。。。。。。。。。。。。。。。。。。。。 本帖最后由 水木子 于 2010-1-8 16:50 编辑
用我原来做的列子改了下,将就看吧!#include <GuiListView.au3>
#include <GUIConstantsEx.au3>
#include <WindowsConstants.au3>
$dir = @ScriptDir&"\config.ini"
$Form1 = GUICreate("列表框操作", 280, 270)
GUIRegisterMsg($WM_NOTIFY, "WM_NOTIFY")
$ListView1 = GUICtrlCreateListView("账号 |密码 |", 10, 10, 260, 150)
$Button1 = GUICtrlCreateButton("添加", 185, 178, 75, 25, $WS_GROUP)
$Input1 = GUICtrlCreateInput("", 60, 180, 120, 21)
$Input2 = GUICtrlCreateInput("", 60, 220, 120, 21)
$Label1 = GUICtrlCreateLabel("账号:", 20, 183, 36, 17)
$Label2 = GUICtrlCreateLabel("密码:", 20, 223, 36, 17)
$Label3 = GUICtrlCreateLabel("数据", 200, 223, 36, 17)
$Label4 = GUICtrlCreateLabel("0", 230, 223, 36, 17)
GUISetState(@SW_SHOW)
Read()
While 1
$nMsg = GUIGetMsg()
Switch $nMsg
Case $GUI_EVENT_CLOSE
Exit
Case $Button1
tian()
EndSwitch
WEnd
Func WM_NOTIFY($hWndGUI, $MsgID, $WParam, $LParam)
Local $tagNMHDR, $Event, $hWndFrom, $IDFrom
Local $tagNMHDR = DllStructCreate("int;int;int", $LParam)
If @error Then Return $GUI_RUNDEFMSG
$IDFrom = DllStructGetData($tagNMHDR, 2)
$Event = DllStructGetData($tagNMHDR, 3)
$tagNMHDR = 0
Switch $IDFrom;选择产生事件的控件
Case $ListView1
Switch $Event; 选择产生的事件
Case $NM_CLICK ; 左击
Left()
Case $NM_DBLCLK ; 双击
Case $NM_RCLICK ; 右击
EndSwitch
EndSwitch
Return $GUI_RUNDEFMSG
EndFunc ;==>WM_NOTIFY
Func Read()
$z = 0
_GUICtrlListView_DeleteAllItems($ListView1)
$read = IniReadSection($dir,"config")
If Not @error Then
For $i = 1 To $read
GUICtrlCreateListViewItem($read[$i], $ListView1)
_GUICtrlListView_AddSubItem($ListView1, $z, $read[$i], 1, $z+1)
GUICtrlSetData($Label4,$z+1)
$z += 1
Next
EndIf
EndFunc
Func tian()
$z = GUICtrlRead($Label4)
$a = GUICtrlRead($Input1)
$b = GUICtrlRead($Input2)
If $a <> "" And $b <> "" Then
IniWrite($dir,"config",$a,$b)
GUICtrlCreateListViewItem($a, $ListView1)
_GUICtrlListView_AddSubItem($ListView1, $z, $b, 1, $z+1)
MsgBox(0,"提示"," 账号: "&$a&" 密码: "&$b&" 保存成功 ")
GUICtrlSetData($Input1,"")
GUICtrlSetData($Input2,"")
GUICtrlSetData($Label4,$z+1)
EndIf
EndFunc
Func Left()
$a = _GUICtrlListView_GetSelectedIndices($ListView1)
$b = _GUICtrlListView_GetItemTextString($ListView1, Number($a))
$c = StringSplit($b,"|")
GUICtrlSetData ($Input1 ,$c)
GUICtrlSetData ($Input2 ,$c)
EndFunc 回复 2# 水木子
谢谢你的及时解答
我就是碰到的这个问题
我是说如果我这样做就出错了_11()
Func _11()
$dir = @ScriptDir&"\config.ini"
$Form1 = GUICreate("列表框操作", 280, 270)
GUIRegisterMsg($WM_NOTIFY, "WM_NOTIFY")
$ListView1 = GUICtrlCreateListView("账号 |密码 |", 10, 10, 260, 150)
$Button1 = GUICtrlCreateButton("添加", 185, 178, 75, 25, $WS_GROUP)
$Input1 = GUICtrlCreateInput("", 60, 180, 120, 21)
$Input2 = GUICtrlCreateInput("", 60, 220, 120, 21)
$Label1 = GUICtrlCreateLabel("账号:", 20, 183, 36, 17)
$Label2 = GUICtrlCreateLabel("密码:", 20, 223, 36, 17)
$Label3 = GUICtrlCreateLabel("数据", 200, 223, 36, 17)
$Label4 = GUICtrlCreateLabel("0", 230, 223, 36, 17)
GUISetState(@SW_SHOW)
Read()
While 1
$nMsg = GUIGetMsg()
Switch $nMsg
Case $GUI_EVENT_CLOSE
Exit
Case $Button1
tian()
EndSwitch
WEnd
EndFunc就是把上面放去func里就出错 将Func Left()
$a = _GUICtrlListView_GetSelectedIndices($ListView1)
$b = _GUICtrlListView_GetItemTextString($ListView1, Number($a))
$c = StringSplit($b,"|")
GUICtrlSetData ($Input1 ,$c)
GUICtrlSetData ($Input2 ,$c)
EndFunc
去掉原来的Left()
提出来,放在Case $NM_CLICK ; 左击
下面运行吧! 你这样无法获取上面的控件句柄! 回复 4# 水木子 #include <GuiListView.au3>
#include <GUIConstantsEx.au3>
#include <WindowsConstants.au3>
_11()
Func _11()
$dir = @ScriptDir&"\config.ini"
$Form1 = GUICreate("列表框操作", 280, 270)
GUIRegisterMsg($WM_NOTIFY, "WM_NOTIFY")
$ListView1 = GUICtrlCreateListView("账号 |密码 |", 10, 10, 260, 150)
$Button1 = GUICtrlCreateButton("添加", 185, 178, 75, 25, $WS_GROUP)
$Input1 = GUICtrlCreateInput("", 60, 180, 120, 21)
$Input2 = GUICtrlCreateInput("", 60, 220, 120, 21)
$Label1 = GUICtrlCreateLabel("账号:", 20, 183, 36, 17)
$Label2 = GUICtrlCreateLabel("密码:", 20, 223, 36, 17)
$Label3 = GUICtrlCreateLabel("数据", 200, 223, 36, 17)
$Label4 = GUICtrlCreateLabel("0", 230, 223, 36, 17)
GUISetState(@SW_SHOW)
Read()
While 1
$nMsg = GUIGetMsg()
Switch $nMsg
Case $GUI_EVENT_CLOSE
Exit
Case $Button1
tian()
EndSwitch
WEnd
EndFunc
func WM_NOTIFY($hWndGUI, $MsgID, $WParam, $LParam)
Local $tagNMHDR, $Event, $hWndFrom, $IDFrom
Local $tagNMHDR = DllStructCreate("int;int;int", $LParam)
If @error Then Return $GUI_RUNDEFMSG
$IDFrom = DllStructGetData($tagNMHDR, 2)
$Event = DllStructGetData($tagNMHDR, 3)
$tagNMHDR = 0
Switch $IDFrom;选择产生事件的控件
Case $ListView1
Switch $Event; 选择产生的事件
Case $NM_CLICK ; 左击
$a = _GUICtrlListView_GetSelectedIndices($ListView1)
$b = _GUICtrlListView_GetItemTextString($ListView1, Number($a))
$c = StringSplit($b,"|")
GUICtrlSetData ($Input1 ,$c)
GUICtrlSetData ($Input2 ,$c)
Case $NM_DBLCLK ; 双击
Case $NM_RCLICK ; 右击
EndSwitch
EndSwitch
Return $GUI_RUNDEFMSG
EndFunc ;==>WM_NOTIFY
Func Read()
$z = 0
_GUICtrlListView_DeleteAllItems($ListView1)
$read = IniReadSection($dir,"config")
If Not @error Then
For $i = 1 To $read
GUICtrlCreateListViewItem($read[$i], $ListView1)
_GUICtrlListView_AddSubItem($ListView1, $z, $read[$i], 1, $z+1)
GUICtrlSetData($Label4,$z+1)
$z += 1
Next
EndIf
EndFunc
Func tian()
$z = GUICtrlRead($Label4)
$a = GUICtrlRead($Input1)
$b = GUICtrlRead($Input2)
If $a <> "" And $b <> "" Then
IniWrite($dir,"config",$a,$b)
GUICtrlCreateListViewItem($a, $ListView1)
_GUICtrlListView_AddSubItem($ListView1, $z, $b, 1, $z+1)
MsgBox(0,"提示"," 账号: "&$a&" 密码: "&$b&" 保存成功 ")
GUICtrlSetData($Input1,"")
GUICtrlSetData($Input2,"")
GUICtrlSetData($Label4,$z+1)
EndIf
EndFunc
还是不行,请看代码!
提示 $ListView1: 使用前并未进行声明. 本帖最后由 水木子 于 2010-1-8 17:11 编辑
回复 6# jscpu
对的,照这样将tian()和Read()全部都替换掉
Func......EndFunc语句不能嵌套使用. 本帖最后由 水木子 于 2010-1-8 17:27 编辑
我试过了,确实这样无法获取到上面的$ListView1。
你是想把这个GUI这成子窗口吧?如果是做子窗口,那就连这个窗口一起像刚才那样写入父窗口就OK了。 回复 8# 水木子
兄弟
能帮我改一下吗!
真的不会
改来改去老出错! 马上下班,留名回家再看。。 看来你得多给些代码喽!
要不就等高手来帮你解答吧!
偶实在能力有限啊! 回复 10# sanmoking
请教下!怎么改哈! 是做父子窗口吗? 何必这么麻烦,做控件的时候,把变量定义成$hListview1就行了,无非是句柄变量和普通变量的区别 是这样吗?#include <GuiListView.au3>
#include <GUIConstantsEx.au3>
#include <WindowsConstants.au3>
$dir = @ScriptDir&"\config.ini"
$Form1 = GUICreate("父窗口", 450, 350)
$But1 = GUICtrlCreateButton("子窗口", 180, 130, 100, 60, $WS_GROUP)
GUISetState(@SW_SHOW)
While 1
$nMsg = GUIGetMsg()
Switch $nMsg
Case -3
Exit
Case $But1
GUISetState(@SW_DISABLE,$Form1)
$Form2 = GUICreate("列表框操作", 280, 270)
GUIRegisterMsg($WM_NOTIFY, "WM_NOTIFY")
$ListView1 = GUICtrlCreateListView("账号 |密码 |", 10, 10, 260, 150)
$Button1 = GUICtrlCreateButton("添加", 185, 178, 75, 25, $WS_GROUP)
$Input1 = GUICtrlCreateInput("", 60, 180, 120, 21)
$Input2 = GUICtrlCreateInput("", 60, 220, 120, 21)
$Label1 = GUICtrlCreateLabel("账号:", 20, 183, 36, 17)
$Label2 = GUICtrlCreateLabel("密码:", 20, 223, 36, 17)
$Label3 = GUICtrlCreateLabel("数据", 200, 223, 36, 17)
$Label4 = GUICtrlCreateLabel("0", 230, 223, 36, 17)
GUISetState(@SW_SHOW)
GUICtrlCreateListViewItem('abc', $ListView1)
_GUICtrlListView_AddSubItem($ListView1, 0, '123', 1, 1)
While 1
$nMsg = GUIGetMsg()
Switch $nMsg
Case -3
GUISetState(@SW_ENABLE,$Form1)
GUIDelete($Form2)
ExitLoop
Case $Button1
EndSwitch
WEnd
EndSwitch
WEnd
Func WM_NOTIFY($hWndGUI, $MsgID, $WParam, $LParam)
Local $tagNMHDR, $Event, $hWndFrom, $IDFrom
Local $tagNMHDR = DllStructCreate("int;int;int", $LParam)
If @error Then Return $GUI_RUNDEFMSG
$IDFrom = DllStructGetData($tagNMHDR, 2)
$Event = DllStructGetData($tagNMHDR, 3)
$tagNMHDR = 0
Switch $IDFrom;选择产生事件的控件
Case $ListView1
Switch $Event; 选择产生的事件
Case $NM_CLICK ; 左击
$a = _GUICtrlListView_GetSelectedIndices($ListView1)
$b = _GUICtrlListView_GetItemTextString($ListView1, Number($a))
$c = StringSplit($b,"|")
GUICtrlSetData ($Input1 ,$c)
GUICtrlSetData ($Input2 ,$c)
Case $NM_DBLCLK ; 双击
Case $NM_RCLICK ; 右击
EndSwitch
EndSwitch
Return $GUI_RUNDEFMSG
EndFunc ;==>WM_NOTIFY
页:
[1]
2