此控件比较复杂;和基础win32控件不同;需要先初始化Windows公共控件库,
invoke InitCommonControls
之后才可使用;
lvdemo.asm,
.386.model flat, stdcalloption casemap :none ; case sensitiveinclude windows.inc
include user32.inc
includelib user32.lib
include kernel32.inc
includelib kernel32.lib
include comctl32.inc
includelib comctl32.lib
include odbc32.inc
includelib odbc32.libICO_MAIN equ 1000
DLG_MAIN equ 2000
IDC_ADD equ 2002
IDC_DEL equ 2003
IDC_CLEAR equ 2005
IDC_LIST equ 2006.data
szShi db '小石子',0
szLi db '小李子',0.data?
hInstance dd ?
hWinMain dd ? ;对话框句柄
hListView dd ? ;列表框句柄.const
szStr1 db "信息1",0
szStr2 db '信息2',0.code
include _ListView.asm_ProcDlgMain proc uses ebx edi esi hWnd,wMsg,wParam,lParamlocal @stWsa:WSADATAmov eax,wMsg.if eax == WM_COMMANDmov eax,wParam.if ax == IDC_ADDinvoke _ListViewAddColumn,hListView,0,50,addr szStr1invoke _ListViewAddColumn,hListView,1,50,addr szStr2invoke _ListViewSetItem,hListView,0,-1,0invoke _ListViewSetItem,hListView,0,0,addr szShiinvoke _ListViewSetItem,hListView,0,1,addr szLi.elseif ax == IDC_DEL.elseif ax == IDC_CLEARinvoke _ListViewClear,hListView.endif.elseif eax == WM_INITDIALOGpush hWndpop hWinMaininvoke LoadIcon,hInstance,ICO_MAINinvoke SendMessage,hWnd,WM_SETICON,ICON_BIG,eaxinvoke GetDlgItem,hWnd,IDC_LISTmov hListView,eaxinvoke SendMessage,hListView,LVM_SETEXTENDEDLISTVIEWSTYLE,\0,LVS_EX_GRIDLINES or LVS_EX_FULLROWSELECTinvoke ShowWindow,hListView,SW_SHOW.elseif eax == WM_CLOSEinvoke EndDialog,hWinMain,NULL.elsemov eax,FALSEret.endifmov eax,TRUEret_ProcDlgMain endpstart:invoke InitCommonControlsinvoke GetModuleHandle,NULLmov hInstance,eaxinvoke DialogBoxParam,eax,DLG_MAIN,NULL,offset _ProcDlgMain,0invoke ExitProcess,NULLend start
lvdemo.rc,
#include <resource.h>#define ICO_MAIN 1000
#define DLG_MAIN 2000#define IDC_ADD 2002
#define IDC_DEL 2003#define IDC_CLEAR 2005
#define IDC_LIST 2006ICO_MAIN icon "Main.ico"DLG_MAIN DIALOG 51, 78, 465, 237
STYLE DS_MODALFRAME | WS_POPUP | WS_VISIBLE | WS_CAPTION | WS_SYSMENU | WS_THICKFRAME
CAPTION "ListView示例"
FONT 9, "宋体"
{PUSHBUTTON "Add", IDC_ADD, 50, 20, 50, 14PUSHBUTTON "Delete", IDC_DEL, 200, 20, 50, 14, WS_TABSTOPDEFPUSHBUTTON "Clear", IDC_CLEAR, 350, 20, 50, 14, BS_DEFPUSHBUTTON | WS_TABSTOPCONTROL "", IDC_LIST, "SysListView32", 13 | WS_CHILD | WS_VISIBLE | WS_BORDER | WS_TABSTOP, 2, 56, 460, 179}
include _ListView.asm
_ListView.asm 这是书上的;
运行;一开始ListView出来是行和列都没有;
invoke _ListViewAddColumn,hListView,0,50,addr szStr1
增加一个列,列号0,宽度50, 列标题是szStr1;
invoke _ListViewSetItem,hListView,0,-1,0
插入一个空行,先要插入空行,后面才能插入数据;
invoke _ListViewSetItem,hListView,0,0,addr szShi
设置0行0列的数据为szShi;
点Clear清空全部的行和列;