[已解决]ListView中如何实现数据的刷新?
本帖最后由 pdp320921 于 2011-4-12 12:30 编辑问题如图题
我想实现图中Refersh 按钮的功能,
试过_GUICtrlListView_DeleteItem($LV)或GUICtrlSendMsg($Lv, $LVM_DELETEALLITEMS, 0, 0)后重新调用function函数不行、
也试过AdlibRegister也不行
求助大虾版主们~~
谢谢! 本帖最后由 netegg 于 2011-4-11 15:39 编辑
简单刷新试试看editlabell,adlib肯定没戏 试试将GUICTRLLISTVIEW_DELETEITEM改成这两句试试.
Global Const $WM_SETREDRAW = 0xB
_SendMessage($hListView,$WM_SETREDRAW,0,0) 新手学习一下,试验一下 本帖最后由 pdp320921 于 2011-4-11 17:17 编辑
回复 3# 3mile
感谢3mile的回复,
试了,提示错误
C:\Users\3G\Desktop\11.au3(93,36) : ERROR: $WM_SETREDRAW previously declared as a 'Const'
Global Const $WM_SETREDRAW = 0xB
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^
C:\Users\3G\Desktop\11.au3 - 1 error(s), 0 warning(s)
回复 2# netegg
弱弱的问一句 editlabell是什么东东? 大牛门都理解错误了,LZ要的不是重绘,而是重载。
_GUICtrlListView_DeleteAllItems然后重新写入就是了. DeleteAllItems要跟句柄,所以,应该使用GUICtrlGetHandle获取句柄先。 本帖最后由 pdp320921 于 2011-4-11 19:32 编辑
回复 7# ceoguang
可是之前用的就是_GUICtrlListView_DeleteAllItems然后重新调用function函数可还是不行?
回复 8# republican
我用的就是句柄啊,不行啊~($LV,就是获取List View的句柄) 回复 9# pdp320921
不明白你说的不行是指什么不行。
我只是想提醒一下,控件ID和句柄是不一样的。 回复 10# republican #include <Constants.au3>
;#NoTrayIcon
#include <GuiListView.au3>
#include <GuiConstantsEx.au3>
#include <WindowsConstants.au3>
#include <array.au3>
Opt("GUIOnEventMode", 1)
DIM $x=0,$m=0
$GUI=GUICreate("Wireless Network Connection",820,400,-1,-1)
$Label_01=GUICtrlCreateLabel("Wireless Network Connection",10,20,800,40,0x01)
$Button_01=GUICtrlCreateButton("Refresh",10,370,150,20)
$Button_02=GUICtrlCreateButton("Exit",660,370,150,20)
$Lv=GUICtrlGetHandle(GUICtrlCreateListView("",10,50,800,315, BitOR($LVS_REPORT,$LVS_SHOWSELALWAYS),$WS_EX_CLIENTEDGE))
_GUICtrlListView_SetExtendedListViewStyle($Lv,BitOR($LVS_EX_GRIDLINES,$LVS_EX_FULLROWSELECT,$LVS_EX_SUBITEMIMAGES))
_GUICtrlListView_AddColumn($Lv, "", 20)
_GUICtrlListView_AddColumn($Lv, "SSID",90,2)
_GUICtrlListView_AddColumn($Lv, "Network type",100,2)
_GUICtrlListView_AddColumn($Lv, "Authentication",100,2)
_GUICtrlListView_AddColumn($Lv, "Encryption",90,2);
_GUICtrlListView_AddColumn($Lv, "BSSID",80,2)
_GUICtrlListView_AddColumn($Lv, "Signal",60,2)
_GUICtrlListView_AddColumn($Lv, "Radio type",95,2)
_GUICtrlListView_AddColumn($Lv, "Channel",80,2)
GUICtrlSetBkColor($Label_01, $GUI_BKCOLOR_TRANSPARENT)
GUICtrlSetOnEvent($Button_01,"_Refresh")
GUICtrlSetOnEvent($Button_02,"_EXIT")
GUISetOnEvent($GUI_EVENT_CLOSE,"_EXIT")
GUISetOnEvent($GUI_EVENT_MINIMIZE,"_MINIMIZE")
GUISetOnEvent($GUI_EVENT_RESTORE,"_RESTORE")
GUISetState()
GUISetState(@SW_SHOW)
Func tt()
$foo = Run(@ComSpec& " /c " & "netsh wlan show networks mode=bssid", @SystemDir, @SW_HIDE, $STDERR_CHILD + $STDOUT_CHILD)
ProcessWaitClose($foo)
$line = StdoutRead($foo)
$a_Arr1=StringRegExp($line,"(?:SSID\s?\d+\s?:\s*)([\w.]+)",3)
$a_Arr2=StringRegExp($line,"(?:Authentication\s*:\s*)([\w.]+.*)",3)
$a_Arr3=StringRegExp($line,"(?:Encryption\s*:\s*)([\w.]+.*)",3)
$a_Arr4=StringRegExp($line,"(?:Network type\s*:\s*)([\w.]+)",3)
$a_Arr5=StringRegExp($line,"(?:Radio type\s*:\s*)([\w.]+)",3)
$a_Arr6=StringRegExp($line,"(?:Channel\s*:\s*)([\w.]+)",3)
$a_Arr7=StringRegExp($line,"(?:Signal\s*:\s*)([\w.]+\%)",3)
$a_Arr8=StringRegExp($line,"(?:BSSID\s?)([\d]+)",3)
for $i = 0 to UBound($a_Arr1) - 1
_GUICtrlListView_AddItem($Lv,$x+1,$x)
_GUICtrlListView_AddSubItem($Lv,$x,$a_Arr1[$i],1)
_GUICtrlListView_AddSubItem($Lv,$x,$a_Arr3[$i],4)
_GUICtrlListView_AddSubItem($Lv,$x,$a_Arr2[$i],3)
_GUICtrlListView_AddSubItem($Lv,$x,$a_Arr4[$i],2)
$x=$x+1
next
For $n=0 To UBound($a_Arr8) - 1
If $a_Arr8[$n] =2 And$a_Arr8[$n+1] <>3 Then
_GUICtrlListView_InsertItem($Lv,"",$n)
EndIf
If $a_Arr8[$n] =2 And $a_Arr8[$n+1] = 3 Then
_GUICtrlListView_InsertItem($Lv,"",$n)
_GUICtrlListView_InsertItem($Lv,"",$n+1)
EndIf
Next
for $j = 0 to UBound($a_Arr8) - 1
_GUICtrlListView_AddSubItem($Lv,$m,$a_Arr5[$j],7)
_GUICtrlListView_AddSubItem($Lv,$m,$a_Arr6[$j],8)
_GUICtrlListView_AddSubItem($Lv,$m,$a_Arr7[$j],6)
_GUICtrlListView_AddSubItem($Lv,$m,$a_Arr8[$j],5)
$m=$m+1
Next
EndFunc
While 1
sleep(10)
WEnd
func _EXIT()
Exit
EndFunc
func _MINIMIZE()
GUISetState(@SW_MINIMIZE)
EndFunc
func _RESTORE()
GUISetState(@SW_RESTORE)
EndFunc
func _Refresh()
;_GUICtrlListView_CancelEditLabel($Lv)
;Global Const $WM_SETREDRAW = 0xB
;_SendMessage($Lv,$WM_SETREDRAW,0,0)
;GUICtrlSendMsg($Lv, $LVM_DELETEALLITEMS, 0, 0)
;_GUICtrlListView_DeleteAllItems($Lv)
;_GUICtrlListView_RegisterSortCallBack($Lv)
;_GUICtrlListView_EndUpdate($Lv)
_GUICtrlListView_DeleteAllItems($Lv)
tt()
_GUICtrlListView_EndUpdate($Lv)
;tt()
;Next
EndFunc
贴上源码~~
代码里$Lv=GUICtrlGetHandle(GUICtrlCreateListView("",10,50,800,315, BitOR($LVS_REPORT,$LVS_SHOWSELALWAYS),$WS_EX_CLIENTEDGE))不就是你说的~~ 回复 11# pdp320921
仿照改的
#include <Constants.au3>
#include <GuiListView.au3>
Opt("GUIOnEventMode", 1)
$GUI = GUICreate("Wireless Network Connection", 820, 400)
GUISetOnEvent(-3, "GuiClick")
$Label_01 = GUICtrlCreateLabel("Wireless Network Connection", 10, 20, 800, 40, 0x01)
$Button_01 = GUICtrlCreateButton("Refresh", 10, 370, 150, 20)
GUICtrlSetOnEvent(-1, "GuiClick")
$Button_02 = GUICtrlCreateButton("Exit", 660, 370, 150, 20)
GUICtrlSetOnEvent(-1, "GuiClick")
$Lv = GUICtrlCreateListView("", 10, 50, 800, 315, BitOR($LVS_EDITLABELS, $LVS_REPORT))
_GUICtrlListView_SetExtendedListViewStyle($Lv, $LVS_EX_GRIDLINES)
_GUICtrlListView_InsertColumn($Lv, 0, "", 20)
_GUICtrlListView_InsertColumn($Lv, 1, "SSID", 90)
_GUICtrlListView_InsertColumn($Lv, 2, "身份验证", 100)
_GUICtrlListView_InsertColumn($Lv, 3, "加密", 100)
_GUICtrlListView_InsertColumn($Lv, 4, "BSSID", 90)
_GUICtrlListView_InsertColumn($Lv, 5, "信号", 80)
_GUICtrlListView_InsertColumn($Lv, 6, "无线电类型", 60)
_GUICtrlListView_InsertColumn($Lv, 7, "频道", 95)
GUISetState()
tt()
While 1
Sleep(100)
WEnd
Func GuiClick()
Switch @GUI_CtrlId
Case -3, $Button_02
Exit
Case $Button_01
_GUICtrlListView_DeleteAllItems($Lv)
_GUICtrlListView_EndUpdate($Lv)
tt()
_GUICtrlListView_EndUpdate($Lv)
EndSwitch
EndFunc ;==>GuiClick
Func tt()
$foo = Run(@ComSpec & " /c " & "netsh wlan show networks mode=bssid", @SystemDir, @SW_HIDE, $STDERR_CHILD + $STDOUT_CHILD)
ProcessWaitClose($foo)
$line = StdoutRead($foo)
$SR = StringRegExp($line, "SSID\s?\d+\s?:\s?([^\r]+)[^:]+:\s?[^\r]+[^:]+:\s?([^\r]+)[^:]+:\s?([^\r]+)[^:]+:\s?([^\r]+)[^:]+:\s?([^\r]+)[^:]+:\s?([^\r]+)[^:]+:\s?([^\r]+)", 3)
For $i = 0 To UBound($SR) - 1 Step 7
GUICtrlCreateListViewItem(Floor($i / 7) & "|" & $SR[$i] & "|" & $SR[$i + 1] & "|" & $SR[$i + 2] & "|" & $SR[$i + 3] & "|" & $SR[$i + 4] & "|" & $SR[$i + 5] & "|" & $SR[$i + 6], $Lv)
Next
EndFunc 回复 11# pdp320921
没有无线网卡,就只做功能测试。
根据12楼改的.
#include <Constants.au3>
#include <GuiListView.au3>
Opt("GUIOnEventMode", 1)
$GUI = GUICreate("Wireless Network Connection", 820, 400)
GUISetOnEvent(-3, "GuiClick")
$Label_01 = GUICtrlCreateLabel("Wireless Network Connection", 10, 20, 800, 40, 0x01)
$Button_01 = GUICtrlCreateButton("Refresh", 10, 370, 150, 20)
GUICtrlSetOnEvent(-1, "GuiClick")
$Button_02 = GUICtrlCreateButton("Exit", 660, 370, 150, 20)
GUICtrlSetOnEvent(-1, "GuiClick")
$Lv = GUICtrlCreateListView("", 10, 50, 800, 315, BitOR($LVS_EDITLABELS, $LVS_REPORT))
_GUICtrlListView_SetExtendedListViewStyle($Lv, $LVS_EX_GRIDLINES)
_GUICtrlListView_InsertColumn($Lv, 0, "", 20)
_GUICtrlListView_InsertColumn($Lv, 1, "SSID", 90)
_GUICtrlListView_InsertColumn($Lv, 2, "身份验证", 100)
_GUICtrlListView_InsertColumn($Lv, 3, "加密", 100)
_GUICtrlListView_InsertColumn($Lv, 4, "BSSID", 90)
_GUICtrlListView_InsertColumn($Lv, 5, "信号", 80)
_GUICtrlListView_InsertColumn($Lv, 6, "无线电类型", 60)
_GUICtrlListView_InsertColumn($Lv, 7, "频道", 95)
GUISetState()
$ClickTime = 0
For $i = $ClickTime * 10 + 1 To $ClickTime * 10 +9
_Add($Lv,$i)
Next
While 1
Sleep(100)
WEnd
Func GuiClick()
Switch @GUI_CtrlId
Case -3, $Button_02
Exit
Case $Button_01
$ClickTime += 1
_GUICtrlListView_DeleteAllItems(GUICtrlGetHandle($Lv))
_GUICtrlListView_EndUpdate($Lv)
For $i = $ClickTime * 10 + 1 To $ClickTime * 10 +9
_Add($Lv,$i)
Next
_GUICtrlListView_EndUpdate($Lv)
EndSwitch
EndFunc ;==>GuiClick
Func _Add($id,$Test)
Local $Index = _GUICtrlListView_AddItem($id,$Test)
_GUICtrlListView_AddSubItem($id,$Index,$Test,1)
_GUICtrlListView_AddSubItem($id,$Index,$Test,2)
_GUICtrlListView_AddSubItem($id,$Index,$Test,3)
EndFunc 本帖最后由 pdp320921 于 2011-4-12 10:49 编辑
回复 12# shenrenba
感谢回复!
不过你这样好像有漏掉的,如果有的AP开了2个以上的channel(即有2个BSSID,channel,)第二个就被漏掉了~~
我只想在我源代码基础上实现刷新功能~ 本帖最后由 shenrenba 于 2011-4-12 10:48 编辑
回复 13# republican
发现错误没_GUICtrlListView_EndUpdate($Lv) 2次 没begin 跟我一样 直接复制的 没注意看吧{:face (303):}
回复 14# pdp320921
自己根据情况改
页:
[1]
2