AutoHotkey Community

It is currently May 27th, 2012, 10:38 am

All times are UTC [ DST ]




Post new topic Reply to topic  [ 8 posts ] 
Author Message
PostPosted: December 21st, 2007, 12:11 pm 
Offline

Joined: May 24th, 2006, 2:49 pm
Posts: 4511
Location: Belgrade
This code shows you how to load icons of arbitrary size in ListView and show them with 32bit color palete. You can tweak isize & color.

Code:
#Singleinstance, force

   ILC_COLOR := 0, ILC_COLOR4 := 0x4, ILC_COLOR8 := 0x8, ILC_COLOR16 := 0x10, ILC_COLOR24 := 0x18, ILC_COLOR32 := 0x20
 
   isize := 128
   color := ILC_COLOR16

   Gui, Add, ListView, w600 h600 Icon HWNDhLV, icon
   
   hIml := ImageList_Create(isize, isize, color, 100, 100)

   LV_SetImageList(hIml)
   loop, c:\windows\*
   {
      hIcon := LoadIcon(A_LoopFileFullPath, 1, isize)     ; LR_LOADFROMFILE
      if !hIcon
         continue
     i := ImageList_AddIcon( hIml, hIcon )
      LV_Add("Icon" i+1, i " "A_LoopFileName)
   }
   Gui, Show, autosize
return

ListView_SetImageList( hwnd, hIml, iImageList=0) {
   SendMessage, 0x1000+3, iImageList, hIml, , ahk_id %hwnd%
   return ErrorLevel
}

ImageList_Create(cx,cy,flags,cInitial,cGrow){
   return DllCall("comctl32.dll\ImageList_Create", "int", cx, "int", cy, "uint", flags, "int", cInitial, "int", cGrow)
}

ImageList_Add(hIml, hbmImage, hbmMask=""){
   return DllCall("comctl32.dll\ImageList_Add", "uint", hIml, "uint",hbmImage, "uint", hbmMask)
}

ImageList_AddIcon(hIml, hIcon) {
   return DllCall("comctl32.dll\ImageList_ReplaceIcon", "uint", hIml, "int", -1, "uint", hIcon)
}

API_ExtractIcon(Icon, Idx=0){
   return DllCall("shell32\ExtractIconA", "UInt", 0, "Str", Icon, "UInt",Idx)
}


API_LoadImage(pPath, uType, cxDesired, cyDesired, fuLoad) {
   return,  DllCall( "LoadImage", "uint", 0, "str", pPath, "uint", uType, "int", cxDesired, "int", cyDesired, "uint", fuLoad)
}

LoadIcon(Filename, IconNumber, IconSize) {
   DllCall("PrivateExtractIcons"
          ,"str",Filename,"int",IconNumber-1,"int",IconSize,"int",IconSize
            ,"uint*",h_icon,"uint*",0,"uint",1,"uint",0,"int")
   if !ErrorLevel
         return h_icon
}



Image

_________________
Image


Last edited by majkinetor on December 21st, 2007, 7:16 pm, edited 1 time in total.

Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: December 21st, 2007, 4:08 pm 
Offline

Joined: October 27th, 2006, 10:12 am
Posts: 649
Works nicely with .ico files but not with .jpg or .gif.


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: December 21st, 2007, 4:29 pm 
Offline

Joined: May 24th, 2006, 2:49 pm
Posts: 4511
Location: Belgrade
Yes.

I beleive the only thing that should be changed is:
ImageList_AddIcon to ImageList_Add and set flag to 0 instad 2...

Image

Code

Code:
#Singleinstance, force

   ILC_COLOR := 0, ILC_COLOR4 := 0x4, ILC_COLOR8 := 0x8, ILC_COLOR16 := 0x10, ILC_COLOR24 := 0x18, ILC_COLOR32 := 0x20
 
   isize := 200
   color := ILC_COLOR32

   Gui, Add, ListView, w600 h600 Icon HWNDhLV, icon
   
   hIml := ImageList_Create(isize, isize, color, 100, 100)

   LV_SetImageList(hIml)
   loop, C:\Windows\*.bmp
   {
      hIcon := API_LoadImage(A_LoopFileFullPath, 0, isize, isize, 0x10)     ; LR_LOADFROMFILE
      i := ImageList_Add( hIml, hIcon )
      LV_Add("Icon" i+1, i " "A_LoopFileName)
   }
   Gui, Show, autosize


return

ListView_SetImageList( hwnd, hIml, iImageList=0) {
   SendMessage, 0x1000+3, iImageList, hIml, , ahk_id %hwnd%
   return ErrorLevel
}

ImageList_Create(cx,cy,flags,cInitial,cGrow){
   return DllCall("comctl32.dll\ImageList_Create", "int", cx, "int", cy, "uint", flags, "int", cInitial, "int", cGrow)
}

ImageList_Add(hIml, hbmImage, hbmMask=""){
   return DllCall("comctl32.dll\ImageList_Add", "uint", hIml, "uint",hbmImage, "uint", hbmMask)
}

ImageList_AddIcon(hIml, hIcon) {
   return DllCall("comctl32.dll\ImageList_ReplaceIcon", "uint", hIml, "int", -1, "uint", hIcon)
}

API_ExtractIcon(Icon, Idx=0){
   return DllCall("shell32\ExtractIconA", "UInt", 0, "Str", Icon, "UInt",Idx)
}


API_LoadImage(pPath, uType, cxDesired, cyDesired, fuLoad) {
   return,  DllCall( "LoadImage", "uint", 0, "str", pPath, "uint", uType, "int", cxDesired, "int", cyDesired, "uint", fuLoad)
}

_________________
Image


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: December 21st, 2007, 7:17 pm 
Offline

Joined: May 24th, 2006, 2:49 pm
Posts: 4511
Location: Belgrade
Actually, I uploaded new version which doesn't make a difference. New LoadIcon load's everything.

_________________
Image


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: April 10th, 2009, 6:26 am 
Offline

Joined: February 11th, 2007, 4:10 pm
Posts: 185
It seems that only bmp, ico and cur can be loaded???


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: April 13th, 2009, 5:57 pm 
Offline
User avatar

Joined: September 8th, 2008, 12:26 am
Posts: 1048
Location: Ploieşti, RO
MSDN link
MSDN wrote:
You must destroy all icons extracted by PrivateExtractIcons by calling the DestroyIcon function.

Regardless, it doesn't work in Win9x, since the function has first been implemented in Win2000. :(

Can it be replaced by an existing function, when used on such OS? I see the API_ExtractIcon function is not used in your script.


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: May 5th, 2011, 7:17 pm 
Anyone figured out how to fix memory usage for this? I know you need DestroyIcon Function to free memory of items no longer used, but I don't know how to use it in ahk.
My script is sometimes using memory up until 500 MB or more :?

Thanks majkinetor anyway


Report this post
Top
  
Reply with quote  
 Post subject:
PostPosted: May 20th, 2011, 10:00 am 
Offline
User avatar

Joined: November 19th, 2010, 9:54 am
Posts: 184
@ Drugwash & Gruffalo

An easy and even better workaround is to use EmptyMem by heresy.
Just call the function below after you load or unload your listviews.


Code:
EmptyMem(PID=0){
   h := DllCall("OpenProcess", "UInt", 0x001F0FFF, "Int", 0, "Int", !PID ? DllCall("GetCurrentProcessId") : PID)
   DllCall("SetProcessWorkingSetSize", "UInt", h, "Int", -1, "Int", -1)
   DllCall("CloseHandle", "Int", h)
   }


Report this post
Top
 Profile  
Reply with quote  
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 8 posts ] 

All times are UTC [ DST ]


Who is online

Users browsing this forum: No registered users and 9 guests


You can post new topics in this forum
You can reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Powered by phpBB® Forum Software © phpBB Group