[已解决]关于在listview控件中的第2列增加图标显示
本帖最后由 xuanniao110 于 2023-10-24 20:31 编辑各位大佬,确实真的弄不明白了,只有求助了
#NoTrayIcon
#PRE_UseX64=n
#include <GuiStatusBar.au3>
#include <GuiListView.au3>
#include <ListViewConstants.au3>
#include <GuiImageList.au3>
#include <GUIConstants.au3>
;数据库定义
Global Const $DBName = "Data.mdb"
Global Const $DBPswd = "answerx"
$Form1 = GUICreate("Radmin远程小工具", 503, 698, 702, 187)
$ListView1 = GUICtrlCreateListView("", 3, 104, 497, 566)
GUICtrlSetBkColor(-1, 0xB5B5B5)
$image = _GUIImageList_Create(16, 16, 5, 3)
_GUIImageList_AddIcon($image, @SystemDir&"/imageres.dll", 28)
_GUIImageList_AddIcon($image, @SystemDir&"/imageres.dll", 20)
_GUICtrlListView_SetImageList($ListView1, $image, 1)
_GUICtrlListView_AddColumn($ListView1, "ID", 40)
_GUICtrlListView_AddColumn($ListView1, "名称", 75)
_GUICtrlListView_AddColumn($ListView1, "IP地址", 100)
_GUICtrlListView_AddColumn($ListView1, "端口", 80)
_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)
$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
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 * From Radmin")
While Not $RS.eof And Not $RS.bof
If @error = 1 Then ExitLoop
GUICtrlCreateListViewItem( _
$RS.Fields(0).value & "|" & _
$RS.Fields(1).value & "|" & _
$RS.Fields(2).value & "|" & _
$RS.Fields(3).value & "|" & _
$RS.Fields(4).value & "|" & _
"********", $ListView1)
$RS.movenext
WEnd
$RS.close
$addfld.Close
_GUICtrlListView_RegisterSortCallBack($ListView1)
_GUICtrlListView_SortItems($ListView1, 0);以ID排序
_GUICtrlListView_SortItems($ListView1, GUICtrlGetState($ListView1))
EndFunc ;==>updata我的ID列最终是隐藏的,所以图标是应该显示在第二列上,搞了2个图标作为例子,目的是为了后续实现TCP检测功能,如果TCP检测为通,则图标为图像列表索引1 不通则为图像列表索引2 现在就是界面上连图标都搞不出来。所以求助了
附件为ACCESS数据库 Data.mdb
想实现的样子,如下图了
本帖最后由 afan 于 2023-10-24 20:06 编辑
设置列表视图扩展样式,需包含 $LVS_EX_SUBITEMIMAGES 样式。
看 _GUIImageList_AddIcon 帮助文档示例 afan 发表于 2023-10-24 19:33
设置列表视图扩展样式,需包含 $LVS_EX_SUBITEMIMAGES 样式。
看 _GUIImageList_Add 帮助文档示例
A大 扩展样式是设置了的
我不是图像是_GUIImageList_AddIcon 添加图标到图像列表 本帖最后由 afan 于 2023-10-24 20:09 编辑
xuanniao110 发表于 2023-10-24 19:57
A大 扩展样式是设置了的
我不是图像是_GUIImageList_AddIcon 添加图标到图像列表
帮助文档 _GUIImageList_AddIcon 示例就是。
用 _GUICtrlListView_AddItem 及 _GUICtrlListView_AddSubItem 创建项目
本帖最后由 xuanniao110 于 2023-10-24 21:26 编辑
afan 发表于 2023-10-24 20:05
帮助文档 _GUIImageList_AddIcon 示例就是。
用 _GUICtrlListView_AddItem 及 _GUICtrlListView_AddSubI ...
#include <GUIConstantsEx.au3>
#include <GuiListView.au3>
#include <GuiImageList.au3>
$Debug_LV = False ; 检查传递给 ListView 函数的类名, 设置为True并输出到一个控件的句柄,用于检查它是否工作
_Main()
Func _Main()
Local $hImage, $hListView
; 创建界面
GUICreate("列表中添加子项", 700, 300)
$hListView = GUICtrlCreateListView("", 2, 2, 594, 268, -1, BitOR($LVS_EX_FULLROWSELECT, $LVS_EX_SUBITEMIMAGES))
GUISetState()
; 加载图像
$hImage = _GUIImageList_Create()
_GUIImageList_AddIcon($hImage, "radmin.exe", 1) ;0
_GUIImageList_AddIcon($hImage, "radmin.exe", 11);1
_GUICtrlListView_SetImageList($hListView, $hImage, 1)
; 添加列
_GUICtrlListView_InsertColumn($hListView, 0, "ID", 0)
_GUICtrlListView_InsertColumn($hListView, 1, "名称", 100)
_GUICtrlListView_InsertColumn($hListView, 2, "IP地址", 100)
_GUICtrlListView_InsertColumn($hListView, 3, "端口号", 100)
_GUICtrlListView_InsertColumn($hListView, 4, "用户名", 100)
_GUICtrlListView_InsertColumn($hListView, 5, "密码", 100)
_GUICtrlListView_InsertColumn($hListView, 6, "在线", 100)
; 添加项
For$x = 0To20
_GUICtrlListView_AddItem($hListView, $x, $x ,-1)
_GUICtrlListView_AddSubItem($hListView, $x , "1111", 1, 0)
_GUICtrlListView_AddSubItem($hListView, $x , "192.168.0.1", 2, -1)
_GUICtrlListView_AddSubItem($hListView, $x , "1111", 3, -1)
_GUICtrlListView_AddSubItem($hListView, $x , "00", 4, -1)
_GUICtrlListView_AddSubItem($hListView, $x , "0000", 5, -1)
_GUICtrlListView_AddSubItem($hListView, $x , "√", 6, -1)
Next
; 循环至用户退出
Do
Until GUIGetMsg() = $GUI_EVENT_CLOSE
GUIDelete()
EndFunc ;==>_Main
本帖最后由 f4李文杨 于 2023-10-27 14:20 编辑
好像很久之前我也写过类式的,当时还在网吧搞维护的时候弄的,后来没有搞了,写了一半没有写完!
不知道你写提不是跟我这个类式呢?
页:
[1]