是这个意思?
#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[1][1]
Global $data = 10
Global $dataArray[$data][9]
;常量定义区
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[6] = [120, 300, 370, 420, 450, -1]
_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][7]
$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 * from Radmin");
While (Not $RS.eof And Not $RS.bof);
$APP[$i][0] = $RS.Fields(0).value
$APP[$i][1] = $RS.Fields(1).value
$APP[$i][2] = $RS.Fields(2).value
$APP[$i][3] = $RS.Fields(3).value
$APP[$i][4] = $RS.Fields(4).value
$APP[$i][5] = $RS.Fields(5).value
$i = $i + 1
$RS.movenext;
WEnd;
$RS.close;
For $x = 0 To $P - 1
_GUICtrlListView_AddItem($Listview1, $APP[$x][0], 0, -1)
_GUICtrlListView_AddSubItem($Listview1, $x, $APP[$x][1], 1, 0)
_GUICtrlListView_AddSubItem($Listview1, $x, $APP[$x][2], 2, -1)
_GUICtrlListView_AddSubItem($Listview1, $x, $APP[$x][3], 3, -1)
_GUICtrlListView_AddSubItem($Listview1, $x, $APP[$x][4], 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[0]
$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
|