VB/VBA使用api实现外部程序listview指定item的双击

如题所述

建议你将信息存在文件或注册表中,然后用个循环读取并加载。这样以后也好修改。

帮你修改了下,将路径按以下格式存为txt文件。

冒险岛online
D:\盛大网络\冒险岛online\maplestory.exe
超级玛丽
D:\ZSNESW\运行游戏.exe
机械迷城
D:\机械迷城\machinarium.exe
植物大战僵尸
D:\Plants vs. Zombies\PlantsVsZombies.exe
平衡球
D:\Ballance\Startup.exe
粘粘世界
D:\新建文件夹\World of Goo V1.4\WorldOfGoo.exe

Private Sub Label1_Click(Index As Integer)
Select Case Index
Case 0
LoadData ("Games.txt")
Case 1
LoadData ("Tools.txt")
Case 2
...
End Select
End Sub

Private Sub LoadData(TxtFile As String)
Dim str As String, Data() As String
Dim Names() As String, Paths() As String
Dim i As Long, k As Long

'打开文件,读取内容
Open TxtFile For Binary As #1
str = Input(LOF(1), #1)
Close #1

Data() = Split(str, vbCrLf)
ReDim Names(0 To Int(UBound(Data) / 2))
ReDim Paths(0 To Int(UBound(Data) / 2))

k = 0
For i = 0 To UBound(Data) Step 2
'确保不为空
If Len(Data(i)) <> 0 And Len(Data(i + 1)) <> 0 Then
Names(k) = Data(i)
Paths(k) = Data(i + 1)

'添加图标
Dim a
Picture1.Picture = LoadPicture("")
a = ExtractIcon(App.hInstance, Paths(k), 0)
a = DrawIcon(Picture1.hdc, 0, 0, a)
ImageList1.ListImages.Add , , Picture1.Image

'添加项目,利用key属性储存路径数据
ListView1.ListItems.Add , Paths(k), Names(k), k + 1

k = k + 1

End If
Next i
End Sub

'双击
Private Sub ListView1_DblClick()
'判断是否点击到item
If Not ListView1.SelectedItem Is Nothing Then
Shell ListView1.SelectedItem.Key
End If
End Sub

'为了让Listview在没点到item时失去焦点
'否则点空白时selectitem不为空
Private Sub ListView1_MouseDown(Button As Integer, Shift As Integer, x As Single, y As Single)
If Not ListView1.HitTest(x, y) Is ListView1.SelectedItem Then
Set ListView1.SelectedItem = Nothing
End If
End Sub
温馨提示:答案为网友推荐,仅供参考

相关了解……

你可能感兴趣的内容

本站内容来自于网友发表,不代表本站立场,仅表示其个人看法,不对其真实性、正确性、有效性作任何的担保
相关事宜请发邮件给我们
© 非常风气网