my goal is to change the the background color of only one listview subitems. i also still need to be able to see the text in the listview too. here is what i got but i dont know what to do next or what im doing wrong.

.586

.model flat, stdcall
option casemap :none

include \masm32\include\windows.inc
include \masm32\include\kernel32.inc
include \masm32\include\user32.inc
include \masm32\include\comctl32.inc
include \masm32\include\gdi32.inc

includelib \masm32\lib\kernel32.lib
includelib \masm32\lib\user32.lib
includelib \masm32\lib\comctl32.lib
includelib \masm32\lib\gdi32.lib


WinMain PROTO :DWORD,:DWORD,:DWORD,:DWORD
WndProc PROTO :DWORD,:DWORD,:DWORD,:DWORD
TopXY PROTO :DWORD,:DWORD

InsertColumn MACRO handle,txt,width
LOCAL lbl
LOCAL strng
jmp lbl
strng db txt,0
lbl:
mov col.imask,LVCF_TEXT or LVCF_WIDTH
mov col.fmt,0
mov col.lx,width
mov col.pszText,offset strng
invoke lstrlen,offset strng
mov col.cchTextMax,eax
invoke SendMessage,handle,LVM_INSERTCOLUMN,0,addr col
ENDM

.data
ClassName db "Starting Template",0
CaptionText db "Adding an item and subitems to a listview",0
LvClassName db "SysListView32",0
text1 db "item 1",0
text2 db "subitem 1",0
text3 db "subitem 2",0
text4 db "subtiem 3",0

.const
LVM_GETSUBITEMRECT equ LVM_FIRST + 56

.data?
hWnd HANDLE ?
hInstance HANDLE ?
hListView HANDLE ?
col LVCOLUMN <>
item LVITEM <>
hdc HDC ?
ps PAINTSTRUCT <>
rect RECT <>

.code
start:
invoke GetModuleHandle, NULL
mov hInstance, eax
invoke WinMain,hInstance,NULL,NULL,SW_SHOWDEFAULT
invoke ExitProcess,eax
invoke InitCommonControls

; ########################################################################

WinMain proc hInst :DWORD,
hPrevInst :DWORD,
CmdLine :DWORD,
CmdShow :DWORD

;====================
; Put LOCALs on stack
;====================

LOCAL wc :WNDCLASSEX
LOCAL msg :MSG
LOCAL Wwd :DWORD
LOCAL Wht :DWORD
LOCAL Wtx :DWORD
LOCAL Wty :DWORD

;==================================================
; Fill WNDCLASSEX structure with required variables
;==================================================

mov wc.cbSize, SIZEOF WNDCLASSEX
mov wc.style, CS_HREDRAW + CS_VREDRAW
mov wc.lpfnWndProc, OFFSET WndProc
mov wc.cbClsExtra, NULL
mov wc.cbWndExtra, NULL
mov eax, hInstance
mov wc.hInstance, eax
invoke LoadIcon, NULL,IDI_APPLICATION
mov wc.hIcon, eax
mov wc.hIconSm, eax
invoke LoadCursor, NULL,IDC_ARROW
mov wc.hCursor, eax
mov wc.hbrBackground,COLOR_BTNFACE+1
mov wc.lpszMenuName, NULL
mov wc.lpszClassName,OFFSET ClassName


invoke RegisterClassEx, addr wc

;================================
; Centre window at following size
;================================

mov Wwd, 500
mov Wht, 350

invoke GetSystemMetrics,SM_CXSCREEN
invoke TopXY,Wwd,eax
mov Wtx, eax

invoke GetSystemMetrics,SM_CYSCREEN
invoke TopXY,Wht,eax
mov Wty, eax

invoke CreateWindowEx,NULL,
ADDR ClassName,
ADDR CaptionText,
WS_OVERLAPPEDWINDOW,
Wtx,Wty,Wwd,Wht,
NULL,
NULL,
hInst,
NULL
mov hWnd,eax

invoke ShowWindow,hWnd,SW_SHOWNORMAL
invoke UpdateWindow,hWnd

;===================================
; Loop until PostQuitMessage is sent
;===================================

StartLoop:
invoke GetMessage,ADDR msg,NULL,0,0
cmp eax, 0
je ExitLoop
invoke TranslateMessage, ADDR msg
invoke DispatchMessage, ADDR msg
jmp StartLoop
ExitLoop:

mov eax,msg.wParam
ret

WinMain endp

; ########################################################################

WndProc proc hWin :HWND,
uMsg :UINT,
wParam :WPARAM,
lParam :LPARAM

.IF uMsg==WM_DESTROY
invoke PostQuitMessage,NULL

.ELSEIF uMsg==WM_CREATE

invoke CreateWindowEx,NULL,
ADDR LvClassName,
NULL,
WS_CHILD + WS_VISIBLE + LVS_REPORT,
0,0,491,250,
hWin,
NULL,
hInstance,
NULL
mov hListView,eax

invoke SendMessage,hListView,LVM_SETEXTENDEDLISTVIEWSTYLE,0,LVS_EX_GRIDLINES

InsertColumn hListView, "Column 4" ,122
InsertColumn hListView, "Column 3" ,122
InsertColumn hListView, "Column 2" ,122
InsertColumn hListView, "Column 1" ,122

mov item.imask,LVIF_TEXT
mov item.pszText,offset text1
mov item.cchTextMax,sizeof text1
invoke SendMessage,hListView,LVM_INSERTITEM,0,addr item

mov item.imask,LVIF_TEXT
mov item.iSubItem,1
mov item.pszText,offset text2
mov item.cchTextMax,sizeof text2
invoke SendMessage,hListView,LVM_SETITEM,0,addr item

mov item.imask,LVIF_TEXT
mov item.iSubItem,2
mov item.pszText,offset text3
mov item.cchTextMax,sizeof text3
invoke SendMessage,hListView,LVM_SETITEM,0,addr item

mov item.imask,LVIF_TEXT
mov item.iSubItem,3
mov item.pszText,offset text4
mov item.cchTextMax,sizeof text4
invoke SendMessage,hListView,LVM_SETITEM,0,addr item



.ELSEIF uMsg == WM_PAINT

;invoke BeginPaint,hWin,addr ps
invoke GetDC,hWin
mov hdc,eax
mov rect.left,LVIR_BOUNDS
mov rect.top,1
invoke SendMessage,hListView,LVM_GETSUBITEMRECT,0,addr rect
invoke CreateSolidBrush,220
invoke FillRect,hdc,addr rect,eax
invoke ReleaseDC,hWin,hdc
;invoke EndPaint,hdc,addr ps

.ELSE
invoke DefWindowProc,hWin,uMsg,wParam,lParam
ret

.ENDIF
xor eax,eax
ret

WndProc endp


; ########################################################################

TopXY proc wDim:DWORD, sDim:DWORD

shr sDim, 1
shr wDim, 1
mov eax, wDim
sub sDim, eax
mov eax,sDim
ret

TopXY endp

; #########################################################################

end start
Posted on 2002-01-22 17:22:29 by smurf
smurf,

Maybe, that's what you are looking for.


Guy
Posted on 2002-01-23 14:03:55 by Guy
wow nice work. thats exactly what i was looking for. :alright:
Posted on 2002-01-23 14:27:51 by smurf
after making some changes to the code you supplied i came apon a few lines i didnt understand what they are doing:
.elseif uMsg==WM_NOTIFY

mov edi,lParam ;move info into edi
assume edi:ptr NMHDR ;make edi point to the NMHDR structure
mov eax,[edi].hwndFrom ;move the identifier of the common control into eax
.if eax==hListView ;if its the listview continue
.if [edi].code == NM_CUSTOMDRAW ;check to see if the code is NM_CUSTOMDRAW
assume edi:ptr NMLVCUSTOMDRAW ;make edi point to the NMLVCUSTOMDRAW structure

.if [edi].iSubItem == 0 ;at item 0 set the colors below
RGB 95,158,160
mov [edi].clrTextBk,eax
RGB 255,255,255
mov [edi].clrText,eax

.elseif [edi].iSubItem == 2 ;at subitem 2 set the colors below
RGB 255,174,0
mov [edi].clrTextBk,eax
RGB 255,255,255
mov [edi].clrText,eax

.else ;set everything else to the colors below
RGB 255,255,255
mov [edi].clrTextBk,eax
RGB 0,0,0
mov [edi].clrText,eax
.endif
return 32 ;<--- what is this line doing exactly
.endif
.endif
return 0 ;<--- also this line
Posted on 2002-01-23 18:53:16 by smurf
return 32 is for CDRF_NOTIFYITEMDRAW OR CDRF_NOTIFYSUBITEMDRAW return value. If you look at the .inc file that I included, you'll see these names equ 20h. Custom Draw need a return 0 at the end or your program will crash. You might want to search for NMCUSTOMDRAW on Yahoo and click the first link to Micorsoft MSDN, at the botton of the NM there are two listviews examples.

Guy
Posted on 2002-01-23 19:23:54 by Guy