How can I place 32x32 icons in one column?

Just starting out? Need help? Post your questions and find answers here.
AZJIO
Addict
Addict
Posts: 2281
Joined: Sun May 14, 2017 1:48 am

How can I place 32x32 icons in one column?

Post by AZJIO »

Code: Select all

#LIG = 0

Define hIcon
Define p.POINT
If OpenWindow(0, 100, 100, 400, 600, "example", #PB_Window_SystemMenu | #PB_Window_ScreenCentered)
	ListIconGadget(#LIG, 5, 5, 390, 590, "Name", 100, #PB_ListIcon_FullRowSelect | #PB_ListIcon_AlwaysShowSelection)
	AddGadgetColumn(#LIG, 1, "Address", 250)
	ExtractIconEx_("Shell32.dll", 3, @hIcon, 0, 1)        ; 32
	SetGadgetAttribute(#LIG, #PB_ListIcon_DisplayMode, #PB_ListIcon_LargeIcon)
	For i = 0 To 11
		AddGadgetItem(#LIG, i, "fuf " + Str(i), hIcon)
		p\x = 5
		p\y = i * 34
		SendMessage_(GadgetID(#LIG), #LVM_SETITEMPOSITION32, i, @p)
		; SendMessage_(GadgetID(#LIG), #LVM_SETITEMPOSITION, i, p\x | (p\y << 32))
	Next
	Repeat : Until WaitWindowEvent()=#PB_Event_CloseWindow
	DestroyIcon_(hIcon)
EndIf
Olli
Addict
Addict
Posts: 1306
Joined: Wed May 27, 2020 12:26 pm

Re: How can I place 32x32 icons in one column?

Post by Olli »

1)
The external function does not send a direct pointor.
It sends a pointor into a table of icon handles.

2)
I am not sure that the external function accepts a 0 value
when the coder needs no small icon, so I also add a void pointor.

Code: Select all

#LIG = 0

Define void
Define iconTable
Define hIcon
Define p.POINT
If OpenWindow(0, 100, 100, 400, 600, "example", #PB_Window_SystemMenu | #PB_Window_ScreenCentered)
	ListIconGadget(#LIG, 5, 5, 390, 590, "Name", 100, #PB_ListIcon_FullRowSelect | #PB_ListIcon_AlwaysShowSelection)
	AddGadgetColumn(#LIG, 1, "Address", 250)
	ExtractIconEx_("Shell32.dll", 3, @iconTable, @void, 1)        ; 32
	hIcon = peekI(iconTable)
	SetGadgetAttribute(#LIG, #PB_ListIcon_DisplayMode, #PB_ListIcon_LargeIcon)
	For i = 0 To 11
		AddGadgetItem(#LIG, i, "fuf " + Str(i), hIcon)
		p\x = 5
		p\y = i * 34
		SendMessage_(GadgetID(#LIG), #LVM_SETITEMPOSITION32, i, @p)
	Next
	Repeat : Until WaitWindowEvent()=#PB_Event_CloseWindow
	DestroyIcon_(hIcon)
EndIf
RASHAD
PureBasic Expert
PureBasic Expert
Posts: 5043
Joined: Sun Apr 12, 2009 6:27 am

Re: How can I place 32x32 icons in one column?

Post by RASHAD »

Code: Select all

#LIG = 0

Define hIcon
Define p.POINT
If OpenWindow(0, 100, 100, 400, 600, "example", #PB_Window_SystemMenu | #PB_Window_ScreenCentered)
	ListIconGadget(#LIG, 5, 5, 84, 590, "Name", 64, #PB_ListIcon_FullRowSelect | #PB_ListIcon_AlwaysShowSelection)
	AddGadgetColumn(#LIG, 1, "Address", 250)
	ExtractIconEx_("Shell32.dll", 3, @hIcon, 0, 1)        ; 32
	SetGadgetAttribute(#LIG, #PB_ListIcon_DisplayMode, #PB_ListIcon_LargeIcon)
	For i = 0 To 11
		AddGadgetItem(#LIG, i, "fuf " + Str(i), hIcon)
		p\x = 5
		p\y = i * 34
		SendMessage_(GadgetID(#LIG), #LVM_SETITEMPOSITION32, i, @p)
		; SendMessage_(GadgetID(#LIG), #LVM_SETITEMPOSITION, i, p\x | (p\y << 32))
	Next
	Repeat : Until WaitWindowEvent()=#PB_Event_CloseWindow
	DestroyIcon_(hIcon)
EndIf
Egypt my love
Olli
Addict
Addict
Posts: 1306
Joined: Wed May 27, 2020 12:26 pm

Re: How can I place 32x32 icons in one column?

Post by Olli »

@RASHAD

Glad to read you. Hope you are fine.
I am interested by your suggest. Mainly, you test a lot before posting a code.

After a check on the microSoft documentation ExtractIconExA, I see my 2nd remark is false (no need a void pointor).

But my 1st remark seems to be right, except if the microSoft documentation is false.

Code: Select all

ExtractIconEx_(... , @hicon, ...)
Debug hIcon ; <-- should not be a handle ?
What is your observation ? (= could you confirm you are right ?)

Regards
User avatar
Michael Vogel
Addict
Addict
Posts: 2866
Joined: Thu Feb 09, 2006 11:27 pm
Contact:

Re: How can I place 32x32 icons in one column?

Post by Michael Vogel »

Don't think it works with 'standard' flags - so custom drawing has do be done (once again)... :cry:

Code: Select all

#LST_Ownerdraw = 1

Structure LBITEMEX
	Icon.i
	Title.i
	Text.i
EndStructure

Procedure WindowCallback(hWnd,uMsg,wParam,lParam)
	
	Select uMsg
	Case #WM_DRAWITEM
		Protected *lpdis.DRAWITEMSTRUCT = lParam
		Protected *lbex.LBITEMEX = GetGadgetItemData(#LST_Ownerdraw,*lpdis\itemID)
		Protected hbrFace, hdcMem, lplf.LOGFONT, hfntPrevious, hfntTitle

		; Draw item rectangle (normal/highlighted)
		If *lpdis\itemState & #ODS_SELECTED
			hbrFace = CreateSolidBrush_(GetSysColor_(#COLOR_HIGHLIGHT))
			FillRect_(*lpdis\hdc,*lpdis\rcItem,hbrFace)
			DrawFocusRect_(*lpdis\hdc,*lpdis\rcItem)
			SetTextColor_(*lpdis\hdc,GetSysColor_(#COLOR_HIGHLIGHTTEXT))
		Else
			hbrFace = CreateSolidBrush_(GetSysColor_(#COLOR_WINDOW))
			FillRect_(*lpdis\hdc,*lpdis\rcItem,hbrFace)
			SetTextColor_(*lpdis\hdc,GetSysColor_(#COLOR_WINDOWTEXT))
		EndIf

		DeleteObject_(hbrFace)

		; Draw the icon
		DrawIcon_(*lpdis\hdc,8,*lpdis\rcItem\top + 8,*lbex\Icon)

		; Create large font
		GetObject_(SendMessage_(*lpdis\hWndItem,#WM_GETFONT,0,0),SizeOf(LOGFONT),lplf)
		lplf\lfHeight = -MulDiv_(12,GetDeviceCaps_(*lpdis\hdc,#LOGPIXELSY),72)
		hfntTitle = CreateFontIndirect_(lplf)

		; Draw the title / text
		SetBkMode_(*lpdis\hdc,#TRANSPARENT)
		hfntPrevious = SelectObject_(*lpdis\hdc,hfntTitle)
		TextOut_(*lpdis\hdc,60,*lpdis\rcItem\top + 2,*lbex\title,lstrlen_(*lbex\title))
		SelectObject_(*lpdis\hdc,hfntPrevious)
		TextOut_(*lpdis\hdc,60,*lpdis\rcItem\top + 28,*lbex\text,lstrlen_(*lbex\text))
		DeleteObject_(hfntTitle)

		ProcedureReturn #True
	EndSelect

	ProcedureReturn #PB_ProcessPureBasicEvents
EndProcedure
Procedure AddLBItemEx(Gadget,Position,Icon,Title$,Text$)

	Protected *lbex.LBITEMEX = AllocateMemory(SizeOf(LBITEMEX)), Index
	*lbex\Icon = Icon
	CompilerIf #PB_Compiler_Unicode
		*lbex\Title = AllocateMemory(Len(Title$) * 2 + 2)
		*lbex\Text = AllocateMemory(Len(Text$) * 2 + 2)
	CompilerElse
		*lbex\Title = AllocateMemory(Len(Title$) + 1)
		*lbex\Text = AllocateMemory(Len(Text$) + 1)
	CompilerEndIf
	PokeS(*lbex\Title,Title$)
	PokeS(*lbex\Text,Text$)
	Index = SendMessage_(GadgetID(Gadget),#LB_ADDSTRING,0,"")
	SetGadgetItemData(Gadget,Index,*lbex)

EndProcedure

OpenWindow(0,0,0,360,300,"°v°",#PB_Window_SystemMenu | #PB_Window_ScreenCentered)
ListViewGadget(#LST_Ownerdraw,0,0,360,300,#LBS_OWNERDRAWFIXED)

SendMessage_(GadgetID(#LST_Ownerdraw),#LB_SETITEMHEIGHT,0,60)

SetWindowCallback(@WindowCallback())

;LoadImage(0,"..\Data\1.ico")
CreateImage(0,32,32,32,#Red)

NewIcon.ICONINFO
NewIcon\fIcon = #True
NewIcon\hbmMask = ImageID(0)
NewIcon\hbmColor = ImageID(0)

Icon=CreateIconIndirect_(@NewIcon)

AddLBItemEx(#LST_Ownerdraw,-1,icon,"Item Caption #1","This is the subtext for the item")
AddLBItemEx(#LST_Ownerdraw,-1,icon,"Item Caption #2","This is the subtext for the item")
AddLBItemEx(#LST_Ownerdraw,-1,icon,"Item Caption #3","This is the subtext for the item")

SetActiveGadget(#LST_Ownerdraw)
SetGadgetState(#LST_Ownerdraw,0)

Repeat : Until WaitWindowEvent()=#PB_Event_CloseWindow
RASHAD
PureBasic Expert
PureBasic Expert
Posts: 5043
Joined: Sun Apr 12, 2009 6:27 am

Re: How can I place 32x32 icons in one column?

Post by RASHAD »

In case of ListIcon with List Display Mode and any size of icons

Code: Select all

OpenWindow(0,0,0,320,240,"64x64 Icons",#PB_Window_SystemMenu | #PB_Window_ScreenCentered)
ListIconGadget(0,0,0,400,600,"",250,#PB_ListIcon_NoHeaders)

For i=1 To 4
  AddGadgetItem(0,-1,"  ListIcon Item #" + Str(i))
Next

hList = ImageList_Create_(64,64,#ILC_COLOR32| #ILC_MASK, 0, 100)

ImageList_AddIcon_(hList,LoadIcon_(0,#IDI_ERROR))
ImageList_AddIcon_(hList,LoadIcon_(0,#IDI_EXCLAMATION))
ImageList_AddIcon_(hList,LoadIcon_(0,#IDI_QUESTION))
ImageList_AddIcon_(hList,LoadIcon_(0,#IDI_INFORMATION))

SendMessage_(GadgetID(0), #LVM_SETIMAGELIST, #LVSIL_SMALL, hList)

lvi.LV_ITEM
lvi\mask = #LVIF_IMAGE
For i = 0 To 3
  lvi\iItem = i : lvi\iImage = i
  SendMessage_(GadgetID(0),#LVM_SETITEM,0,lvi)
Next

Repeat
  Select WaitWindowEvent(1)
    Case #PB_Event_CloseWindow
      Quit = 1
  EndSelect
Until Quit = 1
Egypt my love
Post Reply