AutoHotkey Homepage AutoHotkey Community
Let's help each other out
 
 FAQFAQ   SearchSearch   MemberlistMemberlist   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

Getting icons from shortcut.

 
Post new topic   Reply to topic    AutoHotkey Community Forum Index -> Ask for Help
View previous topic :: View next topic  
Author Message
Phoenix



Joined: 23 Sep 2005
Posts: 40

PostPosted: Fri Feb 22, 2008 12:44 pm    Post subject: Getting icons from shortcut. Reply with quote

Code:

FileGetShortcut, %A_LoopFileFullPath%,,,,, ShortIcon
msgbox, %shorticon%
If (ShortIcon <> "")
{
      msgbox, test
      IL_Add(ImageListID, ShortIcon,1)
}


I am trying to add the icon from a shortcut to an imagelist of a treeview. This code should accomplish this. But no icon is added to the imagelist? Any theories on this?
Back to top
View user's profile Send private message
jaco0646



Joined: 07 Oct 2006
Posts: 582
Location: MN, USA

PostPosted: Sat Feb 23, 2008 5:27 am    Post subject: Reply with quote

If the icon used by a shortcut is the same icon used by its target, FileGetShortcut will often return a blank value for OutIcon. To work around this, use the shortcut's target path for its icon when OutIcon is blank. Here's an example.

Code:
ID := IL_Create()
Gui, Add, TreeView, ImageList%ID%
Loop, %A_StartMenuCommon%\Programs\*.lnk
{
 FileGetShortcut, %A_LoopFileFullPath%, Target,,,,Icon
 If !(Icon)
  Icon := Target
 num := IL_Add(ID, Icon)
 TV_Add(A_LoopFileName, 0, "Icon" num)
}
Gui, Show
return
GuiClose:
ExitApp

_________________
http://autohotkey.net/~jaco0646/
Back to top
View user's profile Send private message Visit poster's website
Phoenix



Joined: 23 Sep 2005
Posts: 40

PostPosted: Sat Feb 23, 2008 10:24 am    Post subject: Reply with quote

The trouble is that the target is C:\WINDOWS\system32\control.exe telephon.cpl,@0,1 so that won't return any valid icon. Instead I have manually chosen an icon for my shortcut and want to add that icon into the imagelist.

Code:

SplitPath, A_LoopFileName,,,,Filename
msgbox, %A_LoopFileFullPath%
FileGetShortcut, %A_LoopFileFullPath%,,,,, ShortIcon
msgbox, %shorticon%
If (ShortIcon <> "")
{
     msgbox, test
     IL_Add(ImageListID, ShortIcon,1)
}


The thing is that the msgbox, %shorticon% returns the correct path of the icon which is C:\WINDOWS\system32\telephon.cpl. But it is not added to the imagelist
Back to top
View user's profile Send private message
jaco0646



Joined: 07 Oct 2006
Posts: 582
Location: MN, USA

PostPosted: Sat Feb 23, 2008 5:40 pm    Post subject: Reply with quote

Are you sure it's not being added to the ImageList? Try assigning your IL_Add function to a variable (as in my previous example), and then report that variable in a message box to see if it's blank.

Code:
If (ShortIcon <> "")
{
 num := IL_Add(ImageListID, ShortIcon,1)
 msgbox,% num
}

_________________
http://autohotkey.net/~jaco0646/
Back to top
View user's profile Send private message Visit poster's website
Display posts from previous:   
Post new topic   Reply to topic    AutoHotkey Community Forum Index -> Ask for Help All times are GMT
Page 1 of 1

 
Jump to:  
You can post new topics in this forum
You can reply to topics in this forum


Powered by phpBB © 2001, 2005 phpBB Group