Page 1 of 1

Bigger icon size in ListIcon (large icon mode)

Posted: Sun Sep 23, 2007 10:54 am
by JCV
How to make the icons in ListIcon larger than the default size in large icon mode?
The icon size is very small in my screen and I want to make it larger than the default large size.

Anyone?

Posted: Sun Sep 23, 2007 11:23 am
by srod
Not sure you can (at least without using custom / owner draw) because Window's list view controls rely on system settings as provided by GetSystemMetrics_() when positioning icons in icon view etc,

Have a look at #SM_CXICONSPACING and #SM_CYICONSPACING under GetSystemMetrics_().

I could be wrong though.


**EDIT : damn, blast and curse that Sparkie fella!

:) Only kidding of course Sparks!

Posted: Sun Sep 23, 2007 1:48 pm
by Sparkie
Not fully tested but seems to work ok on WinXPSP2 with PB4.10B3

***Edit to remove code****
I'll repost when I debug it properly ;)

***Edit to replace code*** There was no bug, it was me :P

Code: Select all

;...New icon size 
iconW = 100 
iconH = 100 

;...Create some images for this example 
zeroImg = CreateImage(0, iconW, iconH) 
StartDrawing(ImageOutput(0)) 
Box(0, 0, iconW, iconH, RGB(0, 0, 0)) 
StopDrawing() 

greenImg = CreateImage(1, iconW, iconH) 
StartDrawing(ImageOutput(1)) 
Box(0, 0, iconW, iconH, RGB(0, 255, 0)) 
StopDrawing() 

blueImg = CreateImage(2, iconW, iconH) 
StartDrawing(ImageOutput(2)) 
Box(0, 0, iconW, iconH, RGB(0, 0, 255)) 
StopDrawing() 

redImg = CreateImage(3, iconW, iconH) 
StartDrawing(ImageOutput(3)) 
Box(0, 0, iconW, iconH, RGB(255, 0, 0)) 
StopDrawing() 



;...Create our newly sized image list 
newIL = ImageList_Create_(iconW, iconH, #ILC_COLOR32, 0, 20) 

;...Add our images 
ImageList_Add_(newIL, ImageID(0), 0) 
ImageList_Add_(newIL, ImageID(1), 0) 
ImageList_Add_(newIL, ImageID(2), 0) 
ImageList_Add_(newIL, ImageID(3), 0) 

If OpenWindow(0, 0, 0, 700, 500, "",  #PB_Window_SystemMenu | #PB_Window_ScreenCentered) And CreateGadgetList(WindowID(0)) 
  ListIconGadget(0, 10, 10, 680, 480, "", 200) 
  ChangeListIconGadgetDisplay(0, #PB_ListIcon_LargeIcon) 
  For i = 0 To 3 
    item$ = "Item " + Str(i) 
    AddGadgetItem(0 , i, item$, greenImg) 
  Next  i 
  FreeImage(1) 
  For i = 4 To 7 
    item$ = "Item " + Str(i) 
    AddGadgetItem(0 , i, item$, blueImg) 
  Next  i 
  FreeImage(2) 
  For i = 8 To 11 
     item$ = "Item " + Str(i) 
     AddGadgetItem(0 , i, item$, redImg) 
  Next  i 
  FreeImage(3) 
  FreeImage(0) 
  ;...Get handle to current ListIconGadget normal image list 
  oldIL = SendMessage_(GadgetID(0), #LVM_GETIMAGELIST, #LVSIL_NORMAL, 0) 
  ;...Replace the old image list with our new one 
  SendMessage_(GadgetID(0), #LVM_SETIMAGELIST, #LVSIL_NORMAL, newIL) 
  ;...Destroy the old image list 
  ImageList_Destroy_(oldIL) 
  Repeat : Until WaitWindowEvent() = #PB_Event_CloseWindow 
EndIf 
End

Posted: Sun Sep 23, 2007 2:11 pm
by srod
Nice one sparks! :wink:

A slight ammendment to provide a mask allows Windows to blend the images when an item is selected. Just add the #ILC_MASK flag to the Image_List_Create function.

Code: Select all

;...New icon size 
iconW = 100
iconH = 100

;...Create some images for this example 
zeroImg = CreateImage(0, iconW, iconH) 
StartDrawing(ImageOutput(0)) 
Box(0, 0, iconW, iconH, RGB(0, 0, 0)) 
StopDrawing() 

greenImg = CreateImage(1, iconW, iconH) 
StartDrawing(ImageOutput(1)) 
Box(0, 0, iconW, iconH, RGB(0, 255, 0)) 
StopDrawing() 

blueImg = CreateImage(2, iconW, iconH) 
StartDrawing(ImageOutput(2)) 
Box(0, 0, iconW, iconH, RGB(0, 0, 255)) 
StopDrawing() 

redImg = CreateImage(3, iconW, iconH) 
StartDrawing(ImageOutput(3)) 
Box(0, 0, iconW, iconH, RGB(255, 0, 0)) 
StopDrawing() 



;...Create our newly sized image list 
newIL = ImageList_Create_(iconW, iconH, #ILC_COLOR32|#ILC_MASK, 0, 20) 

;...Add our images 
ImageList_Add_(newIL, ImageID(0), 0) 
ImageList_Add_(newIL, ImageID(1), 0) 
ImageList_Add_(newIL, ImageID(2), 0) 
ImageList_Add_(newIL, ImageID(3), 0) 

If OpenWindow(0, 0, 0, 700, 500, "",  #PB_Window_SystemMenu | #PB_Window_ScreenCentered) And CreateGadgetList(WindowID(0)) 
  ListIconGadget(0, 10, 10, 680, 480, "", 200) 
  ChangeListIconGadgetDisplay(0, #PB_ListIcon_LargeIcon) 
  For i = 0 To 3 
    item$ = "Item " + Str(i) 
    AddGadgetItem(0 , i, item$, greenImg) 
  Next  i 
  FreeImage(1) 
  For i = 4 To 7 
    item$ = "Item " + Str(i) 
    AddGadgetItem(0 , i, item$, blueImg) 
  Next  i 
  FreeImage(2) 
  For i = 8 To 11 
     item$ = "Item " + Str(i) 
     AddGadgetItem(0 , i, item$, redImg) 
  Next  i 
  FreeImage(3) 
  FreeImage(0) 
  ;...Get handle to current ListIconGadget normal image list 
  oldIL = SendMessage_(GadgetID(0), #LVM_GETIMAGELIST, #LVSIL_NORMAL, 0) 
  ;...Replace the old image list with our new one 
  SendMessage_(GadgetID(0), #LVM_SETIMAGELIST, #LVSIL_NORMAL, newIL) 
  ;...Destroy the old image list 
  ImageList_Destroy_(oldIL) 
  Repeat : Until WaitWindowEvent() = #PB_Event_CloseWindow 
EndIf 
End

Posted: Sun Sep 23, 2007 2:17 pm
by Sparkie
Thanks for adding the mask flag srod. :)

There was no bug so we should be good to go 8)

Posted: Sun Sep 23, 2007 2:27 pm
by srod
I thought of trying simply replacing the image list as you've done, but having read what was in the WinAPI help guide, decided that it wouldn't work if we increased the image size!

Teach me to swear by that help guide! :wink:

Posted: Sun Sep 23, 2007 3:14 pm
by Sparkie
Nothing ventured...nothing gained :)

Posted: Mon Sep 24, 2007 10:01 am
by JCV
Thanks guys! 8)