VB6里有没有能设置多列的列表框呢?

yjt258 2008-03-02 07:05:42
VB6里自带的列表框怎么只能设置一列,要是想设多列或者像任务管理器哪样在标题前加个小图标应该怎么样做呢?
...全文
425 7 打赏 收藏 转发到动态 举报
AI 作业
写回复
用AI写文章
7 条回复
切换为时间正序
请发表友善的回复…
发表回复
yhliao1978 2008-03-05
  • 打赏
  • 举报
回复
用ListView控件,按楼上的方法可添加到工具栏中使用。使用ListView的样式选用“report”就可以得到多列的列表了。
yjt258 2008-03-05
  • 打赏
  • 举报
回复
感谢各位的帮助,我试试看。
cbm6666 2008-03-03
  • 打赏
  • 举报
回复
在工程部件里添加 MicroSoft Windows Common Controls 6.0 打勾应用,左边工具栏便会有ListView与Imagelist

'代码整理出来给你了, Listview1拉宽一点, 照下面需求,将所有控件一一加入窗体

'添加 Picture1 Picture2 Command1 Imagelist1 ListView1

Option Explicit
'**************************** 进程 API
Private Declare Function FindWindow Lib "user32" Alias "FindWindowA" (ByVal lpClassName As String, ByVal lpWindowName As String) As Long
Private Declare Function GetParent Lib "user32" (ByVal hwnd As Long) As Long
Private Declare Function GetWindowThreadProcessId Lib "user32" (ByVal hwnd As Long, lpdwprocessid As Long) As Long
Private Declare Function GetWindow Lib "user32" (ByVal hwnd As Long, ByVal wCmd As Long) As Long
Private Declare Function GetClassName Lib "user32" Alias "GetClassNameA" (ByVal hwnd As Long, ByVal lpClassName As String, ByVal nMaxCount As Long) As Long
Private Declare Function GetWindowText Lib "user32" Alias "GetWindowTextA" (ByVal hwnd As Long, ByVal lpString As String, ByVal aint As Long) As Long
Const MAXLEN = 255
Const GW_HWNDNEXT = 2
'******************************** 图标API
Private Declare Function BitBlt Lib "gdi32" (ByVal hDestDC As Long, ByVal x As Long, ByVal y As Long, ByVal nWidth As Long, ByVal nHeight As Long, ByVal hSrcDC As Long, ByVal xSrc As Long, ByVal ySrc As Long, ByVal dwRop As Long) As Long
Private Declare Function ExtractAssociatedIcon Lib "shell32.dll" Alias "ExtractAssociatedIconA" (ByVal hInst As Long, ByVal lpIconPath As String, lpiIcon As Long) As Long
Private Declare Function DrawIconEx Lib "user32" (ByVal hdc As Long, ByVal Xleft As Long, ByVal yTop As Long, ByVal hIcon As Long, ByVal cxWidth As Long, ByVal cyWidth As Long, ByVal istepIfAniCur As Long, ByVal hbrFlickerFreeDraw As Long, ByVal diFlags As Long) As Long
Private Declare Function DestroyIcon Lib "user32" (ByVal hIcon As Long) As Long
Const DI_MASK = &H1
Const DI_IMAGE = &H2
Const DI_NORMAL = DI_MASK Or DI_IMAGE
'************************************** 变量宣告 *************************************
Dim proid&, hProcess&, phwnd&, hwndval&, tt&, i&, j%, transcolor&, mIcon&
Dim aa$, clsnm$, captitle$, exename$, exepath$, tmpstr$
Dim imgX As ListImage, xn As ListItem, itm As ListItem, clm As ColumnHeader
Dim objWMIService, objProcess, colProcess, itmX
Private Sub Form_Load()
transcolor = vbBlue
With Picture1
.BorderStyle = 0
.AutoSize = True
.AutoRedraw = True
.ScaleMode = 3
.BackColor = transcolor
.Move 0, Me.Height - 1000, 480, 480
.ZOrder 0
End With

With Picture2
.ScaleMode = 3
.BorderStyle = 0
.AutoRedraw = True
.Move Screen.Width, 0, 480, 480
End With
'***********************************************************
ImageList1.MaskColor = transcolor
ImageList1.UseMaskColor = transcolor
ImageList1.BackColor = transcolor
'************************************************************
ListView1.Arrange = lvwAutoLeft
ListView1.LabelWrap = False
ListView1.FlatScrollBar = False
'ListView1.Sorted = True
ListView1.ListItems.Clear
ListView1.ColumnHeaders.Clear
ListView1.View = lvwReport
Set clm = ListView1.ColumnHeaders.Add(, , "进程名称", 1800)
Set clm = ListView1.ColumnHeaders.Add(, , "句 柄", 1000)
Set clm = ListView1.ColumnHeaders.Add(, , "PID", 800)
Set clm = ListView1.ColumnHeaders.Add(, , "类 名", 1800)
Set clm = ListView1.ColumnHeaders.Add(, , "窗口标题", 2600)
Set clm = ListView1.ColumnHeaders.Add(, , "路 径", 4000)
ListView1.Refresh
Me.Move (Screen.Width - Me.Width) \ 2, (Screen.Height - Me.Height) \ 2
End Sub

Private Sub Command1_Click()
On Error Resume Next
Picture1.ZOrder 0
tmpstr = "."
Set objWMIService = GetObject("winmgmts:" & "{impersonationLevel=impersonate}!\\" & tmpstr & "\root\cimv2")
Set colProcess = objWMIService.ExecQuery("Select * from Win32_Process")
If ImageList1.ListImages.Count > 0 Then
ListView1.ListItems.Clear
Set ListView1.SmallIcons = Nothing
Set ListView1.Icons = Nothing
ImageList1.ListImages.Clear
End If

i = 1
For Each objProcess In colProcess
Picture1.Cls
Picture2.Cls
proid = objProcess.processid
exename = objProcess.Name
exepath = IIf(proid > 8 And exename <> "csrss.exe" And exename <> "dllhost.exe", objProcess.ExecutablePath, "")
phwnd = InstanceToWnd(proid)
clsnm = Getclassnm(phwnd)
captitle = GetCaptionFromHwnd(phwnd)
j = InStr(captitle, Chr(0))
If j > 0 Then captitle = Mid(captitle, 1, j - 1)
If exepath <> "" Then
Call Geticonmain(Picture1, exepath)
BitBlt Picture2.hdc, 0, 0, 32, 32, Picture1.hdc, 0, 0, vbSrcCopy
ImageList1.ListImages.Add i, "", Picture2.Image
ListView1.SmallIcons = ImageList1
ListView1.Icons = ImageList1
Set itm = ListView1.ListItems.Add(, "Row" & CStr(i), exename, 1, i)
itm.SubItems(1) = CStr(phwnd)
itm.SubItems(2) = CStr(proid)
If clsnm <> "" Then itm.SubItems(3) = clsnm
If captitle <> "" Then itm.SubItems(4) = captitle
If exepath <> "" Then itm.SubItems(5) = exepath
i = i + 1
End If
Next
Picture1.Move Screen.Width
End Sub

Public Function InstanceToWnd(ByVal target_pid As Long) As Long
Dim test_hwnd&, test_pid&, test_thread_id& '以ProID查找Hwnd
test_hwnd = FindWindow(vbNullString, vbNullString)
Do While test_hwnd <> 0
If GetParent(test_hwnd) = 0 Then
test_thread_id = GetWindowThreadProcessId(test_hwnd, test_pid)
If test_pid = target_pid Then InstanceToWnd = test_hwnd: Exit Do
End If
test_hwnd = GetWindow(test_hwnd, GW_HWNDNEXT)
Loop
End Function

Public Function Getclassnm(hwnd As Long) As String
Dim Ret$, RetVal&, lpClassName$
lpClassName = Space(256)
RetVal = GetClassName(hwnd, lpClassName, 256)
Getclassnm = Trim(Left(lpClassName, RetVal))
End Function

Public Function GetCaptionFromHwnd(hwnd As Long) As String
Dim strBuffer$, intCount%
strBuffer = String$(MAXLEN - 1, 0)
intCount = GetWindowText(hwnd, strBuffer, MAXLEN)
If intCount > 0 Then GetCaptionFromHwnd = Trim(Left(strBuffer, intCount))
End Function

Public Function Geticonmain(pic1 As Object, pathstr As String) As Long
On Error Resume Next
If TypeOf pic1 Is Form Or TypeOf pic1 Is PictureBox Then pic1.AutoRedraw = False
mIcon = ExtractAssociatedIcon(App.hInstance, pathstr, 2)
DrawIconEx pic1.hdc, 0, 0, mIcon, 0, 0, 0, 0, DI_NORMAL
Geticonmain = pic1.hdc
DestroyIcon mIcon
End Function




熊孩子开学喽 2008-03-03
  • 打赏
  • 举报
回复
使用MSFLEXGRID就可以了。多列多行,可以加载图片图标。
yjt258 2008-03-03
  • 打赏
  • 举报
回复
你说的这个控件在哪能找到呢?
舉杯邀明月 2008-03-03
  • 打赏
  • 举报
回复
要用图标只能使用MSFLEXGRID控件。
cbm6666 2008-03-02
  • 打赏
  • 举报
回复
你只能使用 ListView达到你的要求,需要代码便留下邮箱吧.



免费Spire.PDF for .NET 是一款由e-iceblue公司开发的专业性的PDF文档创建组件。它能够使用户在不用Adobe Acrobat和其他外部控件的情况下,运用.NET 应用程序阅读,编写和操纵PDF 文档。Spire.PDF for .NET不仅可以运用在服端比如:ASP.NET 或者其他环境,还可以应用在Windows Forms 应用程序中。Spire.PDF for .NET 适合应用于所有常见的坏境中,比如:创建好的PDF文档可以存到磁盘中, 还可以在Windows Forms应用程序,ASP.NET 应用程序客户端浏览器中保存为数据流。 Spire.PDF for .NET 功能丰富。 除了基本的功能比如:绘制多种图形,图片,创建窗体字段,插入页眉页脚,输入数据表,自动对大型表格进行分页外,Spire.PDF for .NET还支持PDF数字签名,将HTML转换成PDF格式,提取PDF文档中的文本信息和图片,存为文本格式和各种图片格式,甚至可以将PDF中的附件提取出来。 主要功能 支持嵌入式字体,Truetype 字体和CJK字体。 支持绘图。比如:矩形,环形,弧形,椭圆形,也可以自定笔刷将其填充。 可以将图片从数据流,磁盘文件中载入到PDF 文档中。 在PDF 文档中既可以绘制梯状图形和矢量图像,还支持掩模和水印图像。 可以在PDF 文档中载入数据表。可以设置表中的行和列的格式,还可以在表内加入图形元素。 自动对PDF 中的大型表格进行分页。 创建窗体字段。比如在PDF 文档中创建按钮,文本框,列表框,复选框等等。 在PDF 中插入页眉页脚。 通过设置所有者密码和用户密码来加密PDF文档。 通过作者的签名来保护PDF文档。 读取当前PDF文档的表格并且填充表格。 HTML网页在转换到PDF文档时会拆分为多个大型页面,这些页面可以原原本本的展现在PDF文档中,而且在PDF文档的分页处没有任何文字的截断。用户还可以将这些网页在不需要临时文件的情况下,直接转换为数据流来创建PDF文档。

1,453

社区成员

发帖
与我相关
我的任务
社区描述
VB 控件
社区管理员
  • 控件
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧