[已解决]无法换图标,无法加背景色,求各位大大帮助
本帖最后由 xuanniao110 于 2023-11-3 10:49 编辑代码入下:
#include <GUIConstantsEx.au3>
#include <GuiListView.au3>
#include <GuiImageList.au3>
#include <ListViewConstants.au3>
#include <ButtonConstants.au3>
#include <GuiListView.au3>
#include <ListViewConstants.au3>
#include <GuiImageList.au3>
#include <Array.au3>
#include <GUIConstants.au3>
#PRE_UseX64=n
;数据库定义
Global Const $DBName = "Data.mdb"
Global Const $DBPswd = "answerx"
Dim $array
#region ### START Koda GUI section ### Form=
$Form1 = GUICreate("Form1", 496, 389, 270, 202)
$ListView1 = GUICtrlCreateListView("col1|col2|col3|co4|co5|co6", 16, 16, 466, 302)
$iStyle = BitOR($LVS_EX_FULLROWSELECT, $LVS_EX_GRIDLINES, $WS_EX_CLIENTEDGE, $LVS_EX_SUBITEMIMAGES, $LVS_EX_DOUBLEBUFFER)
_GUICtrlListView_SetExtendedListViewStyle($ListView1, $iStyle)
; 加载图像
$hImage = _GUIImageList_Create()
_GUIImageList_AddIcon($hImage, @SystemDir & "\shell32.dll", 110) ;0
_GUIImageList_AddIcon($hImage, @SystemDir & "\shell32.dll", 131);1
_GUICtrlListView_SetImageList($ListView1, $hImage, 1)
$ListViewButton = GUICtrlCreateContextMenu($ListView1)
$ListBut_1 = GUICtrlCreateMenuItem("换图标", $ListViewButton)
$ListBut_2 = GUICtrlCreateMenuItem("Eixt", $ListViewButton)
GUISetState(@SW_SHOW)
#endregion ### END Koda GUI section ###
$addfld = ObjCreate("ADODB.Connection")
$addfld.Open("Provider=Microsoft.Jet.OLEDB.4.0; Data Source=" & $DBName & ";Jet Oledb:Database Password=" & $DBPswd)
$RS = ObjCreate("ADODB.Recordset")
$RS.ActiveConnection = $addfld
$RS.open("SELECT COUNT(*) FROM Radmin");
While (Not $RS.eof And Not $RS.bof);
$P = $RS.Fields(0).value
$RS.movenext;
WEnd;
$RS.close;
Dim $APP[$P]
$i = 0
$addfld = ObjCreate("ADODB.Connection")
$addfld.Open("Provider=Microsoft.Jet.OLEDB.4.0; Data Source=" & $DBName & ";Jet Oledb:Database Password=" & $DBPswd)
$RS = ObjCreate("ADODB.Recordset")
$RS.ActiveConnection = $addfld
$RS.open("SELECT* fromRadmin");
While (Not $RS.eof And Not $RS.bof);
$APP[$i] = $RS.Fields(0).value
$APP[$i] = $RS.Fields(1).value
$APP[$i] = $RS.Fields(2).value
$APP[$i] = $RS.Fields(3).value
$APP[$i] = $RS.Fields(4).value
$APP[$i] = $RS.Fields(5).value
$i = $i + 1
$RS.movenext;
WEnd;
$RS.close;
For $x = 0 To $P - 1
_GUICtrlListView_AddItem($ListView1, $APP[$x],0, -1)
_GUICtrlListView_AddSubItem($ListView1, $x ,$APP[$x], 1, 0)
_GUICtrlListView_AddSubItem($ListView1, $x, $APP[$x], 2, -1)
_GUICtrlListView_AddSubItem($ListView1, $x, $APP[$x], 3, -1)
_GUICtrlListView_AddSubItem($ListView1, $x, $APP[$x], 4, -1)
_GUICtrlListView_AddSubItem($ListView1, $x, $APP[$x], 5, -1)
Next
While 1
$nMsg = GUIGetMsg()
Switch $nMsg
Case $GUI_EVENT_CLOSE, $ListBut_2
Exit
Case $ListBut_1
GUICtrlSetImage(GUICtrlRead($ListView1), @SystemDir & '\shell32.dll', 131)
GUICtrlSetBkColor(GUICtrlRead($ListView1), 0x2E8B57);更新颜色
ConsoleWrite(GUICtrlRead($ListView1)&@CRLF)
EndSwitch
WEnd数据库文件在这里
给你的建意,用以下几个函数
_GUIImageList_Add
_GUICtrlListView_SetItemImage
_GUICtrlListView_GetSelectionMark
我记得,MDB好像可以打包文件到数据库 f4李文杨 发表于 2023-10-27 14:06
给你的建意,用以下几个函数
_GUIImageList_Add
_GUICtrlListView_SetItemImage
大哥把你以前搞的 贴出来学习下吧 本帖最后由 f4李文杨 于 2023-10-28 00:32 编辑
xuanniao110 发表于 2023-10-27 21:10
大哥把你以前搞的 贴出来学习下吧
GUICtrlSetImage(_GUICtrlListView_GetItemParam($ListView1, $G0), @ScriptDir & "\ICO\9.ico")
用这个吧!
#include <GUIConstantsEx.au3>
#include <GuiListView.au3>
#include <GuiImageList.au3>
#include <ListViewConstants.au3>
#include <ButtonConstants.au3>
#include <GuiListView.au3>
#include <ListViewConstants.au3>
#include <GuiImageList.au3>
#include <Array.au3>
#include <GUIConstants.au3>
#PRE_UseX64=n
;数据库定义
Global Const $DBName = "Data.mdb"
Global Const $DBPswd = "answerx"
Dim $array
#region ### START Koda GUI section ### Form=
$Form1 = GUICreate("Form1", 496, 389, 270, 202)
$ListView1 = GUICtrlCreateListView("col1|col2|col3|co4|co5|co6", 16, 16, 466, 302)
$iStyle = BitOR($LVS_EX_FULLROWSELECT, $LVS_EX_GRIDLINES, $WS_EX_CLIENTEDGE, $LVS_EX_SUBITEMIMAGES, $LVS_EX_DOUBLEBUFFER)
_GUICtrlListView_SetExtendedListViewStyle($ListView1, $iStyle)
; 加载图像
$hImage = _GUIImageList_Create()
_GUIImageList_AddIcon($hImage, @SystemDir & "\shell32.dll", 110) ;0
_GUIImageList_AddIcon($hImage, @SystemDir & "\shell32.dll", 131);1
_GUICtrlListView_SetImageList($ListView1, $hImage, 1)
$ListViewButton = GUICtrlCreateContextMenu($ListView1)
$ListBut_1 = GUICtrlCreateMenuItem("换图标", $ListViewButton)
$ListBut_2 = GUICtrlCreateMenuItem("Eixt", $ListViewButton)
GUISetState(@SW_SHOW)
#endregion ### END Koda GUI section ###
$addfld = ObjCreate("ADODB.Connection")
$addfld.Open("Provider=Microsoft.Jet.OLEDB.4.0; Data Source=" & $DBName & ";Jet Oledb:Database Password=" & $DBPswd)
$RS = ObjCreate("ADODB.Recordset")
$RS.ActiveConnection = $addfld
$RS.open("SELECT COUNT(*) FROM Radmin");
While (Not $RS.eof And Not $RS.bof);
$P = $RS.Fields(0).value
$RS.movenext;
WEnd;
$RS.close;
Dim $APP[$P]
$i = 0
$addfld = ObjCreate("ADODB.Connection")
$addfld.Open("Provider=Microsoft.Jet.OLEDB.4.0; Data Source=" & $DBName & ";Jet Oledb:Database Password=" & $DBPswd)
$RS = ObjCreate("ADODB.Recordset")
$RS.ActiveConnection = $addfld
$RS.open("SELECT* fromRadmin");
While (Not $RS.eof And Not $RS.bof);
$APP[$i] = $RS.Fields(0).value
$APP[$i] = $RS.Fields(1).value
$APP[$i] = $RS.Fields(2).value
$APP[$i] = $RS.Fields(3).value
$APP[$i] = $RS.Fields(4).value
$APP[$i] = $RS.Fields(5).value
$i = $i + 1
$RS.movenext;
WEnd;
$RS.close;
For $x = 0 To $P - 1
_GUICtrlListView_AddItem($ListView1, $APP[$x],0, -1)
_GUICtrlListView_AddSubItem($ListView1, $x ,$APP[$x], 1, 0)
_GUICtrlListView_AddSubItem($ListView1, $x, $APP[$x], 2, -1)
_GUICtrlListView_AddSubItem($ListView1, $x, $APP[$x], 3, -1)
_GUICtrlListView_AddSubItem($ListView1, $x, $APP[$x], 4, -1)
_GUICtrlListView_AddSubItem($ListView1, $x, $APP[$x], 5, -1)
Next
While 1
$nMsg = GUIGetMsg()
Switch $nMsg
Case $GUI_EVENT_CLOSE, $ListBut_2
Exit
Case $ListBut_1
;GUICtrlSetImage(GUICtrlRead($ListView1), @SystemDir & '\shell32.dll', 131)
GUICtrlSetImage(_GUICtrlListView_GetItemParam($ListView1, _GUICtrlListView_GetSelectionMark($ListView1)), @SystemDir & '\shell32.dll', 131)
GUICtrlSetBkColor(GUICtrlRead($ListView1), 0x2E8B57);更新颜色
ConsoleWrite(GUICtrlRead($ListView1)&@CRLF)
EndSwitch
WEnd
本帖最后由 chzj589 于 2023-10-28 20:59 编辑
应该是重新读取吧
While 1
$nMsg = GUIGetMsg()
Switch $nMsg
Case $GUI_EVENT_CLOSE, $ListBut_2
Exit
Case $ListBut_1
GUICtrlSendMsg($ListView1, 4105, 0, 0)
MsgBox(0, "读取", "重新读取", 1)
$hImage1 = _GUIImageList_Create(20, 20, 5, 3, 3)
_GUIImageList_AddIcon($hImage1, "shell32.dll", 39, True)
_GUIImageList_AddIcon($hImage1, "shell32.dll", 137, True)
_GUIImageList_AddIcon($hImage1, "shell32.dll", 4, True)
_GUIImageList_AddIcon($hImage1, "shell32.dll", 40, True)
_GUICtrlListView_SetImageList($hListview1, $hImage1, 1)
_GUICtrlListView_SetTextBkColor($ListView1, $CLR_MONEYGREEN);0xFFE0C0);
;_GUICtrlListView_AddArray($ListView1, $APP)
For $x = 0 To $P - 1
_GUICtrlListView_AddItem($ListView1, $APP[$x], 0, -1)
_GUICtrlListView_AddSubItem($ListView1, $x, $APP[$x], 1, 0)
_GUICtrlListView_AddSubItem($ListView1, $x, $APP[$x], 2, 1)
_GUICtrlListView_AddSubItem($ListView1, $x, $APP[$x], 3, 2)
_GUICtrlListView_AddSubItem($ListView1, $x, $APP[$x], 4, 3)
_GUICtrlListView_AddSubItem($ListView1, $x, $APP[$x], 5, -1)
Next
EndSwitch
WEnd
f4李文杨 发表于 2023-10-28 00:28
GUICtrlSetImage(_GUICtrlListView_GetItemParam($ListView1, $G0), @ScriptDir & "\ICO\9.ico")
用这个 ...
大哥我试过了你这代码确实还是不能改图标和改背景色 chzj589 发表于 2023-10-28 16:59
应该是重新读取吧
重新读取是一种方法但是我程序是循环TCP判断判断通 才更换那一列的图标以及更换背景颜色,所以重新读取不可行
代码入下:
#NoTrayIcon
#PRE_UseX64=n
#include <ButtonConstants.au3>
#include <ComboConstants.au3>
#include <GuiStatusBar.au3>
#include <GuiListView.au3>
#include <ListViewConstants.au3>
#include <StaticConstants.au3>
#include <WindowsConstants.au3>
#include <WinAPIEx.au3>
#include <EditConstants.au3>
#include <GuiIPAddress.au3>
#include <GuiImageList.au3>
#include <GuiEdit.au3>
#include <GUIComboBox.au3>
#include <GuiConstantsEx.au3>
#include <Array.au3>
#include <GuiButton.au3>
#include <ModernMenuRaw.au3>
#include <GUIConstants.au3>
;切换程序执行目录为脚本目录
FileChangeDir(@ScriptDir)
;防止程序多启
$version = @ScriptName
If WinExists($version) Then
Exit
EndIf
AutoItWinSetTitle($version)
Local $ver = FileGetVersion($version)
;数据库定义
Global Const $DBName = "Data.mdb"
Global Const $DBPswd = "answerx"
#Region ### START Koda GUI section ### Form=E:\文件夹归类\AU3文档\KXF文件\Radmin自动输入密码.kxf
$Form1 = GUICreate("Radmin远程小工具", 503, 698, 702, 187)
$Pic1 = GUICtrlCreatePic(@ScriptDir & "\ad.bmp", 0, 0, 500, 60)
$Group1 = GUICtrlCreateGroup("", 3, 60, 497, 41)
;~ _WinAPI_SetThemeAppProperties(1)
$Button5 = GUICtrlCreateButton("在线检测", 390, 71, 70, 25, $BS_FLAT)
_SetIcon(-1, 'Radmin.exe', 13, 0, 16, 16)
GUICtrlCreateGroup("", -99, -99, 1, 1)
$ListView1 = GUICtrlCreateListView("", 3, 104, 497, 566)
GUICtrlSetBkColor(-1, 0xB5B5B5)
; 加载图像
$hImage = _GUIImageList_Create(16,16,5,2)
;~ _GUIImageList_AddIcon($hImage, "radmin.exe", 1) ;0
_GUIImageList_AddIcon($hImage, "shell32.dll", 39, True)
;~ _GUIImageList_AddIcon($hImage, "radmin.exe", 11);1
_GUIImageList_AddIcon($hImage, "shell32.dll", 137, True)
_GUICtrlListView_SetImageList($ListView1, $hImage, 1)
_GUICtrlListView_AddColumn($ListView1, "ID", 0)
_GUICtrlListView_AddColumn($ListView1, "名称", 95)
_GUICtrlListView_AddColumn($ListView1, "IP地址", 120)
_GUICtrlListView_AddColumn($ListView1, "端口", 85)
_GUICtrlListView_AddColumn($ListView1, "用户名", 82)
_GUICtrlListView_AddColumn($ListView1, "密码", 63)
_GUICtrlListView_AddColumn($ListView1, "在线", 47)
$iStyle = BitOR($LVS_EX_FULLROWSELECT, $LVS_EX_GRIDLINES, $WS_EX_CLIENTEDGE, $LVS_EX_SUBITEMIMAGES, $LVS_EX_DOUBLEBUFFER)
_GUICtrlListView_SetExtendedListViewStyle($ListView1, $iStyle)
Dim $RC_menu, $RC0, $RC1, $RC2, $RC3, $RC4
$RC_menu = GUICtrlCreateContextMenu($ListView1)
$RC0 = _GUICtrlCreateODMenuItem("完全控制", $RC_menu, "Radmin.exe", -16)
GUICtrlCreateMenuItem("", $RC_menu)
$RC1 = _GUICtrlCreateODMenuItem("添加连接", $RC_menu, "Radmin.exe", -9)
$RC2 = _GUICtrlCreateODMenuItem("编辑连接", $RC_menu, "Radmin.exe", -10)
$RC3 = _GUICtrlCreateODMenuItem("删除连接", $RC_menu, "Radmin.exe", -8)
GUICtrlCreateMenuItem("", $RC_menu)
$RC4 = _GUICtrlCreateODMenuItem("是否在线", $RC_menu, "Radmin.exe", -14)
$StatusBar1 = _GUICtrlStatusBar_Create($Form1)
Dim $StatusBar1_PartsWidth =
_GUICtrlStatusBar_SetParts($StatusBar1, $StatusBar1_PartsWidth)
_GUICtrlStatusBar_SetText($StatusBar1, "", 0)
_GUICtrlStatusBar_SetText($StatusBar1, "", 1)
_GUICtrlStatusBar_SetText($StatusBar1, "在线", 2)
_GUICtrlStatusBar_SetText($StatusBar1, @TAB & "", 3)
_GUICtrlStatusBar_SetText($StatusBar1, "离线", 4)
_GUICtrlStatusBar_SetText($StatusBar1, @TAB & "", 5)
GUISetState(@SW_SHOW)
updata()
While 1
$Msg = GUIGetMsg(1)
Select
Case $Msg = $GUI_EVENT_CLOSE And $Msg = $Form1;关闭1窗口
Exit
Case $Msg = $Button5
updata()
_GUICtrlStatusBar_SetText($StatusBar1, "", 3)
_GUICtrlStatusBar_SetText($StatusBar1, "", 5)
_GUICtrlStatusBar_SetText($StatusBar1, "正在检测设备通讯……", 0)
$Index = Number(_GUICtrlListView_GetSelectedIndices($ListView1))
$cs = _GUICtrlListView_GetItemCount($ListView1)
$i = GUICtrlRead($StatusBar1, 1)
For $i = 0 To $cs - 1
$z = _GUICtrlStatusBar_GetText($StatusBar1, 3)
$m = _GUICtrlStatusBar_GetText($StatusBar1, 5)
$x = $z + 1
$y = $m + 1
$add = _GUICtrlListView_GetItemText($ListView1, $i, 2)
$dkh = _GUICtrlListView_GetItemText($ListView1, $i, 3)
_GUICtrlStatusBar_SetText($StatusBar1, $i, 1)
TCPStartup() ; 开始 TCP 服务
Local $socket = TCPConnect($add, $dkh)
If $socket = -1 Then
TCPShutdown() ; 停止 TCP 服务
_GUICtrlListView_SetItemText($ListView1, $i, "×", 6)
_GUICtrlStatusBar_SetText($StatusBar1, @TAB & $y, 5)
Else
TCPShutdown() ; 停止 TCP 服务
_GUICtrlListView_SetItemText($ListView1, $i, "√", 6)
;------------------------------------------------------------------------------------------------------------------------------
;此处应该是更换图标
GUICtrlSetImage($i,"", "shell32.dll", 137)
;此处应该是更换背景颜色
GUICtrlSetBkColor(_GUICtrlListView_GetItemParam($ListView1, $i), 0x2E8B57);更新颜色
;-------------------------------------------------------------------------------------------------------------------------------
_GUICtrlStatusBar_SetText($StatusBar1, @TAB & $x, 3)
EndIf
Next
_GUICtrlStatusBar_SetText($StatusBar1, "总共" & $cs & "台设备", 0)
_GUICtrlStatusBar_SetText($StatusBar1, "", 1)
EndSelect
WEnd
Func updata()
GUICtrlSendMsg($ListView1, $LVM_DELETEALLITEMS, 0, 0)
$addfld = ObjCreate("ADODB.Connection")
$addfld.Open("Provider=Microsoft.Jet.OLEDB.4.0; Data Source=" & $DBName & ";Jet Oledb:Database Password=" & $DBPswd)
$RS = ObjCreate("ADODB.Recordset")
$RS.ActiveConnection = $addfld
$RS.open("SELECT COUNT(*) FROM Radmin");
While (Not $RS.eof And Not $RS.bof);
$P = $RS.Fields(0).value
$RS.movenext;
WEnd;
$RS.close;
Dim $APP[$P]
$i = 0
$addfld = ObjCreate("ADODB.Connection")
$addfld.Open("Provider=Microsoft.Jet.OLEDB.4.0; Data Source=" & $DBName & ";Jet Oledb:Database Password=" & $DBPswd)
$RS = ObjCreate("ADODB.Recordset")
$RS.ActiveConnection = $addfld
$RS.open("SELECT* fromRadmin");
While (Not $RS.eof And Not $RS.bof);
$APP[$i] = $RS.Fields(0).value
$APP[$i] = $RS.Fields(1).value
$APP[$i] = $RS.Fields(2).value
$APP[$i] = $RS.Fields(3).value
$APP[$i] = $RS.Fields(4).value
$APP[$i] = $RS.Fields(5).value
$i = $i + 1
$RS.movenext;
WEnd;
$RS.close;
For $x = 0 To $P - 1
_GUICtrlListView_AddItem($ListView1, $APP[$x], 0, -1)
_GUICtrlListView_AddSubItem($ListView1, $x, $APP[$x], 1, 0)
_GUICtrlListView_AddSubItem($ListView1, $x, $APP[$x], 2, -1)
_GUICtrlListView_AddSubItem($ListView1, $x, $APP[$x], 3, -1)
_GUICtrlListView_AddSubItem($ListView1, $x, $APP[$x], 4, -1)
_GUICtrlListView_AddSubItem($ListView1, $x, "******", 5, -1)
Next
_GUICtrlListView_RegisterSortCallBack($ListView1)
_GUICtrlListView_SortItems($ListView1, 0);以ID排序
_GUICtrlListView_SortItems($ListView1, GUICtrlGetState($ListView1))
_GUICtrlListView_UnRegisterSortCallBack($ListView1)
EndFunc ;==>updata
Func _SetIcon($hWnd, $sFile, $iIndex = 0, $nAlign = 0, $iWidth = 20, $iHeight = 20) ;控件句柄, 图标图像的路径, 图标索引, 图标在控件中的位置, 图标宽度, 图标高度
$hImage1 = _GUIImageList_Create($iWidth, $iHeight, 5, 1, 0) ;创建图像列表控件
_GUIImageList_AddIcon($hImage1, $sFile, $iIndex, True) ;向图像列表添加图标
_GUICtrlButton_SetImageList($hWnd, $hImage1, $nAlign) ;分配一个图像列表到按钮控件,$nAlign 是图标位置参数
EndFunc ;==>_SetIcon
GUICtrlCreateListViewItem xuanniao110 发表于 2023-10-29 10:12
重新读取是一种方法但是我程序是循环TCP判断判断通 才更换那一列的图标以及更换背景颜色,所以重新读 ...
是这个意思?
#AutoIt3Wrapper_UseX64=n
##include <ButtonConstants.au3>
#include <ComboConstants.au3>
#include <GuiStatusBar.au3>
#include <GuiListView.au3>
#include <ListViewConstants.au3>
#include <StaticConstants.au3>
#include <WindowsConstants.au3>
#include <WinAPIEx.au3>
#include <EditConstants.au3>
#include <GuiIPAddress.au3>
#include <GuiImageList.au3>
#include <GuiEdit.au3>
#include <GUIComboBox.au3>
#include <GuiConstantsEx.au3>
#include <Array.au3>
#include <GuiButton.au3>
#include <ModernMenuRaw.au3>
#include <GUIConstants.au3>
#PRE_UseX64=n
;数据库定义
Global Const $DBName = "Data.mdb"
Global Const $DBPswd = "answerx"
Dim $array
Global $data = 10
Global $dataArray[$data]
;常量定义区
Global Const $ODT_LISTVIEW = 102
Global Const $ODA_DRAWENTIRE = 0x1
Global Const $ODA_SELECT = 0x2
Global Const $ODA_FOCUS = 0x4
Global Const $ODS_SELECTED = 0x0001
#Region ### START Koda GUI section ### Form=
$Form1 = GUICreate("Form1", 603, 698, 270, -1)
$Button5 = GUICtrlCreateButton("在线检测", 390, 71, 70, 25);, $BS_FLAT)
;$ListView1 = GUICtrlCreateListView("col1|col2 |col3|co4|co5|co6", 16, 16, 466, 302);, BitOR($LVS_REPORT, $LVS_OWNERDRAWFIXED, $LVS_OWNERDATA));两个自绘属性都加上!
;Dim $hListview1 = GUICtrlGetHandle(-1)
;$iStyle = BitOR($LVS_EX_FULLROWSELECT, $LVS_EX_GRIDLINES, $WS_EX_CLIENTEDGE, $LVS_EX_SUBITEMIMAGES, $LVS_EX_DOUBLEBUFFER)
;_GUICtrlListView_SetExtendedListViewStyle($ListView1, $iStyle)
;_GUICtrlListView_SetItemCount($ListView1, UBound($dataArray))
$Listview1 = GUICtrlCreateListView("", 3, 104, 597, 566, BitOR($LVS_REPORT, $LVS_SHOWSELALWAYS))
Dim $hListview1 = GUICtrlGetHandle(-1)
GUICtrlSetBkColor(-1, 0xB5B5B5)
$iStyle = BitOR($LVS_EX_FULLROWSELECT, $LVS_EX_GRIDLINES, $WS_EX_CLIENTEDGE, $LVS_EX_SUBITEMIMAGES, $LVS_EX_DOUBLEBUFFER)
_GUICtrlListView_SetExtendedListViewStyle($Listview1, $iStyle)
; 设置颜色
_GUICtrlListView_SetTextBkColor($Listview1, 0xFFE0C0);$CLR_MONEYGREEN)
_GUICtrlListView_SetBkColor($Listview1, 14675183);$CLR_MONEYGREEN)
_GUICtrlListView_AddColumn($Listview1, "ID", 0)
_GUICtrlListView_AddColumn($Listview1, "名称", 95)
_GUICtrlListView_AddColumn($Listview1, "IP地址", 120)
_GUICtrlListView_AddColumn($Listview1, "端口", 85)
_GUICtrlListView_AddColumn($Listview1, "用户名", 82)
_GUICtrlListView_AddColumn($Listview1, "密码", 63)
_GUICtrlListView_AddColumn($Listview1, "在线", 47)
; 加载图像
$hImage = _GUIImageList_Create()
_GUIImageList_AddIcon($hImage, @SystemDir & "\shell32.dll", 110) ;0
_GUIImageList_AddIcon($hImage, @SystemDir & "\shell32.dll", 131);1
_GUICtrlListView_SetImageList($Listview1, $hImage, 1)
Dim $RC_menu, $RC0, $RC1, $RC2, $RC3, $RC4
$RC_menu = GUICtrlCreateContextMenu($Listview1)
$RC0 = _GUICtrlCreateODMenuItem("完全控制", $RC_menu, "Radmin.exe", -16)
GUICtrlCreateMenuItem("", $RC_menu)
$RC1 = _GUICtrlCreateODMenuItem("添加连接", $RC_menu, "Radmin.exe", -9)
$RC2 = _GUICtrlCreateODMenuItem("编辑连接", $RC_menu, "Radmin.exe", -10)
$RC3 = _GUICtrlCreateODMenuItem("删除连接", $RC_menu, "Radmin.exe", -8)
GUICtrlCreateMenuItem("", $RC_menu)
$RC4 = _GUICtrlCreateODMenuItem("是否在线", $RC_menu, "Radmin.exe", -14)
$StatusBar1 = _GUICtrlStatusBar_Create($Form1)
Dim $StatusBar1_PartsWidth =
_GUICtrlStatusBar_SetParts($StatusBar1, $StatusBar1_PartsWidth)
_GUICtrlStatusBar_SetText($StatusBar1, "", 0)
_GUICtrlStatusBar_SetText($StatusBar1, "", 1)
_GUICtrlStatusBar_SetText($StatusBar1, "在线", 2)
_GUICtrlStatusBar_SetText($StatusBar1, @TAB & "", 3)
_GUICtrlStatusBar_SetText($StatusBar1, "离线", 4)
_GUICtrlStatusBar_SetText($StatusBar1, @TAB & "", 5)
GUISetState(@SW_SHOW)
updata()
GUIRegisterMsg($WM_NOTIFY, "WM_NOTIFY")
While 1
$nMsg = GUIGetMsg()
Switch $nMsg
Case $GUI_EVENT_CLOSE;, $ListBut_2
Exit
Case $Button5
updata()
_GUICtrlStatusBar_SetText($StatusBar1, "", 3)
_GUICtrlStatusBar_SetText($StatusBar1, "", 5)
_GUICtrlStatusBar_SetText($StatusBar1, "正在检测设备通讯……", 0)
$index = Number(_GUICtrlListView_GetSelectedIndices($Listview1))
$cs = _GUICtrlListView_GetItemCount($Listview1)
$i = GUICtrlRead($StatusBar1, 1)
For $i = 0 To $cs - 1
$z = _GUICtrlStatusBar_GetText($StatusBar1, 3)
$m = _GUICtrlStatusBar_GetText($StatusBar1, 5)
$x = $z + 1
$y = $m + 1
$add = _GUICtrlListView_GetItemText($Listview1, $i, 2)
$dkh = _GUICtrlListView_GetItemText($Listview1, $i, 3)
_GUICtrlStatusBar_SetText($StatusBar1, $i, 1)
TCPStartup() ; 开始 TCP 服务
Local $socket = TCPConnect($add, $dkh)
If $socket = -1 Then
TCPShutdown() ; 停止 TCP 服务
_GUICtrlListView_SetItemText($Listview1, $i, "×", 6)
_GUICtrlStatusBar_SetText($StatusBar1, @TAB & $y, 5)
Else
TCPShutdown() ; 停止 TCP 服务
_GUICtrlListView_SetItemText($Listview1, $i, "√", 6)
;------------------------------------------------------------------------------------------------------------------------------
;此处应该是更换图标
GUICtrlSetImage($i, "", "shell32.dll", 137)
;此处应该是更换背景颜色
GUICtrlSetBkColor(_GUICtrlListView_GetItemParam($Listview1, $i), 0x2E8B57);更新颜色
;-------------------------------------------------------------------------------------------------------------------------------
_GUICtrlStatusBar_SetText($StatusBar1, @TAB & $x, 3)
EndIf
Next
_GUICtrlStatusBar_SetText($StatusBar1, "总共" & $cs & "台设备", 0)
_GUICtrlStatusBar_SetText($StatusBar1, "", 1)
EndSwitch
WEnd
Func updata()
GUICtrlSendMsg($Listview1, $LVM_DELETEALLITEMS, 0, 0)
$addfld = ObjCreate("ADODB.Connection")
$addfld.Open("Provider=Microsoft.Jet.OLEDB.4.0; Data Source=" & $DBName & ";Jet Oledb:Database Password=" & $DBPswd)
$RS = ObjCreate("ADODB.Recordset")
$RS.ActiveConnection = $addfld
$RS.open("SELECT COUNT(*) FROM Radmin");
While (Not $RS.eof And Not $RS.bof);
$P = $RS.Fields(0).value
$RS.movenext;
WEnd;
$RS.close;
Dim $APP[$P]
$i = 0
$addfld = ObjCreate("ADODB.Connection")
$addfld.Open("Provider=Microsoft.Jet.OLEDB.4.0; Data Source=" & $DBName & ";Jet Oledb:Database Password=" & $DBPswd)
$RS = ObjCreate("ADODB.Recordset")
$RS.ActiveConnection = $addfld
$RS.open("SELECT* fromRadmin");
While (Not $RS.eof And Not $RS.bof);
$APP[$i] = $RS.Fields(0).value
$APP[$i] = $RS.Fields(1).value
$APP[$i] = $RS.Fields(2).value
$APP[$i] = $RS.Fields(3).value
$APP[$i] = $RS.Fields(4).value
$APP[$i] = $RS.Fields(5).value
$i = $i + 1
$RS.movenext;
WEnd;
$RS.close;
For $x = 0 To $P - 1
_GUICtrlListView_AddItem($Listview1, $APP[$x], 0, -1)
_GUICtrlListView_AddSubItem($Listview1, $x, $APP[$x], 1, 0)
_GUICtrlListView_AddSubItem($Listview1, $x, $APP[$x], 2, -1)
_GUICtrlListView_AddSubItem($Listview1, $x, $APP[$x], 3, -1)
_GUICtrlListView_AddSubItem($Listview1, $x, $APP[$x], 4, -1)
_GUICtrlListView_AddSubItem($Listview1, $x, "******", 5, -1)
Next
_GUICtrlListView_RegisterSortCallBack($Listview1)
_GUICtrlListView_SortItems($Listview1, 0);以ID排序
_GUICtrlListView_SortItems($Listview1, GUICtrlGetState($Listview1))
_GUICtrlListView_UnRegisterSortCallBack($Listview1)
EndFunc ;==>updata
Func _SetIcon($hWnd, $sFile, $iIndex = 0, $nAlign = 0, $iWidth = 20, $iHeight = 20) ;控件句柄, 图标图像的路径, 图标索引, 图标在控件中的位置, 图标宽度, 图标高度
$hImage1 = _GUIImageList_Create($iWidth, $iHeight, 5, 1, 0) ;创建图像列表控件
_GUIImageList_AddIcon($hImage1, $sFile, $iIndex, True) ;向图像列表添加图标
_GUICtrlButton_SetImageList($hWnd, $hImage1, $nAlign) ;分配一个图像列表到按钮控件,$nAlign 是图标位置参数
EndFunc ;==>_SetIcon
Func WM_NOTIFY($hWnd, $iMsg, $iwParam, $ilParam)
#forceref $hWnd, $iMsg, $iwParam
Local $iColumn = GUICtrlGetState($Listview1) + 1
;Local $SList1 = GUICtrlRead($BInput1)
Local $hWndListView1 = $hListview1, $iColumn = 1
If Not IsHWnd($hListview1) Then $hWndListView1 = GUICtrlGetHandle($hListview1)
Local $tNMHDR = DllStructCreate($tagNMHDR, $ilParam)
Local $hWndFrom = HWnd(DllStructGetData($tNMHDR, 'hWndFrom'))
Local $iCode = DllStructGetData($tNMHDR, 'Code')
Switch $hWndFrom
Case $hListview1;$hWndListView1;$hListView1
Switch $iCode
Case $NM_CLICK ;= -2
Global $aHit = _GUICtrlListView_SubItemHitTest($hListview1)
Local $tInfo = DllStructCreate($tagNMITEMACTIVATE, $ilParam)
Local $iIndex = DllStructGetData($tInfo, 'Index')
Local $iSub = DllStructGetData($tInfo, 'SubItem')
$index1 = _GUICtrlListView_GetSelectedIndices($hListview1)
If $index1 <> "" Then
Local $idd = DllStructGetData($tInfo, "Index")
;GUICtrlSetData($iInput1, $idd)
;GUICtrlSetData($iInput4, $idd)
Local $sText
;$idd= GUICtrlRead($H)
$aItem = _GUICtrlListView_GetItemTextArray($Listview1, $idd)
For $i = 1 To $aItem
$sText &= $aItem[$i] & ",";& @CRLF
Next
MsgBox(0, "", $sText)
Else
MsgBox(0, "", "你点了空白栏", 1)
EndIf
Case -12;$NM_CUSTOMDRAW
;If GUICtrlRead($Checkboxg) = $GUI_CHECKED Then
Local $tCustDraw = DllStructCreate($tagNMLVCUSTOMDRAW, $ilParam)
Local $iDrawStage = DllStructGetData($tCustDraw, "dwDrawStage")
If $iDrawStage = $CDDS_PREPAINT Then Return $CDRF_NOTIFYITEMDRAW
If $iDrawStage = $CDDS_ITEMPREPAINT Then Return $CDRF_NOTIFYSUBITEMDRAW
Local $iItem = DllStructGetData($tCustDraw, "dwItemSpec")
Local $iSubItem = DllStructGetData($tCustDraw, "iSubItem")
Local $FTxt2 = "×"
Local $FTxt1 = "√"
If _GUICtrlListView_GetItemText($hWndListView1, $iItem, 6) = $FTxt2 Then
$iColor = RGB2BGR(0x0000FF)
$iColorBk = RGB2BGR(0xFFFF00)
DllStructSetData($tCustDraw, "clrText", $iColor)
DllStructSetData($tCustDraw, "clrTextBk", $iColorBk)
Else;If _GUICtrlListView_GetItemText($hWndListView1, $iItem, 6) = $FTxt2 Then
;$iColor = RGB2BGR(0x0000FF)
;$iColorBk = RGB2BGR(0xC0C0C0)
;DllStructSetData($tCustDraw, "clrText", $iColor)
;DllStructSetData($tCustDraw, "clrTextBk", $iColorBk)
EndIf
EndSwitch
EndSwitch
Return $GUI_RUNDEFMSG
EndFunc ;==>WM_NOTIFY
Func RGB2BGR($iColor)
Return BitAND(BitShift(String(Binary($iColor)), 8), 0xFFFFFF)
EndFunc ;==>RGB2BGR
本帖最后由 xuanniao110 于 2023-10-29 15:53 编辑
chzj589 发表于 2023-10-29 15:42
是这个意思?
代码如下:
#AutoIt3Wrapper_UseX64=n
##include <ButtonConstants.au3>
#include <ComboConstants.au3>
#include <GuiStatusBar.au3>
#include <GuiListView.au3>
#include <ListViewConstants.au3>
#include <StaticConstants.au3>
#include <WindowsConstants.au3>
#include <WinAPIEx.au3>
#include <EditConstants.au3>
#include <GuiIPAddress.au3>
#include <GuiImageList.au3>
#include <GuiEdit.au3>
#include <GUIComboBox.au3>
#include <GuiConstantsEx.au3>
#include <Array.au3>
#include <GuiButton.au3>
#include <ModernMenuRaw.au3>
#include <GUIConstants.au3>
#PRE_UseX64=n
;数据库定义
Global Const $DBName = "Data.mdb"
Global Const $DBPswd = "answerx"
Dim $array
Global $data = 10
Global $dataArray[$data]
;常量定义区
Global Const $ODT_LISTVIEW = 102
Global Const $ODA_DRAWENTIRE = 0x1
Global Const $ODA_SELECT = 0x2
Global Const $ODA_FOCUS = 0x4
Global Const $ODS_SELECTED = 0x0001
#Region ### START Koda GUI section ### Form=
$Form1 = GUICreate("Form1", 603, 698, 270, -1)
$Button5 = GUICtrlCreateButton("在线检测", 390, 71, 70, 25);, $BS_FLAT)
;$ListView1 = GUICtrlCreateListView("col1|col2 |col3|co4|co5|co6", 16, 16, 466, 302);, BitOR($LVS_REPORT, $LVS_OWNERDRAWFIXED, $LVS_OWNERDATA));两个自绘属性都加上!
;Dim $hListview1 = GUICtrlGetHandle(-1)
;$iStyle = BitOR($LVS_EX_FULLROWSELECT, $LVS_EX_GRIDLINES, $WS_EX_CLIENTEDGE, $LVS_EX_SUBITEMIMAGES, $LVS_EX_DOUBLEBUFFER)
;_GUICtrlListView_SetExtendedListViewStyle($ListView1, $iStyle)
;_GUICtrlListView_SetItemCount($ListView1, UBound($dataArray))
$Listview1 = GUICtrlCreateListView("", 3, 104, 597, 566, BitOR($LVS_REPORT, $LVS_SHOWSELALWAYS))
Dim $hListview1 = GUICtrlGetHandle(-1)
GUICtrlSetBkColor(-1, 0xB5B5B5)
$iStyle = BitOR($LVS_EX_FULLROWSELECT, $LVS_EX_GRIDLINES, $WS_EX_CLIENTEDGE, $LVS_EX_SUBITEMIMAGES, $LVS_EX_DOUBLEBUFFER)
_GUICtrlListView_SetExtendedListViewStyle($Listview1, $iStyle)
; 设置颜色
_GUICtrlListView_SetTextBkColor($Listview1, 0xFFE0C0);$CLR_MONEYGREEN)
_GUICtrlListView_SetBkColor($Listview1, 14675183);$CLR_MONEYGREEN)
_GUICtrlListView_AddColumn($Listview1, "ID", 0)
_GUICtrlListView_AddColumn($Listview1, "名称", 95)
_GUICtrlListView_AddColumn($Listview1, "IP地址", 120)
_GUICtrlListView_AddColumn($Listview1, "端口", 85)
_GUICtrlListView_AddColumn($Listview1, "用户名", 82)
_GUICtrlListView_AddColumn($Listview1, "密码", 63)
_GUICtrlListView_AddColumn($Listview1, "在线", 47)
; 加载图像
$hImage = _GUIImageList_Create()
_GUIImageList_AddIcon($hImage, @SystemDir & "\shell32.dll", 110) ;0
_GUIImageList_AddIcon($hImage, @SystemDir & "\shell32.dll", 131);1
_GUICtrlListView_SetImageList($Listview1, $hImage, 1)
Dim $RC_menu, $RC0, $RC1, $RC2, $RC3, $RC4
$RC_menu = GUICtrlCreateContextMenu($Listview1)
$RC0 = _GUICtrlCreateODMenuItem("完全控制", $RC_menu, "Radmin.exe", -16)
GUICtrlCreateMenuItem("", $RC_menu)
$RC1 = _GUICtrlCreateODMenuItem("添加连接", $RC_menu, "Radmin.exe", -9)
$RC2 = _GUICtrlCreateODMenuItem("编辑连接", $RC_menu, "Radmin.exe", -10)
$RC3 = _GUICtrlCreateODMenuItem("删除连接", $RC_menu, "Radmin.exe", -8)
GUICtrlCreateMenuItem("", $RC_menu)
$RC4 = _GUICtrlCreateODMenuItem("是否在线", $RC_menu, "Radmin.exe", -14)
$StatusBar1 = _GUICtrlStatusBar_Create($Form1)
Dim $StatusBar1_PartsWidth =
_GUICtrlStatusBar_SetParts($StatusBar1, $StatusBar1_PartsWidth)
_GUICtrlStatusBar_SetText($StatusBar1, "", 0)
_GUICtrlStatusBar_SetText($StatusBar1, "", 1)
_GUICtrlStatusBar_SetText($StatusBar1, "在线", 2)
_GUICtrlStatusBar_SetText($StatusBar1, @TAB & "", 3)
_GUICtrlStatusBar_SetText($StatusBar1, "离线", 4)
_GUICtrlStatusBar_SetText($StatusBar1, @TAB & "", 5)
GUISetState(@SW_SHOW)
updata()
GUIRegisterMsg($WM_NOTIFY, "WM_NOTIFY")
While 1
$nMsg = GUIGetMsg()
Switch $nMsg
Case $GUI_EVENT_CLOSE;, $ListBut_2
Exit
Case $Button5
updata()
_GUICtrlStatusBar_SetText($StatusBar1, "", 3)
_GUICtrlStatusBar_SetText($StatusBar1, "", 5)
_GUICtrlStatusBar_SetText($StatusBar1, "正在检测设备通讯……", 0)
$index = Number(_GUICtrlListView_GetSelectedIndices($Listview1))
$cs = _GUICtrlListView_GetItemCount($Listview1)
$i = GUICtrlRead($StatusBar1, 1)
For $i = 0 To $cs - 1
$z = _GUICtrlStatusBar_GetText($StatusBar1, 3)
$m = _GUICtrlStatusBar_GetText($StatusBar1, 5)
$x = $z + 1
$y = $m + 1
$add = _GUICtrlListView_GetItemText($Listview1, $i, 2)
$dkh = _GUICtrlListView_GetItemText($Listview1, $i, 3)
_GUICtrlStatusBar_SetText($StatusBar1, $i, 1)
TCPStartup() ; 开始 TCP 服务
Local $socket = TCPConnect($add, $dkh)
If $socket = -1 Then
TCPShutdown() ; 停止 TCP 服务
_GUICtrlListView_SetItemText($Listview1, $i, "×", 6)
_GUICtrlStatusBar_SetText($StatusBar1, @TAB & $y, 5)
Else
TCPShutdown() ; 停止 TCP 服务
_GUICtrlListView_SetItemText($Listview1, $i, "√", 6)
;------------------------------------------------------------------------------------------------------------------------------
;此处应该是更换图标
_GUICtrlListView_SetItemImage($ListView1, $i, 1, 1) ; 这样可以更改图标了☆
;此处应该是更换背景颜色
GUICtrlSetBkColor(_GUICtrlListView_GetItemParam($Listview1, $i), 0x2E8B57);更新颜色
;-------------------------------------------------------------------------------------------------------------------------------
_GUICtrlStatusBar_SetText($StatusBar1, @TAB & $x, 3)
EndIf
Next
_GUICtrlStatusBar_SetText($StatusBar1, "总共" & $cs & "台设备", 0)
_GUICtrlStatusBar_SetText($StatusBar1, "", 1)
EndSwitch
WEnd
Func updata()
GUICtrlSendMsg($Listview1, $LVM_DELETEALLITEMS, 0, 0)
$addfld = ObjCreate("ADODB.Connection")
$addfld.Open("Provider=Microsoft.Jet.OLEDB.4.0; Data Source=" & $DBName & ";Jet Oledb:Database Password=" & $DBPswd)
$RS = ObjCreate("ADODB.Recordset")
$RS.ActiveConnection = $addfld
$RS.open("SELECT COUNT(*) FROM Radmin");
While (Not $RS.eof And Not $RS.bof);
$P = $RS.Fields(0).value
$RS.movenext;
WEnd;
$RS.close;
Dim $APP[$P]
$i = 0
$addfld = ObjCreate("ADODB.Connection")
$addfld.Open("Provider=Microsoft.Jet.OLEDB.4.0; Data Source=" & $DBName & ";Jet Oledb:Database Password=" & $DBPswd)
$RS = ObjCreate("ADODB.Recordset")
$RS.ActiveConnection = $addfld
$RS.open("SELECT* fromRadmin");
While (Not $RS.eof And Not $RS.bof);
$APP[$i] = $RS.Fields(0).value
$APP[$i] = $RS.Fields(1).value
$APP[$i] = $RS.Fields(2).value
$APP[$i] = $RS.Fields(3).value
$APP[$i] = $RS.Fields(4).value
$APP[$i] = $RS.Fields(5).value
$i = $i + 1
$RS.movenext;
WEnd;
$RS.close;
For $x = 0 To $P - 1
_GUICtrlListView_AddItem($Listview1, $APP[$x], 0, -1)
_GUICtrlListView_AddSubItem($Listview1, $x, $APP[$x], 1, 0)
_GUICtrlListView_AddSubItem($Listview1, $x, $APP[$x], 2, -1)
_GUICtrlListView_AddSubItem($Listview1, $x, $APP[$x], 3, -1)
_GUICtrlListView_AddSubItem($Listview1, $x, $APP[$x], 4, -1)
_GUICtrlListView_AddSubItem($Listview1, $x, "******", 5, -1)
Next
_GUICtrlListView_RegisterSortCallBack($Listview1)
_GUICtrlListView_SortItems($Listview1, 0);以ID排序
_GUICtrlListView_SortItems($Listview1, GUICtrlGetState($Listview1))
_GUICtrlListView_UnRegisterSortCallBack($Listview1)
EndFunc ;==>updata
Func _SetIcon($hWnd, $sFile, $iIndex = 0, $nAlign = 0, $iWidth = 20, $iHeight = 20) ;控件句柄, 图标图像的路径, 图标索引, 图标在控件中的位置, 图标宽度, 图标高度
$hImage1 = _GUIImageList_Create($iWidth, $iHeight, 5, 1, 0) ;创建图像列表控件
_GUIImageList_AddIcon($hImage1, $sFile, $iIndex, True) ;向图像列表添加图标
_GUICtrlButton_SetImageList($hWnd, $hImage1, $nAlign) ;分配一个图像列表到按钮控件,$nAlign 是图标位置参数
EndFunc ;==>_SetIcon
Func WM_NOTIFY($hWnd, $iMsg, $iwParam, $ilParam)
#forceref $hWnd, $iMsg, $iwParam
Local $iColumn = GUICtrlGetState($Listview1) + 1
;Local $SList1 = GUICtrlRead($BInput1)
Local $hWndListView1 = $hListview1, $iColumn = 1
If Not IsHWnd($hListview1) Then $hWndListView1 = GUICtrlGetHandle($hListview1)
Local $tNMHDR = DllStructCreate($tagNMHDR, $ilParam)
Local $hWndFrom = HWnd(DllStructGetData($tNMHDR, 'hWndFrom'))
Local $iCode = DllStructGetData($tNMHDR, 'Code')
Switch $hWndFrom
Case $hListview1;$hWndListView1;$hListView1
Switch $iCode
Case $NM_CLICK ;= -2
Global $aHit = _GUICtrlListView_SubItemHitTest($hListview1)
Local $tInfo = DllStructCreate($tagNMITEMACTIVATE, $ilParam)
Local $iIndex = DllStructGetData($tInfo, 'Index')
Local $iSub = DllStructGetData($tInfo, 'SubItem')
$index1 = _GUICtrlListView_GetSelectedIndices($hListview1)
If $index1 <> "" Then
Local $idd = DllStructGetData($tInfo, "Index")
;GUICtrlSetData($iInput1, $idd)
;GUICtrlSetData($iInput4, $idd)
Local $sText
;$idd= GUICtrlRead($H)
$aItem = _GUICtrlListView_GetItemTextArray($Listview1, $idd)
For $i = 1 To $aItem
$sText &= $aItem[$i] & ",";& @CRLF
Next
MsgBox(0, "", $sText)
Else
MsgBox(0, "", "你点了空白栏", 1)
EndIf
Case -12;$NM_CUSTOMDRAW
;If GUICtrlRead($Checkboxg) = $GUI_CHECKED Then
Local $tCustDraw = DllStructCreate($tagNMLVCUSTOMDRAW, $ilParam)
Local $iDrawStage = DllStructGetData($tCustDraw, "dwDrawStage")
If $iDrawStage = $CDDS_PREPAINT Then Return $CDRF_NOTIFYITEMDRAW
If $iDrawStage = $CDDS_ITEMPREPAINT Then Return $CDRF_NOTIFYSUBITEMDRAW
Local $iItem = DllStructGetData($tCustDraw, "dwItemSpec")
Local $iSubItem = DllStructGetData($tCustDraw, "iSubItem")
Local $FTxt2 = "×"
Local $FTxt1 = "√"
If _GUICtrlListView_GetItemText($hWndListView1, $iItem, 6) = $FTxt2 Then
$iColor = RGB2BGR(0x0000FF)
$iColorBk = RGB2BGR(0xFFFF00)
DllStructSetData($tCustDraw, "clrText", $iColor)
DllStructSetData($tCustDraw, "clrTextBk", $iColorBk)
Else;If _GUICtrlListView_GetItemText($hWndListView1, $iItem, 6) = $FTxt2 Then
;$iColor = RGB2BGR(0x0000FF)
;$iColorBk = RGB2BGR(0xC0C0C0)
;DllStructSetData($tCustDraw, "clrText", $iColor)
;DllStructSetData($tCustDraw, "clrTextBk", $iColorBk)
EndIf
EndSwitch
EndSwitch
Return $GUI_RUNDEFMSG
EndFunc ;==>WM_NOTIFY
Func RGB2BGR($iColor)
Return BitAND(BitShift(String(Binary($iColor)), 8), 0xFFFFFF)
EndFunc ;==>RGB2BGR完全不会windows的消息模式,正在学习中 不过这能更改颜色了奇怪的是只有一列有要点一下那一列才全部出来
本帖最后由 chzj589 于 2023-10-29 16:11 编辑
xuanniao110 发表于 2023-10-29 15:52
代码如下:
完全不会windows的消息模式,正在学习中 不过这能更改颜色了奇怪的是只有一列有 ...
把217行 $FTxt2
改为 $FTxt1
点击"在线检测",这样才对 chzj589 发表于 2023-10-29 16:10
把217行 $FTxt2
改为 $FTxt1
点击"在线检测",这样才对
这个我晓得你只是判断√ 才改色我的意思是它为什么就只改了一列的颜色? xuanniao110 发表于 2023-10-29 16:24
这个我晓得你只是判断√ 才改色我的意思是它为什么就只改了一列的颜色?
可能是修改列的原因,如果从数据库读取就会整行改色 chzj589 发表于 2023-10-31 09:34
可能是修改列的原因,如果从数据库读取就会整行改色
真玩不转只有不要改色了 xuanniao110 发表于 2023-10-31 15:09
真玩不转只有不要改色了
不要灰心,鼓励一下
#AutoIt3Wrapper_UseX64=n
##include <ButtonConstants.au3>
#include <ComboConstants.au3>
#include <GuiStatusBar.au3>
#include <GuiListView.au3>
#include <ListViewConstants.au3>
#include <StaticConstants.au3>
#include <WindowsConstants.au3>
#include <WinAPIEx.au3>
#include <EditConstants.au3>
#include <GuiIPAddress.au3>
#include <GuiImageList.au3>
#include <GuiEdit.au3>
#include <GUIComboBox.au3>
#include <GuiConstantsEx.au3>
#include <Array.au3>
#include <GuiButton.au3>
#include <ModernMenuRaw.au3>
#include <GUIConstants.au3>
#PRE_UseX64=n
;数据库定义
Global Const $DBName = "Data.mdb"
Global Const $DBPswd = "answerx"
Dim $array
Global $data = 10
Global $dataArray[$data]
;常量定义区
Global Const $ODT_LISTVIEW = 102
Global Const $ODA_DRAWENTIRE = 0x1
Global Const $ODA_SELECT = 0x2
Global Const $ODA_FOCUS = 0x4
Global Const $ODS_SELECTED = 0x0001
#Region ### START Koda GUI section ### Form=
$Form1 = GUICreate("Form1", 603, 698, 270, -1)
$Button5 = GUICtrlCreateButton("在线检测", 390, 71, 70, 25);, $BS_FLAT)
;$ListView1 = GUICtrlCreateListView("col1|col2 |col3|co4|co5|co6", 16, 16, 466, 302);, BitOR($LVS_REPORT, $LVS_OWNERDRAWFIXED, $LVS_OWNERDATA));两个自绘属性都加上!
;Dim $hListview1 = GUICtrlGetHandle(-1)
;$iStyle = BitOR($LVS_EX_FULLROWSELECT, $LVS_EX_GRIDLINES, $WS_EX_CLIENTEDGE, $LVS_EX_SUBITEMIMAGES, $LVS_EX_DOUBLEBUFFER)
;_GUICtrlListView_SetExtendedListViewStyle($ListView1, $iStyle)
;_GUICtrlListView_SetItemCount($ListView1, UBound($dataArray))
$Listview1 = GUICtrlCreateListView("", 3, 104, 597, 566, BitOR($LVS_REPORT, $LVS_SHOWSELALWAYS))
Dim $hListview1 = GUICtrlGetHandle(-1)
GUICtrlSetBkColor(-1, 0xB5B5B5)
$iStyle = BitOR($LVS_EX_FULLROWSELECT, $LVS_EX_GRIDLINES, $WS_EX_CLIENTEDGE, $LVS_EX_SUBITEMIMAGES, $LVS_EX_DOUBLEBUFFER)
_GUICtrlListView_SetExtendedListViewStyle($Listview1, $iStyle)
; 设置颜色
_GUICtrlListView_SetTextBkColor($Listview1, 0xFFE0C0);$CLR_MONEYGREEN)
_GUICtrlListView_SetBkColor($Listview1, 14675183);$CLR_MONEYGREEN)
_GUICtrlListView_AddColumn($Listview1, "ID", 0)
_GUICtrlListView_AddColumn($Listview1, "名称", 95)
_GUICtrlListView_AddColumn($Listview1, "IP地址", 120)
_GUICtrlListView_AddColumn($Listview1, "端口", 85)
_GUICtrlListView_AddColumn($Listview1, "用户名", 82)
_GUICtrlListView_AddColumn($Listview1, "密码", 63)
_GUICtrlListView_AddColumn($Listview1, "", 4)
_GUICtrlListView_AddColumn($Listview1, "在线", 57)
; 加载图像
$hImage = _GUIImageList_Create()
_GUIImageList_AddIcon($hImage, @SystemDir & "\shell32.dll", 110) ;0
_GUIImageList_AddIcon($hImage, @SystemDir & "\shell32.dll", 131);1
_GUIImageList_AddIcon($hImage, @SystemDir & "\shell32.dll", 137)
_GUICtrlListView_SetImageList($Listview1, $hImage, 1)
Dim $RC_menu, $RC0, $RC1, $RC2, $RC3, $RC4
$RC_menu = GUICtrlCreateContextMenu($Listview1)
$RC0 = _GUICtrlCreateODMenuItem("完全控制", $RC_menu, "Radmin.exe", -16)
GUICtrlCreateMenuItem("", $RC_menu)
$RC1 = _GUICtrlCreateODMenuItem("添加连接", $RC_menu, "Radmin.exe", -9)
$RC2 = _GUICtrlCreateODMenuItem("编辑连接", $RC_menu, "Radmin.exe", -10)
$RC3 = _GUICtrlCreateODMenuItem("删除连接", $RC_menu, "Radmin.exe", -8)
GUICtrlCreateMenuItem("", $RC_menu)
$RC4 = _GUICtrlCreateODMenuItem("是否在线", $RC_menu, "Radmin.exe", -14)
$StatusBar1 = _GUICtrlStatusBar_Create($Form1)
Dim $StatusBar1_PartsWidth =
_GUICtrlStatusBar_SetParts($StatusBar1, $StatusBar1_PartsWidth)
_GUICtrlStatusBar_SetText($StatusBar1, "", 0)
_GUICtrlStatusBar_SetText($StatusBar1, "", 1)
_GUICtrlStatusBar_SetText($StatusBar1, "在线", 2)
_GUICtrlStatusBar_SetText($StatusBar1, @TAB & "", 3)
_GUICtrlStatusBar_SetText($StatusBar1, "离线", 4)
_GUICtrlStatusBar_SetText($StatusBar1, @TAB & "", 5)
GUISetState(@SW_SHOW)
updata()
GUIRegisterMsg($WM_NOTIFY, "WM_NOTIFY")
While 1
$nMsg = GUIGetMsg()
Switch $nMsg
Case $GUI_EVENT_CLOSE;, $ListBut_2
Exit
Case $Button5
updataa()
#cs
_GUICtrlStatusBar_SetText($StatusBar1, "", 3)
_GUICtrlStatusBar_SetText($StatusBar1, "", 5)
_GUICtrlStatusBar_SetText($StatusBar1, "正在检测设备通讯……", 0)
$index = Number(_GUICtrlListView_GetSelectedIndices($Listview1))
$cs = _GUICtrlListView_GetItemCount($Listview1)
$i = GUICtrlRead($StatusBar1, 1)
For $i = 0 To $cs - 1
$z = _GUICtrlStatusBar_GetText($StatusBar1, 3)
$m = _GUICtrlStatusBar_GetText($StatusBar1, 5)
$x = $z + 1
$y = $m + 1
$add = _GUICtrlListView_GetItemText($Listview1, $i, 2)
$dkh = _GUICtrlListView_GetItemText($Listview1, $i, 3)
_GUICtrlStatusBar_SetText($StatusBar1, $i, 1)
TCPStartup() ; 开始 TCP 服务
Local $socket = TCPConnect($add, $dkh)
If $socket = -1 Then
TCPShutdown() ; 停止 TCP 服务
;_GUICtrlListView_SetItemText($Listview1, $i, "×", 6)
_GUICtrlStatusBar_SetText($StatusBar1, @TAB & $y, 5)
Else
TCPShutdown() ; 停止 TCP 服务
;_GUICtrlListView_SetItemText($Listview1, $i, "√", 6)
;------------------------------------------------------------------------------------------------------------------------------
;此处应该是更换图标
_GUICtrlListView_SetItemImage($Listview1, $i, 1, 1) ; 这样可以更改图标了☆
;此处应该是更换背景颜色
GUICtrlSetBkColor(_GUICtrlListView_GetItemParam($Listview1, $i), 0x2E8B57);更新颜色
;-------------------------------------------------------------------------------------------------------------------------------
_GUICtrlStatusBar_SetText($StatusBar1, @TAB & $x, 3)
EndIf
Next
_GUICtrlStatusBar_SetText($StatusBar1, "总共" & $cs & "台设备", 0)
_GUICtrlStatusBar_SetText($StatusBar1, "", 1)
#ce
EndSwitch
WEnd
Func updataa()
Local $a, $b
_GUICtrlStatusBar_SetText($StatusBar1, "", 3)
_GUICtrlStatusBar_SetText($StatusBar1, "", 5)
_GUICtrlStatusBar_SetText($StatusBar1, "正在检测设备通讯……", 0)
$index = Number(_GUICtrlListView_GetSelectedIndices($Listview1))
$cs = _GUICtrlListView_GetItemCount($Listview1)
$i = GUICtrlRead($StatusBar1, 1)
For $i = 0 To $cs - 1
$z = _GUICtrlStatusBar_GetText($StatusBar1, 3)
$m = _GUICtrlStatusBar_GetText($StatusBar1, 5)
$x = $z + 1
$y = $m + 1
$add = _GUICtrlListView_GetItemText($Listview1, $i, 2)
$dkh = _GUICtrlListView_GetItemText($Listview1, $i, 3)
_GUICtrlStatusBar_SetText($StatusBar1, $i, 1)
TCPStartup() ; 开始 TCP 服务
Local $socket = TCPConnect($add, $dkh)
If $socket = -1 Then
TCPShutdown() ; 停止 TCP 服务
$b = 1
_GUICtrlStatusBar_SetText($StatusBar1, @TAB & $y, 5)
Else
TCPShutdown() ; 停止 TCP 服务
$b = 2
_GUICtrlStatusBar_SetText($StatusBar1, @TAB & $x, 3)
EndIf
Next
_GUICtrlStatusBar_SetText($StatusBar1, "总共" & $cs & "台设备", 0)
_GUICtrlStatusBar_SetText($StatusBar1, "", 1)
Local $socket
GUICtrlSendMsg($Listview1, $LVM_DELETEALLITEMS, 0, 0)
$addfld = ObjCreate("ADODB.Connection")
$addfld.Open("Provider=Microsoft.Jet.OLEDB.4.0; Data Source=" & $DBName & ";Jet Oledb:Database Password=" & $DBPswd)
$RS = ObjCreate("ADODB.Recordset")
$RS.ActiveConnection = $addfld
$RS.open("SELECT COUNT(*) FROM Radmin");
While (Not $RS.eof And Not $RS.bof);
$P = $RS.Fields(0).value
$RS.movenext;
WEnd;
$RS.close;
Dim $APP[$P]
$i = 0
$addfld = ObjCreate("ADODB.Connection")
$addfld.Open("Provider=Microsoft.Jet.OLEDB.4.0; Data Source=" & $DBName & ";Jet Oledb:Database Password=" & $DBPswd)
$RS = ObjCreate("ADODB.Recordset")
$RS.ActiveConnection = $addfld
$RS.open("SELECT* fromRadmin");
While (Not $RS.eof And Not $RS.bof);
$APP[$i] = $RS.Fields(0).value
$APP[$i] = $RS.Fields(1).value
$APP[$i] = $RS.Fields(2).value
$APP[$i] = $RS.Fields(3).value
$APP[$i] = $RS.Fields(4).value
$APP[$i] = $RS.Fields(5).value
$i = $i + 1
$RS.movenext;
WEnd;
$RS.close;
If $b <= 1 Then
$a = "×"
$b = 1
Else
$a = "√"
$b = 2
EndIf
For $x = 0 To $P - 1
_GUICtrlListView_AddItem($Listview1, $APP[$x], 0, -1)
_GUICtrlListView_AddSubItem($Listview1, $x, $APP[$x], 1, 0)
_GUICtrlListView_AddSubItem($Listview1, $x, $APP[$x], 2, -1)
_GUICtrlListView_AddSubItem($Listview1, $x, $APP[$x], 3, -1)
_GUICtrlListView_AddSubItem($Listview1, $x, $APP[$x], 4, -1)
_GUICtrlListView_AddSubItem($Listview1, $x, "******", 5, -1);"******",
_GUICtrlListView_AddSubItem($Listview1, $x, $a, 7, $b)
Next
_GUICtrlListView_RegisterSortCallBack($Listview1)
_GUICtrlListView_SortItems($Listview1, 0);以ID排序
_GUICtrlListView_SortItems($Listview1, GUICtrlGetState($Listview1))
_GUICtrlListView_UnRegisterSortCallBack($Listview1)
EndFunc ;==>updataa
Func updata()
GUICtrlSendMsg($Listview1, $LVM_DELETEALLITEMS, 0, 0)
$addfld = ObjCreate("ADODB.Connection")
$addfld.Open("Provider=Microsoft.Jet.OLEDB.4.0; Data Source=" & $DBName & ";Jet Oledb:Database Password=" & $DBPswd)
$RS = ObjCreate("ADODB.Recordset")
$RS.ActiveConnection = $addfld
$RS.open("SELECT COUNT(*) FROM Radmin");
While (Not $RS.eof And Not $RS.bof);
$P = $RS.Fields(0).value
$RS.movenext;
WEnd;
$RS.close;
Dim $APP[$P]
$i = 0
$addfld = ObjCreate("ADODB.Connection")
$addfld.Open("Provider=Microsoft.Jet.OLEDB.4.0; Data Source=" & $DBName & ";Jet Oledb:Database Password=" & $DBPswd)
$RS = ObjCreate("ADODB.Recordset")
$RS.ActiveConnection = $addfld
$RS.open("SELECT* fromRadmin");
While (Not $RS.eof And Not $RS.bof);
$APP[$i] = $RS.Fields(0).value
$APP[$i] = $RS.Fields(1).value
$APP[$i] = $RS.Fields(2).value
$APP[$i] = $RS.Fields(3).value
$APP[$i] = $RS.Fields(4).value
$APP[$i] = $RS.Fields(5).value
$i = $i + 1
$RS.movenext;
WEnd;
$RS.close;
For $x = 0 To $P - 1
_GUICtrlListView_AddItem($Listview1, $APP[$x], 0, -1)
_GUICtrlListView_AddSubItem($Listview1, $x, $APP[$x], 1, 0)
_GUICtrlListView_AddSubItem($Listview1, $x, $APP[$x], 2, -1)
_GUICtrlListView_AddSubItem($Listview1, $x, $APP[$x], 3, -1)
_GUICtrlListView_AddSubItem($Listview1, $x, $APP[$x], 4, -1)
_GUICtrlListView_AddSubItem($Listview1, $x, "******", 5, -1)
_GUICtrlListView_AddSubItem($Listview1, $x, "×", 6, -1)
Next
_GUICtrlListView_RegisterSortCallBack($Listview1)
_GUICtrlListView_SortItems($Listview1, 0);以ID排序
_GUICtrlListView_SortItems($Listview1, GUICtrlGetState($Listview1))
_GUICtrlListView_UnRegisterSortCallBack($Listview1)
EndFunc ;==>updata
Func _SetIcon($hWnd, $sFile, $iIndex = 0, $nAlign = 0, $iWidth = 20, $iHeight = 20) ;控件句柄, 图标图像的路径, 图标索引, 图标在控件中的位置, 图标宽度, 图标高度
$hImage1 = _GUIImageList_Create($iWidth, $iHeight, 5, 1, 0) ;创建图像列表控件
_GUIImageList_AddIcon($hImage1, $sFile, $iIndex, True) ;向图像列表添加图标
_GUICtrlButton_SetImageList($hWnd, $hImage1, $nAlign) ;分配一个图像列表到按钮控件,$nAlign 是图标位置参数
EndFunc ;==>_SetIcon
Func WM_NOTIFY($hWnd, $iMsg, $iwParam, $ilParam)
#forceref $hWnd, $iMsg, $iwParam
Local $iColumn = GUICtrlGetState($Listview1) + 1
;Local $SList1 = GUICtrlRead($BInput1)
Local $hWndListView1 = $hListview1, $iColumn = 1
If Not IsHWnd($hListview1) Then $hWndListView1 = GUICtrlGetHandle($hListview1)
Local $tNMHDR = DllStructCreate($tagNMHDR, $ilParam)
Local $hWndFrom = HWnd(DllStructGetData($tNMHDR, 'hWndFrom'))
Local $iCode = DllStructGetData($tNMHDR, 'Code')
Switch $hWndFrom
Case $hListview1;$hWndListView1;$hListView1
Switch $iCode
Case $NM_CLICK ;= -2
Global $aHit = _GUICtrlListView_SubItemHitTest($hListview1)
Local $tInfo = DllStructCreate($tagNMITEMACTIVATE, $ilParam)
Local $iIndex = DllStructGetData($tInfo, 'Index')
Local $iSub = DllStructGetData($tInfo, 'SubItem')
$index1 = _GUICtrlListView_GetSelectedIndices($hListview1)
If $index1 <> "" Then
Local $idd = DllStructGetData($tInfo, "Index")
;GUICtrlSetData($iInput1, $idd)
;GUICtrlSetData($iInput4, $idd)
Local $sText
;$idd= GUICtrlRead($H)
$aItem = _GUICtrlListView_GetItemTextArray($Listview1, $idd)
For $i = 1 To $aItem
$sText &= $aItem[$i] & ",";& @CRLF
Next
MsgBox(0, "", $sText)
Else
;MsgBox(0, "", "你点了空白栏", 1)
EndIf
Case -12;$NM_CUSTOMDRAW
;If GUICtrlRead($Checkboxg) = $GUI_CHECKED Then
Local $tInfo = DllStructCreate($tagNMITEMACTIVATE, $ilParam)
Local $tCustDraw = DllStructCreate($tagNMLVCUSTOMDRAW, $ilParam)
Local $iDrawStage = DllStructGetData($tCustDraw, "dwDrawStage")
If $iDrawStage = $CDDS_PREPAINT Then Return $CDRF_NOTIFYITEMDRAW
If $iDrawStage = $CDDS_ITEMPREPAINT Then Return $CDRF_NOTIFYSUBITEMDRAW
Local $iItem = DllStructGetData($tCustDraw, "dwItemSpec")
Local $iSubItem = DllStructGetData($tCustDraw, "iSubItem")
Local $FTxt2 = "×"
Local $FTxt1 = "√"
Local $FTxt3 = "00";"******";
Local $sExt11 = $FTxt2 & "|" & $FTxt2
Local $idd = DllStructGetData($tInfo, "Index")
$aItem = _GUICtrlListView_GetItemTextArray($Listview1, $idd)
For $i = 1 To $aItem
Local $aa = _GUICtrlListView_GetItemText($hWndListView1, $iItem, $i)
If StringRegExp($aa, '(?mi)^\h*(' & $sExt11 & ")$") Then
$iColor = RGB2BGR(0x000000)
$iColorBk1 = RGB2BGR(0xFFFF00)
DllStructSetData($tCustDraw, "clrText", $iColor)
DllStructSetData($tCustDraw, "clrTextBk", $iColorBk1)
EndIf
Next
EndSwitch
EndSwitch
Return $GUI_RUNDEFMSG
EndFunc ;==>WM_NOTIFY
Func RGB2BGR($iColor)
Return BitAND(BitShift(String(Binary($iColor)), 8), 0xFFFFFF)
EndFunc ;==>RGB2BGR