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

 我来答
匿名用户
2016-09-27
展开全部
建议你将信息存在文件或注册表中,然后用个循环读取并加载。这样以后也好修改。

帮你修改了下,将路径按以下格式存为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
推荐律师服务: 若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询

为你推荐:

下载百度知道APP,抢鲜体验
使用百度知道APP,立即抢鲜体验。你的手机镜头里或许有别人想知道的答案。
扫描二维码下载
×

类别

我们会通过消息、邮箱等方式尽快将举报结果通知您。

说明

0/200

提交
取消

辅 助

模 式