Listview with large thumbail without stretching

Get help with using AutoHotkey (v1.1 and older) and its commands and hotkeys
smarq8
Posts: 69
Joined: 16 Jan 2016, 00:33

Listview with large thumbail without stretching

20 Jan 2018, 16:59

I need to display in my LV image thimbails. My code already work except that I need larger icons with preserved aspect ratio.
Any help?

Code: Select all

#include <GDIp>
Gdip_Startup()
Gui, Add, ListView, r30 w300 hwndhLV, image|w|h  ; Create a ListView.
dir := "D:\x\ClearedText\tesseract\old\oem0_psm6_20180114221528_DONE\letters\105"
ImageListID := IL_Create(10)  ; Create an ImageList to hold 10 small icons.
LV_SetImageList(ImageListID)  ; Assign the above ImageList to the current ListView
Gui Show
loop,Files,% dir "\*.png"
{
	if (A_Index==2)
		LV_ModifyCol()
	;msgbox,% A_LoopFileFullPath
	Gdip_GetImageDimensionsFile(A_LoopFileFullPath,w,h)
	IL_Add(ImageListID, A_LoopFileFullPath,0xffffff,1)
	
	LV_Add("Icon" . A_Index,"",w,h)
	
	;msgbox,% hlv
	;LV_Add("", A_Index, "n/a")
	;LV_EX_SetSubItemImage(hLV, A_Index, 2, A_Index)
	;LV_EX_SetSubItemImage(hLV, A_Index, 3, A_Index)
	;LV_EX_SetSubItemImage(hLV, A_Index, 4, A_Index)
	;LV_EX_SetSubItemImage(hLV, A_Index, 4, A_Index)
	;LV_EX_SetSubItemImage(hLV, A_Index, 5, A_Index)
	;msgbox
	
}
LV_ModifyCol(2,"Sort Logical")

return

GuiClose:
ExitApp

Gdip_GetImageDimensionsFile(file, ByRef Width, ByRef Height){
	pBitmap  := Gdip_CreateBitmapFromFile(file)
	Gdip_GetImageDimensions(pBitmap,Width,Height)
	Gdip_DisposeImage(pBitmap)
}

f4::reload
#Include LV_EX.ahk
Image

I need something similar to this but with larger icons
Image
garry
Posts: 3763
Joined: 22 Dec 2013, 12:50

Re: Listview with large thumbail without stretching

21 Jan 2018, 04:47

just a small example

Code: Select all

#warn
#noenv
Setworkingdir,%a_scriptdir%
Gui,2:default

e4x=
(Ltrim Join`r`n
VOLUME;Sndvol32.exe
CHARMAP;Charmap.exe
Notepad;Notepad.exe
mozilla;%a_programfiles%\Mozilla Firefox\Firefox.exe
)
   Gui,2:Add, ListView, backgroundGray  checked grid x10 y5  h160 w400 +hscroll altsubmit vMLV1A gMLV1B      , Icon|Program
   gosub,lb
gui,2:show, x100 y10 h180 w430,LV-Icon-Check --- Click on column-2 to start
return

2Guiclose:
exitapp


lb:
Gui,2:Submit,nohide
Gui,2:ListView,mlv1a
t1:=150
t2:=230

   LV_ModifyCol(1,T1)
   LV_ModifyCol(2,T2)

  ;ILStatus := IL_Create(1,1,0)                ;small
   ILStatus := IL_Create(1,1,1)                ;bigger
   LV_SetImageList(ILStatus, 1)
LV_Delete()
GuiControl,2: -Redraw,MLV1a
loop,parse,e4x,`n,`r
  {
  x:=a_loopfield
  c1=
  c2=
  IconNumber := IL_Add(ILSTATUS, "%pictxx05%" )      ;- clear with picture which not exist
  stringsplit,C,x,`;,
  SplitPath,c2, name, dir, ext, name_no_ext, drive
  IconNumber := IL_Add(ILSTATUS, C2 )
  LV_Add("icon" . IconNumber ,C1,name_no_ext)
  }
GuiControl,2: +Redraw,MLV1a
LV_ModifyCol(1,"right")     ;- move text to right
return
;-----------------------------------------------------------------


mlv1b:
Gui,2:submit,nohide
Gui,2:ListView, mlv1a
t1a:=(t1+20)
If A_GuiEvent = Normal
   {
    MouseGetPos,x,y
       {
       if x<%T1%
          return
       if x>%T1a%
          {
          LV_GetText(C2,A_EventInfo,2)
          ;msgbox, 262208, C2,%c2%
          run,%c2%
          return
          }
       }
}
return
;==============================================
Last edited by garry on 21 Jan 2018, 05:30, edited 1 time in total.
smarq8
Posts: 69
Joined: 16 Jan 2016, 00:33

Re: Listview with large thumbail without stretching

21 Jan 2018, 04:59

it also stretch my images without aspect ratio

Image
just me
Posts: 9453
Joined: 02 Oct 2013, 08:51
Location: Germany

Re: Listview with large thumbail without stretching

21 Jan 2018, 05:37

All images in an ImageList have the same dimensions. You can set the dimensions using IL_EX_SetSize() immediately after you created the ImageList.

Win Vista+ provides an additional creation flag ILC_ORIGINALSIZE = 0x00010000 which might permit to add images smaller than the specified dimensions.I didn't test it as yet.
smarq8
Posts: 69
Joined: 16 Jan 2016, 00:33

Re: Listview with large thumbail without stretching

21 Jan 2018, 07:38

here is my solution using ILC_ORIGINALSIZE.
Now Im wondering is it possible to center image inside tile because it is always aligned to left up corner.
I also need to load images other than .bmp

Image

Code: Select all

#include <GDIp>
Gdip_Startup()
#Singleinstance, force 

	ILC_COLOR32 := 0x20 
	ILC_ORIGINALSIZE := 0x00010000
	dir := "D:\x\ClearedText\tesseract\old\oem0_psm6_20180114221528_DONE\letters\105"
	isizew := 128
	isizeh := 128
	hIml := ImageList_Create(isizew, isizeh, ILC_COLOR32|ILC_ORIGINALSIZE, 100, 100) 
	;==============================================================
	Gui, Add, ListView, w600 h600 HWNDhLV grid, icon&A_Index|w|h
	LV_SetImageList(hIml,1) ; list mode (default)
	;==============================================================
	;Gui, Add, ListView, w600 h600 HWNDhLV icon, icon&A_Index|w|h
	;LV_SetImageList(hIml,0) ; icon mode
	;==============================================================
	Gui, Show, autosize 
	loop,% dir "\*.bmp"
	{ 
		if (A_Index<25)
			continue
		Gdip_GetImageDimensionsFile(A_LoopFileFullPath,w,h)
		m := (w<h ? isizeh/h : isizew/w)
		hIcon := API_LoadImage(A_LoopFileFullPath, 0, round(w*m), round(h*m), 0x10) ; fit to isize
		;hIcon := API_LoadImage(A_LoopFileFullPath, 0, w, h, 0x10) ; use oryginal size but crop image if larger than isize
		i := ImageList_Add( hIml, hIcon ) 
		;LV_Add("Icon" A_Index-1,A_Index,A_Index) 
		LV_Add("Icon" . i+1, A_Index,w,h)
		if (i==1)
			LV_ModifyCol()
		;msgbox,% i
	}
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
}

Gdip_GetImageDimensionsFile(file, ByRef Width, ByRef Height){
	pBitmap  := Gdip_CreateBitmapFromFile(file)
	Gdip_GetImageDimensions(pBitmap,Width,Height)
	Gdip_DisposeImage(pBitmap)
}

map(x, in_min, in_max, out_min, out_max) {
  return (x - in_min) * (out_max - out_min) / (in_max - in_min) + out_min
}

Return to “Ask for Help (v1)”

Who is online

Users browsing this forum: Google [Bot], Joey5, RandomBoy and 369 guests