因此,如果想要“提取程序的图标”,就需要找到可以完成此功能的软件(程序),并且此程序支持“命令行”方式运行。
“提取程序的图标”的工具软件,搜索就能找到,如 IconsExtract 等, *** 作和使用都比较方便 ,但大多是用 GUI 窗口方式(即用户手动交互式 *** 作)来完成,并不支持命令行方式。
控件: 一个 CommandButton 一个 CommonDialog 一个 PictureBox-------------代码------------------Option ExplicitPrivate Declare Function DrawIcon Lib "user32" (ByVal hdc As Long, ByVal x As Long, ByVal y As Long, ByVal hIcon As Long) As Long
Private Declare Function ExtractIcon Lib "shell32.dll" Alias "ExtractIconA" (ByVal hInst As Long, ByVal lpszExeFileName As String, ByVal nIconIndex As Long) As Long
Private Sub Command1_Click()
Dim total As Long
Dim p As Long
Dim i As Integer
Me.Picture1.Cls
Me.CommonDialog1.Filter = "图标|*.Exe*.Ico*.Dll"
Me.CommonDialog1.ShowOpen
If Dir(Me.CommonDialog1.FileName) <>"" Then
If ExtractIcon(App.hInstance, Me.CommonDialog1.FileName, -1) = 0 Then '如果没有图标
MsgBox "No Icon!"
Else
p = ExtractIcon(App.hInstance, Me.CommonDialog1.FileName, 0) '读取每个图标
DrawIcon Picture1.hdc, 0, 0, p
End If
End If
End Sub
百分之百可用,只限jdk1.4用不了,会报错。本人试了,jdk1.6可以使用public static void main(String[] args) throws Exception {
File file = new File( "D:\\Program Files\\Tencent\\QQ\\Bin\\QQ.exe") \\提取图标的应用程序
OutputStream inStream = new FileOutputStream(new File("c:\\45.png"))\\图标保存地址
try {
BufferedImage www = (BufferedImage)((ImageIcon) toIcon(file)).getImage()
ImageIO.write(www, "png", inStream)
inStream.flush()
inStream.close()
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace()
}
}
public static Icon toIcon(File file) throws FileNotFoundException {
ShellFolder shellFolder = ShellFolder.getShellFolder(file)
Icon icon = new ImageIcon(shellFolder.getIcon(true))
return icon
}
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)