[modified source to avoid crash]
Hello,
Here's a icon viewer developped in Fbsl.
The source code will show you how to :
-use volatile CLASS
-use API calls
-use API structure manipulation
'======================================================
' Shell32 Icon Index FBSL
'======================================================
#Option Explicit
#DLLDECLARE user32("GetSystemMetrics","DestroyIcon")
#DLLDECLARE comctl32("ImageList_Create","ImageList_ReplaceIcon")
#DLLDECLARE shell32("ExtractIcon")
DIM $LV_ITEM, %hList, %t, %hIcon, %hImage, $index, %j
' ------------------------------------------------------
'// SysListView Class :: TYPE + MACRO
' ------------------------------------------------------
Class SLV '// volatile class (== without parens() )
Macro SetValue(param1, param2) = SetMem( LV_ITEM, param1, param2 )
Static mask = 0, iItem = 4, iSubItem = 8, state = 12
Static stateMask = 16, pszText = 20, cchTextMax = 24, iImage = 28
Static ILC_COLOR32 = 32, ILC_MASK = 1, LVSIL_SMALL = 1, LVSIL_STATE = 2
Static LVS_LIST = 0x0003, LVIF_TEXT = 1, LVIF_IMAGE = 2, LVS_REPORT = 0x0001
Static LVS_TYPEMASK = 3, LVS_EX_GRIDLINES = 1, LVS_EX_LABELTIP = 0x00004000
Static LVIS_STATEIMAGEMASK = 0xF000, SM_CXICON = 11, SM_CYICON = 12
End Class
' ------------------------------------------------------
' // Main Entry point
' ------------------------------------------------------
Sub Main()
MYCreateSysListView()
Begin Events
End Events
End Sub
' ------------------------------------------------------
'// ListView Creation
' ------------------------------------------------------
Sub MYCreateSysListView()
Fbsl_settext(me,"Shell32 Icon Index")
Alloc(LV_ITEM,36)
SLV->SetValue( SLV->LVIF_TEXT + SLV->LVIS_STATEIMAGEMASK + SLV->LVIF_IMAGE, SLV->mask )' set state masks
SLV->SetValue( 256, SLV->cchTextMax)
hList = Fbsl_control("SysListView32",me,"",0,0,0,500,294,_
WS_VISIBLE + WS_CHILD + SLV->LVS_LIST + SLV->LVS_TYPEMASK + SLV->LVS_REPORT, WS_EX_STATICEDGE)
SendMessage(hList, SLV->LVM_SETBKCOLOR, 0, rgb(255,255,192))
SendMessage(hList, SLV->LVM_SETTEXTBKCOLOR, 0, rgb(255,255,192))
SendMessage(hList, SLV->LVM_SETEXTENDEDLISTVIEWSTYLE,0, SLV->LVS_EX_LABELTIP)
'==========create an image list======================
hImage = ImageList_Create(GetSystemMetrics(SLV->SM_CXICON),_
GetSystemMetrics(SLV->SM_CYICON), SLV->ILC_COLOR32 + SLV->ILC_MASK, 1, 1)
'====Extract the icon then destroy the handle to replace with next icon
For t = 0 To 237
hIcon = ExtractIcon(0,"shell32.dll",t)
ImageList_ReplaceIcon(hImage,-1,hIcon)
DestroyIcon(hIcon)
If hIcon <> 0 Then j = t
Next
'=====set the image list to the listview=========
SendMessage(hList,SLV->LVM_SETIMAGELIST,SLV->LVSIL_SMALL,hImage)
'=====populate the listview======================
For t = 0 To j
index = "Icon # : " & t
SLV->SetValue( t, SLV->iItem) ' item index
SLV->SetValue( @index, SLV->pszText) ' pointer to text string
SLV->SetValue( t, SLV->iImage) ' image index
SendMessage(hList,SLV->LVM_INSERTITEM,0,LV_ITEM)
Next
Resize(me, 0, 0, 520, 324)
Center(me)
Show(me)
End Sub
Enjoy