获取图标任何文件图标问题!(已解决 感谢afan)
本帖最后由 nmgwddj 于 2010-3-9 15:49 编辑我只想做出一个和这个启动项管理工具一样的效果。
问题1,刚才发帖问过了。就是如何在ListView列表中 显示每个启动项文件的图标。
问题2,如何返回ListView中Checked是否是选择状态
希望能帮忙解决:face (3): 整了好记天了!
我自己做出来大概效果是这样的
根据楼下的提示。判断选择方面也做好了。
下边是完整代码。唯一缺点就是没有文件图标。希望高手给完善 谢谢!!!#include <GUIConstantsEx.au3>
#include <ListViewConstants.au3>
#include <TreeViewConstants.au3>
#include <WindowsConstants.au3>
#include <GuiListView.au3>
#include <ButtonConstants.au3>
#include <GuiImageList.au3>
#include <GuiButton.au3>
#Region ### START Koda GUI section ### Form=
$Form1 = GUICreate("Form1", 623, 360, 209, 152)
;------------------------------------------------------------------
$Group1 = GUICtrlCreateGroup("", 4, -5, 245, 73)
GUICtrlCreateGroup("", -99, -99, 1, 1)
$Group1 = GUICtrlCreateGroup("", 250, -5, 245, 73)
GUICtrlCreateGroup("", -99, -99, 1, 1)
;------------------------------------------------------------------
;------------------------------------------------------------------
$menu_A = GUICtrlCreateMenu("菜单1[&O]");创建一个菜单控件
GUICtrlCreateMenu("菜单2[&T]");创建一个菜单控件
;-------------------------------------------------------------------
Local $button1
$button1 = GUICtrlCreateButton("刷新", 10, 6, 50, 55, $BS_FLAT)
$hImage1 = _GUIImageList_Create(30, 30, 5, 1, 0)
_GUIImageList_AddIcon($hImage1, "c:\windows\regedit.exe", 0, True)
_GUICtrlButton_SetImageList($button1, $hImage1, 2)
$Button2 = GUICtrlCreateButton("删除", 70, 6, 50, 55, $BS_FLAT)
$hImage2 = _GUIImageList_Create(30, 30, 5, 1, 0)
_GUIImageList_AddIcon($hImage2, "shell32.dll", 131, True)
_GUICtrlButton_SetImageList($Button2, $hImage2, 2)
$Button3 = GUICtrlCreateButton("关于", 130, 6, 50, 55, $BS_FLAT)
$hImage3 = _GUIImageList_Create(30, 30, 5, 1, 0)
_GUIImageList_AddIcon($hImage3, "shell32.dll", 221, True)
_GUICtrlButton_SetImageList($Button3, $hImage3, 2)
$Button4 = GUICtrlCreateButton("退出", 190, 6, 50, 55, $BS_FLAT)
$hImage4 = _GUIImageList_Create(30, 30, 5, 1, 0)
_GUIImageList_AddIcon($hImage4, "shell32.dll", 219, True)
_GUICtrlButton_SetImageList($Button4, $hImage4, 2)
;-------------------------------------------------------------------
$TreeView1 = GUICtrlCreateTreeView(8, 72, 169, 265, BitOR($TVS_HASBUTTONS, $TVS_HASLINES, $TVS_LINESATROOT, $TVS_DISABLEDRAGDROP, $TVS_SHOWSELALWAYS), $WS_EX_CLIENTEDGE)
$everyone = GUICtrlCreateTreeViewItem("所有启动项", $TreeView1)
$userrun = GUICtrlCreateTreeViewItem("HKEY_CURRENT_USER", $everyone)
$run1 = GUICtrlCreateTreeViewItem("Run", $userrun)
$runone = GUICtrlCreateTreeViewItem("RunOne", $userrun)
$machinerun = GUICtrlCreateTreeViewItem("HKEY_LOCAL_MACHINE", $everyone)
$run2 = GUICtrlCreateTreeViewItem("Run", $machinerun)
$runone1 = GUICtrlCreateTreeViewItem("RunOne", $machinerun)
$RunOnceEx = GUICtrlCreateTreeViewItem("RunOnceEx", $machinerun)
$RunServices = GUICtrlCreateTreeViewItem("RunServices", $machinerun)
$RunServicesEX = GUICtrlCreateTreeViewItem("RunServicesEX", $machinerun)
GUICtrlSetState($everyone, $GUI_EXPAND)
GUICtrlSetState($userrun, $GUI_EXPAND)
GUICtrlSetState($machinerun, $GUI_EXPAND)
;------------------------------------------------------------------
GUICtrlSetImage($TreeView1, "regedit.exe", 0);设置指定控件的位图或图标
$ListView1 = GUICtrlCreateListView("名称 |路径|信息 ", 184, 72, 433, 265)
_GUICtrlListView_SetExtendedListViewStyle($ListView1, BitOR($LVS_EX_GRIDLINES, $LVS_EX_FULLROWSELECT, $LVS_EX_SUBITEMIMAGES, $LVS_EX_CHECKBOXES))
GUICtrlSendMsg(-1, $LVM_SETCOLUMNWIDTH, 1, 250);设置“路径”显示长度
GUISetState(@SW_SHOW)
#EndRegion ### END Koda GUI section ###
up()
While 1
$nMsg = GUIGetMsg()
Switch $nMsg
Case $GUI_EVENT_CLOSE
Exit
Case $everyone
del()
up()
Case $userrun
del()
Run1()
Case $run1
del()
Run1()
Case $runone
del()
RunOne()
Case $machinerun
del()
Run2()
RunOne1()
RunOnceEx()
RunServices()
RunServicesEX()
Case $run2
del()
Run2()
Case $runone1
del()
RunOne1()
Case $RunOnceEx
del()
RunOnceEx()
Case $RunServices
del()
RunServices()
Case $RunServicesEX
del()
RunServicesEX()
Case $button1
GUICtrlSendMsg($ListView1, $LVM_DELETEALLITEMS, 0, 0)
up()
Case $Button2
dir()
Case $Button3
MsgBox(64, '关于', "BY 内蒙赤峰DJ", 5)
Case $Button4
Exit
EndSwitch
WEnd
Func up()
Run1()
RunOne()
Run2()
RunOne1()
RunOnceEx()
RunServices()
RunServicesEX()
EndFunc ;==>up
;----------------------------------------------------------------------------------------------HKEY_CURRENT_USER
Func Run1()
$Texts = "RegUserRun"
For $i = 1 To 100
$var = RegEnumVal("HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Run", $i)
If @error <> 0 Then ExitLoop
$var2 = RegRead("HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Run", $var)
GUICtrlCreateListViewItem("" & $var & "|" & $var2 & "|" & $Texts & "", $ListView1)
Next
EndFunc ;==>Run1
Func RunOne()
$Texts = "RegUserRunOne"
For $i = 1 To 100
$var = RegEnumVal("HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\RunOne", $i)
If @error <> 0 Then ExitLoop
$var2 = RegRead("HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\RunOne", $var)
GUICtrlCreateListViewItem("" & $var & "|" & $var2 & "|" & $Texts & "", $ListView1)
Next
EndFunc ;==>RunOne
;-------------------------------------------------------------------------------------------------HKEY_LOCAL_MACHINE
Func Run2()
$Texts = "RegMachineRun"
For $i = 1 To 100
$var = RegEnumVal("HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\Run", $i)
If @error <> 0 Then ExitLoop
$var2 = RegRead("HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\Run", $var)
GUICtrlCreateListViewItem("" & $var & "|" & $var2 & "|" & $Texts & "", $ListView1)
Next
EndFunc ;==>Run2
Func RunOne1()
$Texts = "RegMachineRunOne"
For $i = 1 To 100
$var = RegEnumVal("HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\RunOne", $i)
If @error <> 0 Then ExitLoop
$var2 = RegRead("HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\RunOne", $var)
GUICtrlCreateListViewItem("" & $var & "|" & $var2 & "|" & $Texts & "", $ListView1)
Next
EndFunc ;==>RunOne1
Func RunOnceEx()
$Texts = "RegMachineRunOnceEx"
For $i = 1 To 100
$var = RegEnumVal("HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\RunOnceEx", $i)
If @error <> 0 Then ExitLoop
$var2 = RegRead("HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\RunOnceEx", $var)
GUICtrlCreateListViewItem("" & $var & "|" & $var2 & "|" & $Texts & "", $ListView1)
Next
EndFunc ;==>RunOnceEx
Func RunServices()
$Texts = "RegMachineRunServices"
For $i = 1 To 100
$var = RegEnumVal("HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\RunServices", $i)
If @error <> 0 Then ExitLoop
$var2 = RegRead("HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\RunServices", $var)
GUICtrlCreateListViewItem("" & $var & "|" & $var2 & "|" & $Texts & "", $ListView1)
Next
EndFunc ;==>RunServices
Func RunServicesEX()
$Texts = "RegMachineRunServicesEX"
For $i = 1 To 100
$var = RegEnumVal("HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\RunServicesEX", $i)
If @error <> 0 Then ExitLoop
$var2 = RegRead("HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\RunServicesEX", $var)
GUICtrlCreateListViewItem("" & $var & "|" & $var2 & "|" & $Texts & "", $ListView1)
Next
EndFunc ;==>RunServicesEX
;-------------------------------------------------------------------------------------------------------
Func dir()
$log = _GUICtrlListView_GetItemCount($ListView1);获取列表视图控件的项目数
$CURRENT = "HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\"
$LOCAL = "HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\"
If MsgBox(4, '提示', '您确定要删除此项目?') = 6 Then
For $i = 0 To $log
$Text = _GUICtrlListView_GetItemTextString($ListView1, $i);获取全部列表视图中的项目
$String = StringSplit($Text, "|")
If _GUICtrlListView_GetItemChecked($ListView1, $i) = True Then
If $String = "RegUserRun" Then RegDelete($CURRENT & "Run", $String)
If $String = "RegUserRunOne" Then RegDelete($CURRENT & "RunOnce", $String)
If $String = "RegMachineRun" Then RegDelete($LOCAL & "Run", $String)
If $String = "RegMachineRunOne" Then RegDelete($LOCAL & "RunOnce", $String)
If $String = "RegMachineRunOnceEx" Then RegDelete($LOCAL & "RunOnceEx", $String)
If $String = "RegMachineRunServices" Then RegDelete($LOCAL & "RunServices", $String)
If $String = "RegMachineRunServicesEX" Then RegDelete($LOCAL & "RunServicesEX", $String)
Else
EndIf
Next
MsgBox(64, '提示', '删除成功')
Else
EndIf
del()
up()
EndFunc ;==>dir
Func del()
GUICtrlSendMsg($ListView1, $LVM_DELETEALLITEMS, 0, 0)
EndFunc ;==>del 判断项目复选框勾选情况
#Include <GuiTreeView.au3>
_GUICtrlTreeView_GetChecked($hWnd, $hItem) 感谢楼上的。。判断选择的问题解决了 呵呵
是#Include <GuiListView.au3>
_GUICtrlListView_GetItemChecked($hWnd, $iIndex)就差图标的问题了:face (37): 判断项目勾选的例子!#include <GUIListView.au3>
#include <WindowsConstants.au3>
Global $ListView, $anniu, $Text, $Texts
GUICreate("ListView", 320, 300)
$ListView = GUICtrlCreateListView("编号|姓名", 1, 1, 318, 230, -1, _
BitOR($WS_EX_CLIENTEDGE, $LVS_EX_CHECKBOXES, $LVS_EX_FULLROWSELECT, $LVS_REPORT))
$anniu = GUICtrlCreateButton("读取选中项", 100, 250, 100, 30)
_GUICtrlListView_SetColumnWidth($ListView, 0, 100)
_GUICtrlListView_SetColumnWidth($ListView, 1, 180)
GUISetState(@SW_SHOW)
_GUICtrlListView_InsertItem($ListView, '张三', 0)
_GUICtrlListView_InsertItem($ListView, '李四', 0)
_GUICtrlListView_InsertItem($ListView, '王五', 0)
_GUICtrlListView_InsertItem($ListView, '孙六', 0)
_GUICtrlListView_InsertItem($ListView, '赵七', 0)
_GUICtrlListView_InsertItem($ListView, '成八', 0)
_GUICtrlListView_InsertItem($ListView, '冯九', 0)
_GUICtrlListView_InsertItem($ListView, '钱十', 0)
_GUICtrlListView_AddSubItem($ListView, 0, "65786315", 1, 1)
_GUICtrlListView_AddSubItem($ListView, 1, "56454688", 1, 1)
_GUICtrlListView_AddSubItem($ListView, 2, "86575765", 1, 1)
_GUICtrlListView_AddSubItem($ListView, 3, "87654832", 1, 1)
_GUICtrlListView_AddSubItem($ListView, 4, "96325478", 1, 1)
_GUICtrlListView_AddSubItem($ListView, 5, "64651873", 1, 1)
_GUICtrlListView_AddSubItem($ListView, 6, "96437251", 1, 1)
_GUICtrlListView_AddSubItem($ListView, 7, "64976835", 1, 1)
While 1
$nMsg = GUIGetMsg()
Switch $nMsg
Case - 3
Exit
Case $anniu
Read()
EndSwitch
WEnd
Func Read()
$a = _GUICtrlListView_GetItemCount($ListView)
For $i = 0 To $a
$Text = _GUICtrlListView_GetItemTextString($ListView, $i)
If _GUICtrlListView_GetItemChecked($ListView, $i) = True Then $Texts &= '第:' & $i + 1 & ' 项被选中' & ' 项目文本:' & $Text & @CRLF & @CRLF
Next
MsgBox(64, '选中项目', $Texts)
$Texts = ''
EndFunc ;==>Read 这段代码最帅Func Read()
$a = _GUICtrlListView_GetItemCount($ListView)
For $i = 0 To $a
$Text = _GUICtrlListView_GetItemTextString($ListView, $i)
If _GUICtrlListView_GetItemChecked($ListView, $i) = True Then $Texts &= '第:' & $i + 1 & ' 项被选中' & ' 项目文本:' & $Text & @CRLF & @CRLF
Next
MsgBox(64, '选中项目', $Texts)
$Texts = ''
EndFunc ;==>Read
希望能帮忙解决图标的问题:face (37): 根据2#的提示。判断选择方面也做好了。请高手给个列子 完善下图标的问题:face (37): 图标的问题 应该先解决获取路径问题 本帖最后由 131738 于 2010-3-8 17:55 编辑
回复 5# nmgwddj
复制了你的源码,作为回报,给你一个收集的源码,你分析一下#cs ____________________________________
AutoIt 版本: 3.2.11.5.1
脚本作者: 老刀
QQ: 50665286
程序文件获取资料用,一般网吧写工具可以用到这个资料,给大家做参考
#ce _______________脚本开始_________________
#include <ButtonConstants.au3>
#include <GUIConstantsEx.au3>
#include <StaticConstants.au3>
#include <WindowsConstants.au3>
#include <EditConstants.au3>
#include <Array.au3>
#Region ### START Koda GUI section ### Form=
$Form1_1 = GUICreate("老刀制作:程序资料获取", 393, 301, 195, 117, _
BitOR($WS_OVERLAPPEDWINDOW, $WS_CLIPSIBLINGS),$WS_EX_ACCEPTFILES) ;主窗口
$InputFile = GuiCtrlCreateInput("",88, 8, 300, 49,$ES_AUTOHSCROLL) ;输入框(Input)控件
GUICtrlSetState(-1,$GUI_ACCEPTFILES) ;调整输入框接受拖放,并读出文件信息
GUICtrlSetBkColor(-1, 0x7A67EE) ;设置输入框背景颜色
$Button2 = GUICtrlCreateButton("获取信息", 8, 72, 75, 25, 0)
$Button1 = GUICtrlCreateButton("手改路径", 104, 72, 75, 25, 0)
$Label2 = GUICtrlCreateLabel("图标:", 16, 128, 40, 17) ;静态的 Label 控件
$Label3 = GUICtrlCreateIcon(GUICtrlRead($InputFile),0,72, 112) ;创建图标(Icon)控件
$Label4 = GUICtrlCreateLabel("文件名", 180, 128, 170, 25) ;静态的 Label 控件
$Label5 = GUICtrlCreateLabel("所在盘: ", 16, 192, 140, 25) ;静态的 Label 控件
$Label6 = GUICtrlCreateLabel("磁盘剩余空间: ", 180, 192, 170, 25) ;静态的 Label 控件
$Label7 = GUICtrlCreateLabel("文件夹大小: ", 16, 256, 170, 25) ;静态的 Label 控件
$Label8 = GUICtrlCreateLabel("可拖拽目标文件到蓝色区域", 8, 20, 74, 38) ;静态的 Label 控件
$laodao = GUICtrlCreateLabel("老刀制作QQ:50665286", 220, 256, 156, 33,_
BitOR($SS_CENTER,$SS_CENTERIMAGE), $WS_EX_STATICEDGE) ;静态的 Label 控件
#EndRegion ### END Koda GUI section ###
GUISetState()
While 1
$nMsg = GUIGetMsg()
Switch $nMsg
Case $GUI_EVENT_CLOSE ;关闭
Exit ;退出
Case $GUI_EVENT_DROPPED ;拖动文件到编辑框
_display() ;调用函数
Case $Button2 ;"获取信息"按钮事件
_display()
Case $Button1 ;"手改路径"按钮事件
$ExeDir = FileOpenDialog("选择程序路径","e:\","程序文件(*.exe)",1+2) ;文件打开对话框
GUICtrlSetData($InputFile,$ExeDir) ;将手动选择的文件写入输入框数据
EndSwitch
WEnd
Func _display()
$dir = GUICtrlRead($InputFile) ;读取输入框数据
$aName = StringSplit($dir,"\") ;以"\"分隔符将输入框字符串拆分,返回一个数组
_ArrayDisplay($aName, "输入框数据拆分结果")
MsgBox(0,"1",$aName)
$name = $aName[$aName] ;提取完整路径中的程序名
MsgBox(0,"1",$name)
If $dir = "" Then ;如果读取输入框数据为"" 则,
MsgBox(0,"错误","没有程序路径!")
ElseIf Not FileExists($dir) Then ;又如果文件或目录不存在,则提示
MsgBox(0,"错误","请确认路径是否正确,")
ElseIf StringRight($name,4) = ".lnk" Then ;再如果从右开始的4个字符=.lnk,则
$aLnk = FileGetShortcut($dir) ;获取快捷方式的各种属性
GUICtrlSetData($InputFile,$aLnk) ;修改输入框数据为快捷方式的程序名
_display()
Else
GUICtrlSetImage ($Label3,$dir) ;设置图标( 控件ID, 文件名 [, 图标名 [, 图标类型]] )
GUICtrlSetData($Label4,"文件名: " & $name)
GUICtrlSetData($Label5,"所在盘: " & $aName & "\")
GUICtrlSetData($Label6,"磁盘剩余空间: " & Round(DriveSpaceFree($aName),2) & " MB")
$size = StringMid($dir,1,StringLen($dir)-StringLen($name))
GUICtrlSetData($Label7,"程序目录大小: " & Round(DirGetSize($size)/1048576,2) & " MB")
EndIf
EndFunc 刚才在论坛搜索,却搜不到了。。。。。。。。。。。 呵呵 。 好东西啊。 界面也很好看嘛。。 很清水 图标的问题 应该先解决获取路径问题
afan 发表于 2010-3-8 17:42 http://www.autoitx.com/images/common/back.gif
我看了第一个图里那个工具。不是绝对路径 它也是获取不到图标的。
能保证得到路径就能获取图标就可以。其他。比如加了参数的启动项 那个工具也获取不到。
要是 afan能解决的那 话更好不过了。如果没有太好的办法。就给我个有路径就能获取图标的例子 3Q 回复 11# nmgwddj
一会给你写 本帖最后由 lchl0588 于 2010-3-8 20:22 编辑
呵呵,LZ的标题 也不明确,应该改下哦,,,,关于图标,请参见这里有顽固不化与偶的详解
还有一个参数貌似能用:_GUIImageList_AddBitmap
回复 11# nmgwddj
有个DLL 图标大全,本身里面包含在内
请问第一个图是否还有其它文件?
上述是绝对路径,随机貌似需要自定义函数! 帅,等看afan出手 楼上那个帖子我看过了。所以才做出上边的图标按钮,,、
我的意思是ListView控件中的图标,获取每个启动项绝对路径 然后用什么函数就不明白了。
我试了GUICtrlSetImage 它只支持DLL 和EXE 另外一些后缀名的文件没办法获取到图标!
我再仔细看下你的例子 谢谢。
afan 先别睡觉啊 给个列子就行 我慢慢研究!