04. november 2002 - 18:28Der er
12 kommentarer og 2 løsninger
Hente Windows Ikoner
Jeg har tidligere set kode, som kunne hente ikonet ud af en bestemt fil .. Men hvad med at hente ikonet ved at specificere filtypen -- altså fx. "doc".. Kan det lade sig gøre? og hvordan?
Jeg kunne godt tænke mig en funktion (API kald eller whatever) som kunne returnere ikonet for en bestemt filtype og ikke fra en exe-fil eller fra andre bestemte filer .. altså så jeg ikke skal bruge noget filnavn/-sti for at hente ikonet, men bare filens extension; som jeg nævnte før, fx. "doc"
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
Private Sub Form_Load() 'Call LoadIcon(Picture1, "C:\Windows\Winmine.exe") 'File Call LoadIcon(Picture1, "C:\Windows\Script.doc") 'Type 'Call LoadIcon(Picture1, "C:\Windows") 'Mappe End Sub
Public Sub LoadIcon(pic As Object, strPath As String) Dim mIcon As Long pic.Cls pic.AutoRedraw = True mIcon = ExtractAssociatedIcon(App.hInstance, strPath, 2) DrawIconEx pic.hdc, 5, 5, mIcon, 32, 32, 0, 0, DI_NORMAL DestroyIcon mIcon End Sub
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
Private Sub Form_Load() Call LoadIcon(Picture1, "zip") 'Type End Sub
Public Sub LoadIcon(pic As Object, strType As String) Dim mIcon As Long pic.Cls pic.AutoRedraw = True strType = App.Path & "kill." & strType Open strType For Binary As #1: Close #1 mIcon = ExtractAssociatedIcon(App.hInstance, strType, 2) Kill strType DrawIconEx pic.hdc, 5, 5, mIcon, 32, 32, 0, 0, DI_NORMAL DestroyIcon mIcon End Sub
vise en liste over filer på en FTP, og benytte ikonerne, som var tildelt filerne på din egen computer (undtagen exe filer).
Synes godt om
Ny brugerNybegynder
Din løsning...
Tilladte BB-code-tags: [b]fed[/b] [i]kursiv[/i] [u]understreget[/u] Web- og emailadresser omdannes automatisk til links. Der sættes "nofollow" på alle links.