此控件比较复杂;和基础win32控件不同;需要先初始化Windows公共控件库,

    invoke    InitCommonControls

之后才可使用;

lvdemo.asm,

		.386
		.model flat, stdcall
		option casemap :none   ; case sensitive

include		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.lib

ICO_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,lParam
		local	@stWsa:WSADATA

		mov	eax,wMsg
		.if	eax ==	WM_COMMAND
			mov	eax,wParam

			.if	ax ==	IDC_ADD
				invoke	_ListViewAddColumn,hListView,0,50,addr szStr1
				invoke	_ListViewAddColumn,hListView,1,50,addr szStr2
				invoke	_ListViewSetItem,hListView,0,-1,0
				invoke	_ListViewSetItem,hListView,0,0,addr szShi
				invoke	_ListViewSetItem,hListView,0,1,addr szLi

			.elseif	ax ==	IDC_DEL

			.elseif	ax ==	IDC_CLEAR
				invoke	_ListViewClear,hListView
			.endif

		.elseif	eax ==	WM_INITDIALOG
			push	hWnd
			pop	hWinMain
			invoke	LoadIcon,hInstance,ICO_MAIN
			invoke	SendMessage,hWnd,WM_SETICON,ICON_BIG,eax

			invoke	GetDlgItem,hWnd,IDC_LIST
			mov	hListView,eax
		        invoke	SendMessage,hListView,LVM_SETEXTENDEDLISTVIEWSTYLE,\
				0,LVS_EX_GRIDLINES or LVS_EX_FULLROWSELECT
			invoke	ShowWindow,hListView,SW_SHOW


		.elseif	eax ==	WM_CLOSE
				invoke	EndDialog,hWinMain,NULL

		.else
			mov	eax,FALSE
			ret
		.endif
		mov	eax,TRUE
		ret

_ProcDlgMain	endp

start:
		invoke	InitCommonControls
		invoke	GetModuleHandle,NULL
		mov	hInstance,eax
		invoke	DialogBoxParam,eax,DLG_MAIN,NULL,offset _ProcDlgMain,0
		invoke	ExitProcess,NULL

		end	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		2006

ICO_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, 14
 PUSHBUTTON "Delete", IDC_DEL, 200, 20, 50, 14, WS_TABSTOP

 DEFPUSHBUTTON "Clear", IDC_CLEAR, 350, 20, 50, 14, BS_DEFPUSHBUTTON | WS_TABSTOP

 CONTROL "", IDC_LIST, "SysListView32", 13 | WS_CHILD | WS_VISIBLE | WS_BORDER | WS_TABSTOP, 2, 56, 460, 179

}

include        _ListView.asm

 _ListView.asm 这是书上的;

运行;一开始ListView出来是行和列都没有;

Win32汇编ListView控件学习-LMLPHP

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;

Win32汇编ListView控件学习-LMLPHP 

点Clear清空全部的行和列; 

 

03-01 02:10