【HSP3.x 移植版】『HSPの裏技』リストビューでアイコンを使ってみる

『HSPの裏技』リストビューでアイコンを使ってみる(HSP2.x 版)をHSP3.x バージョンへ書き換えたものです。
http://chokuto.ifdef.jp/urawaza/lv_icon.html

※このサンプルで読み込まれるビットマップファイル iconlist.bmp は上記URLで公開されているものを使用することを仮定しています。

前のが間違ってたので書き直し

『HSPの裏技』リストビューでアイコンを使ってみる(HSP2.x 版)をHSP3.x バージョンへ書き換えたものです。
http://chokuto.ifdef.jp/urawaza/lv_icon.html

※このサンプルで読み込まれるビットマップファイル iconlist.bmp は上記URLで公開されているものを使用することを仮定しています。

前のが間違ってたので書き直し

  • タグ:
  • タグはありません
;HSP3.x
;HSP使
; http://chokuto.ifdef.jp/urawaza/lv_icon.html
; ※ iconlist.bmp URL使
;
; []Advanced HSP
; http://chokuto.ifdef.jp/advanced/bitmapobject.html
#module ;###### #########
#uselib "gdi32.dll"
#cfunc CreateCompatibleDC "CreateCompatibleDC" int
#cfunc CreateCompatibleBitmap "CreateCompatibleBitmap" int, int, int
#func SelectObject "SelectObject" int, int
#func BitBlt "BitBlt" int, int, int, int, int, int, int, int, int
#func DeleteDC "DeleteDC" int
#func DeleteObject "DeleteObject" int
#define SRCCOPY 0x00CC0020
; DIB
#defcfunc CreateDIB int px, int py, int sx, int sy
; DIB
hBitmap = CreateCompatibleBitmap(hdc, sx, sy)
;
hdcMemory = CreateCompatibleDC(hdc)
;
SelectObject hdcMemory, hBitmap
hOldBitmap = stat
; HSP
BitBlt hdcMemory, 0, 0, sx, sy, hdc, px, py, SRCCOPY
;
SelectObject hdcMemory, hOldBitmap
;
DeleteDC hdcMemory
; (DIB)
return hBitmap
; DIB
#deffunc DeleteDIB int hbmp
;
DeleteObject hbmp
return
#global ;############# ########################
#module ;########### ##############
#uselib "comctl32.dll"
#cfunc ImageList_Create "ImageList_Create" int,int,int,int,int
#func ImageList_Destroy "ImageList_Destroy" int
#func ImageList_AddMasked "ImageList_AddMasked" int,int,int
#func ImageList_Draw "ImageList_Draw" int,int,int,int,int,int
#define global ILC_COLOR 0x0000
#define global ILC_COLOR4 0x0004
#define global ILC_COLOR8 0x0018
#define global ILC_COLOR16 0x0010
#define global ILC_COLOR24 0x0018
#define global ILC_COLOR32 0x0020
#define global ILC_COLORDDB 0x00FE
#define global ILC_MASK 0x0001
#define ILD_TRANSPARENT 0x0001
;
#defcfunc CreateImageList int sx, int sy, int type, int num
return ImageList_Create(sx, sy, type, num, 0)
;
#deffunc DestroyImageList int handle
ImageList_Destroy handle
return
;
#deffunc AddImageListItem int handle, int cx, int cy, int sx, int sy, int maskColor
; DIB
hDIB = CreateDIB(cx, cy, sx, sy)
;
ImageList_AddMasked handle, hDIB, maskColor
firstItemIndex = stat
; DIB
DeleteDIB hDIB
return firstItemIndex
;
#deffunc DrawImageListItem int handle, int index, int cx, int cy
ImageList_Draw handle, index, hdc, cx, cy, ILD_TRANSPARENT
return
#global ;############# ########################
#module ;############ ###############
#uselib "comctl32.dll"
#func InitCommonControlsEx "InitCommonControlsEx" int
#uselib "user32.dll"
#func SetWindowLong "SetWindowLongA" int,int,int
#cfunc GetWindowLong "GetWindowLongA" int,int
;
#define ICC_LISTVIEW_CLASSES 4
#define WS_CHILD 0x40000000
#define WS_VISIBLE 0x10000000
#define global LVS_ICON 0x0000
#define global LVS_REPORT 0x0001
#define global LVS_SMALLICON 0x0002
#define global LVS_LIST 0x0003
#define LVS_TYPEMASK 0x0003
#define LVM_SETIMAGELIST 0x1003
#define LVM_SETITEM 0x1006
#define LVM_INSERTITEM 0x1007
#define LVM_DELETEITEM 0x1008
#define LVM_INSERTCOLUMN 0x101B
#define LVM_GETNEXTITEM 0x100C
#define LVM_GETITEMTEXT 0x102D
#define LVCF_FMT 0x0001
#define LVCF_WIDTH 0x0002
#define LVCF_TEXT 0x0004
#define LVCF_SUBITEM 0x0008
#define LVIF_TEXT 0x0001
#define LVIF_IMAGE 0x0002
#define LVNI_SELECTED 0x0002
#define LVSIL_NORMAL 0x0000
#define LVSIL_SMALL 0x0001
#define GWL_STYLE (-16)
; ( global )
#define global LVCFMT_LEFT 0x0000
#define global LVCFMT_RIGHT 0x0001
#define global LVCFMT_CENTER 0x0002
;
#deffunc CreateListView int sx, int sy, int type, int hLargeImgList, int hSmallImgList
;
initinfo = 8, ICC_LISTVIEW_CLASSES
InitCommonControlsEx varptr(initinfo)
;
styleFlags = WS_CHILD | WS_VISIBLE | type
winobj "SysListView32", "", 0, styleFlags, sx, sy
newObjID = stat
; ()
if hLargeImgList {
; LVM_SETIMAGELIST
sendmsg objinfo_hwnd(newObjID), LVM_SETIMAGELIST, LVSIL_NORMAL, hLargeImgList
logmes "LVM_SETIMAGELIST, LVSIL_NORMAL : " + stat
}
; ()
if hSmallImgList {
; LVM_SETIMAGELIST
sendmsg objinfo_hwnd(newObjID), LVM_SETIMAGELIST, LVSIL_SMALL, hSmallImgList
logmes "LVM_SETIMAGELIST, LVSIL_SMALL : " + stat
}
return newObjID
;
#deffunc InsertListViewColumn int objID, int index, str text, int align, int pixels
textbuf = text
; LVCOLUMN
dim lvcolumn, 8
lvcolumn(0) = LVCF_FMT | LVCF_WIDTH | LVCF_TEXT | LVCF_SUBITEM
lvcolumn(1) = align
lvcolumn(2) = pixels
lvcolumn(3) = varptr(textbuf)
; LVM_INSERTCOLUMN
sendmsg objinfo_hwnd(objID), LVM_INSERTCOLUMN, index, varptr(lvcolumn)
return
;
#deffunc InsertListViewItem int objID, int index, str text, int image
textbuf = text
; LVITEM
dim lvitem, 13
lvitem(0) = LVIF_TEXT | LVIF_IMAGE
lvitem(1) = index
lvitem(5) = varptr(textbuf)
lvitem(7) = image
; LVM_INSERTITEM
sendmsg objinfo_hwnd(objID), LVM_INSERTITEM, 0, varptr(lvitem)
return
;
#deffunc SetListViewItemText int objID, int index, int subitem, str text
textbuf = text
; LVITEM
dim lvitem, 13
lvitem(0) = LVIF_TEXT
lvitem(1) = index
lvitem(2) = subitem
lvitem(5) = varptr(textbuf)
; LVM_SETITEM
sendmsg objinfo_hwnd(objID), LVM_SETITEM, 0, varptr(lvitem)
return
;
#defcfunc GetListViewItemText int objID, int index, int subitem
; LVITEM
dim lvitem, 13
lvitem(2) = subitem
textbufsize = 256
;
repeat
sdim textbuf, textbufsize
lvitem(5) = varptr(textbuf)
lvitem(6) = textbufsize
; LVM_GETITEMTEXT
sendmsg objinfo_hwnd(objID), LVM_GETITEMTEXT, index, varptr(lvitem)
if stat < textbufsize - 1 : break
textbufsize *= 2
loop
return textbuf
;
#deffunc DeleteListViewItem int objID, int index
; LVM_DELETEITEM
sendmsg objinfo_hwnd(objID), LVM_DELETEITEM, index, 0
return
;
#defcfunc GetSelectedListViewItem int objID, int startIndex
; LVM_GETNEXTITEM
sendmsg objinfo_hwnd(objID), LVM_GETNEXTITEM, startIndex, LVNI_SELECTED
return stat
;
#deffunc SetListViewType int objID, int type
;
style = GetWindowLong(objinfo_hwnd(objID), GWL_STYLE)
;
style = (style & (-1 ^ LVS_TYPEMASK)) | type
;
SetWindowLong objinfo_hwnd(objID), GWL_STYLE, style
return
#global ;############# ########################
;
buffer 2,,, 0 ;
picload "iconlist.bmp"
; (32×32)
hLargeImgList = CreateImageList(32, 32, ILC_COLOR24 | ILC_MASK, 4)
AddImageListItem hLargeImgList, 0, 0, 32*4, 32, 0xF0CAA6
;
pos 0, 0
gzoom 16*4, 16, 2, 0, 0, 32*4, 32
; (16×16)
hSmallImgList = CreateImageList(16, 16, ILC_COLOR24 | ILC_MASK, 4)
AddImageListItem hSmallImgList, 0, 0, 16*4, 16, 0xF0CAA6
gsel 0
objsize ginfo_winx, 25
button gosub "", *OnChangeListTypeButtonClicked
;
pos 0, 25
CreateListView ginfo_winx, ginfo_winy, LVS_ICON, hLargeImgList, hSmallImgList
listviewID = stat
;
InsertListViewColumn listviewID, 0, "", LVCFMT_LEFT, 100
InsertListViewColumn listviewID, 1, "", LVCFMT_LEFT, 200
;
InsertListViewItem listviewID, 0, "", 0
SetListViewItemText listviewID, 0, 1, ""
InsertListViewItem listviewID, 1, "", 1
SetListViewItemText listviewID, 1, 1, ""
InsertListViewItem listviewID, 2, "", 2
SetListViewItemText listviewID, 2, 1, ""
InsertListViewItem listviewID, 3, "", 3
SetListViewItemText listviewID, 3, 1, ""
InsertListViewItem listviewID, 4, "", 0
SetListViewItemText listviewID, 4, 1, ""
InsertListViewItem listviewID, 5, "", 1
SetListViewItemText listviewID, 5, 1, ""
stop
*OnChangeListTypeButtonClicked
;
type = (type + 1) \ 4
SetListViewType listviewID, type
return
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX