hi guys
i search an example or an algo for a color listview
with a selected Line in an another color than blue
can your helpme please
greets
ragdog
One crude method is to use GetSysColor and SetSysColors to change the color assigned to COLOR_HIGHLIGHT, and then use SetSysColors to restore the original. There is an example here (http://msdn.microsoft.com/archive/default.asp?url=/archive/en-us/samples/internet/shellcc/customdraw_listview/default.asp) that looks like it highlights a listview item by intercepting the NM_CUSTOMDRAW notification (http://msdn2.microsoft.com/en-us/library/ms670610.aspx).
hi
thanks for you reply!
i mean if I a line select it is blue and would like these into a another color in red,transparent etc...
thanks
ragdog
ownerdraw is probably the best way
setsyscolor is global, so i'd advise against using it
"The SetSysColors function sends a WM_SYSCOLORCHANGE message to all windows to inform them of the change in color. It also directs Windows to repaint the affected portions of all currently visible windows. "
bad bad bad bad idea
SetSysColor is a crude method that is easy to implement. I would rate it a bad^1 idea. A bad^4 idea is like one that formats your hard drive :toothy
nah, anything that has to change colors globally and without the users conscent implies bad coding / hacked up code
which isnt good for reputation at all...
try looking at the LVM_ messages... theres ones to set the back color and text color, but not for single items
unless you go the ownerdrawn route, which really isnt that hard to impliment...
.elseif uMsg == WM_NOTIFY
mov edi,lParam
assume edi:ptr NMLVCUSTOMDRAW
mov eax,[edi].nmcd.hdr.code
.if eax== NM_CUSTOMDRAW
mov eax,[edi].nmcd.dwDrawStage
.if eax==CDDS_PREPAINT
mov eax,CDRF_NOTIFYITEMDRAW
ret
.elseif eax==CDDS_ITEMPREPAINT
mov eax,[edi].nmcd.dwItemSpec
and eax,1
dec eax
and eax,(0C9C9C9h-0E2E2E2h)
add eax,0E2E2E2h
mov dwOldColor,eax
mov [edi].clrTextBk,eax
mov [edi].clrText,0FF0000h
mov eax,CDRF_NOTIFYSUBITEMDRAW
ret
.elseif eax==CDDS_SUBITEM or CDDS_ITEMPREPAINT
;.if [edi].iSubItem==2 ;col
;.if [edi].nmcd.dwItemSpec==8 && [edi].iSubItem==1 ;{8,1}
.if [edi].nmcd.dwItemSpec==8 || [edi].nmcd.dwItemSpec==3
mov [edi].clrTextBk,08fffffh
mov [edi].clrText,0FF0000h
.else
push dwOldColor
pop [edi].clrTextBk
mov [edi].clrText,0FF0000h
.endif
.endif
mov eax,CDRF_NEWFONT
ret
.endif
.endif
ASSUME edi:nothing
hi
thanks for your help
@six_L
i have added your code to my project and have tested
this works not by me i have no color and i select a line there I have also no color :'(
my source is posted
thanks in forward and for your replys guys :U
greets
ragdog
[attachment deleted by admin]
.586
.model flat, stdcall ;32 bit memory model
option casemap :none ;case sensitive
include \masm32\include\windows.inc
include \masm32\include\user32.inc
include \masm32\include\kernel32.inc
include \masm32\include\shell32.inc
include \masm32\include\comdlg32.inc
include \masm32\include\gdi32.inc
include \masm32\include\advapi32.inc
include \masm32\include\comctl32.inc
include \masm32\include\masm32.inc
includelib \masm32\lib\user32.lib
includelib \masm32\lib\kernel32.lib
includelib \masm32\lib\shell32.lib
includelib \masm32\lib\comdlg32.lib
includelib \masm32\lib\gdi32.lib
includelib \masm32\lib\advapi32.lib
includelib \masm32\lib\comctl32.lib
includelib \masm32\lib\masm32.lib
DlgProc PROTO :HWND,:UINT,:WPARAM,:LPARAM
InsertColumns PROTO
AddLine PROTO :DWORD,:DWORD,:DWORD
include \masm32\macros\macros.asm
S macro pdata:VARARG
LOCAL Buff
.data
ifidni <pdata>,<>
Buff db 0
else
Buff db pdata,0
endif
.code
exitm <OFFSET Buff>
endm
.const
IDD_DIALOG equ 1000
IDB_EXIT equ 1001
IDB_INSERT equ 1003
IDC_LIST equ 1004
.data
ListCap1 db "Cap1",0
ListCap2 db "Cap2",0
ListCap3 db "Cap3",0
templateDH db "%d",0
templateByte db "%s",0
brw dd 0
sz1 db "text1",0
sz2 db "text2",0
sz3 db "text3",0
buffer1 db 512 dup (0)
.data?
hInstance dd ?
hList dd ?
lvi LV_ITEM <>
Buffer db MAX_PATH dup(?)
dwOldColor dd ?
.code
;>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
cButton proc hParent:DWORD,lpText:DWORD,x:DWORD,y:DWORD,w:DWORD,h:DWORD,ID:DWORD
LOCAL hFont :DWORD
invoke CreateFont,12,0,0,0,FW_NORMAL,FALSE,FALSE,FALSE, \
ANSI_CHARSET,OUT_DEFAULT_PRECIS,CLIP_DEFAULT_PRECIS, \
DEFAULT_QUALITY,DEFAULT_PITCH, S("MS Sans Serif")
mov hFont, eax
invoke CreateWindowEx,0,S('BUTTON'),lpText,WS_CHILD or WS_VISIBLE ,
x,y,w,h,hParent,ID,
hInstance,NULL
push eax
invoke SendMessage,eax,WM_SETFONT,hFont, 0
pop eax
ret
cButton endp
;>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
cListView proc hParent:DWORD, x:DWORD,y:DWORD,w:DWORD,h:DWORD,ID:DWORD
LOCAL hFont :DWORD
invoke CreateFont,12,0,0,0,FW_NORMAL,FALSE,FALSE,FALSE, \
ANSI_CHARSET,OUT_DEFAULT_PRECIS,CLIP_DEFAULT_PRECIS, \
DEFAULT_QUALITY,DEFAULT_PITCH, S("MS Sans Serif")
mov hFont, eax
invoke CreateWindowEx, WS_EX_STATICEDGE + WS_EX_TRANSPARENT,\
S("SysListView32"),S("test"),WS_TABSTOP + WS_VSCROLL + CBS_SIMPLE+WS_VISIBLE+WS_CHILD,x,y,w,h,\
hParent,ID,hInstance,NULL
push eax
invoke SendMessage,eax,WM_SETFONT,hFont, 0
pop eax
ret
cListView endp
;>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
DlgProc proc hWnd:HWND,uMsg:UINT,wParam:WPARAM,lParam:LPARAM
.if uMsg == WM_CREATE
invoke cButton,hWnd,S('INSERT'),71,256,56,16,IDB_INSERT
invoke cButton,hWnd,S('EXIT'),7,256,56,16,IDB_EXIT
invoke cListView,hWnd,7,16,398,229,IDC_LIST
mov hList,eax
invoke SendMessage,hList,LVM_SETEXTENDEDLISTVIEWSTYLE,LVS_EX_FULLROWSELECT or LVS_EX_HEADERDRAGDROP,-1
invoke InsertColumns
invoke AddLine,addr sz1,addr sz2,addr sz3
invoke AddLine,addr sz1,addr sz2,addr sz3
invoke AddLine,addr sz1,addr sz2,addr sz3
invoke AddLine,addr sz1,addr sz2,addr sz3
.elseif uMsg == WM_COMMAND
.if wParam == IDB_EXIT
invoke DestroyWindow, hWnd
.elseif wParam==IDB_INSERT
invoke AddLine,addr sz1,addr sz2,addr sz3
.endif
.elseif uMsg == WM_NOTIFY
mov edi,lParam
assume edi:ptr NMLVCUSTOMDRAW
mov eax,[edi].nmcd.hdr.code
.if eax== NM_CUSTOMDRAW
mov eax,[edi].nmcd.dwDrawStage
.if eax==CDDS_PREPAINT
mov eax,CDRF_NOTIFYITEMDRAW
ret
.elseif eax==CDDS_ITEMPREPAINT
mov eax,[edi].nmcd.dwItemSpec
and eax,1
dec eax
and eax,(0C9C9C9h-0E2E2E2h)
add eax,0E2E2E2h
mov dwOldColor,eax
mov [edi].clrTextBk,eax
mov [edi].clrText,0FF0000h
mov eax,CDRF_NOTIFYSUBITEMDRAW
ret
.elseif eax==CDDS_SUBITEM or CDDS_ITEMPREPAINT
;.if [edi].iSubItem==2 ;col
;.if [edi].nmcd.dwItemSpec==8 && [edi].iSubItem==1 ;{8,1}
.if [edi].nmcd.dwItemSpec==8 || [edi].nmcd.dwItemSpec==1
mov [edi].clrTextBk,08fffffh
mov [edi].clrText,0FF0000h
.else
push dwOldColor
pop [edi].clrTextBk
mov [edi].clrText,0FF0000h
.endif
.endif
mov eax,CDRF_NEWFONT
ret
.endif
ASSUME edi:nothing
.elseif uMsg == WM_CLOSE
invoke DestroyWindow, hWnd
.elseif uMsg == WM_DESTROY
invoke PostQuitMessage, NULL
.else
invoke DefWindowProc, hWnd, uMsg, wParam, lParam
ret
.endif
ret0:
xor eax, eax
ret
DlgProc endp
;>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
InsertColumns proc
LOCAL lvc:LV_COLUMN
invoke SendMessage,hList,LVM_SETEXTENDEDLISTVIEWSTYLE,LVS_EX_FULLROWSELECT or LVS_EX_FLATSB ,-1
mov lvc.imask,LVCF_TEXT+LVCF_WIDTH
mov lvc.pszText,offset ListCap1
mov lvc.lx,100
invoke SendMessage,hList, LVM_INSERTCOLUMN,0,addr lvc
or lvc.imask,LVCF_FMT
mov lvc.fmt,LVCFMT_LEFT ;CENTER
mov lvc.pszText,offset ListCap2
mov lvc.lx,130
invoke SendMessage,hList, LVM_INSERTCOLUMN, 1 ,addr lvc
mov lvc.pszText,offset ListCap3
mov lvc.lx,120
invoke SendMessage,hList, LVM_INSERTCOLUMN, 2 ,addr lvc
ret
InsertColumns endp
;>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
AddLine PROC Location:DWORD,Byte1:DWORD,Byte2:DWORD
invoke lstrcpy,addr Buffer,Location
mov lvi.imask,LVIF_TEXT
mov lvi.pszText,offset Buffer
mov lvi.iSubItem,0
invoke SendMessage,hList,LVM_INSERTITEM,0,addr lvi
mov lvi.iItem,eax
inc lvi.iSubItem
invoke lstrcpy,addr Buffer,Byte1
invoke SendMessage,hList,LVM_SETITEM,0,addr lvi
inc lvi.iSubItem
invoke lstrcpy,addr Buffer,Byte2
invoke SendMessage,hList,LVM_SETITEM,0,addr lvi
ret
AddLine 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
;>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
WinMain proc hInst:DWORD, hPrevInst, CmdLine, CmdShow
LOCAL wc:WNDCLASSEX
LOCAL msg:MSG
LOCAL Wwd:DWORD
LOCAL Wht:DWORD
LOCAL Wtx:DWORD
LOCAL Wty:DWORD
LOCAL hWnd:HANDLE
mov wc.cbSize, sizeof WNDCLASSEX
mov wc.style, CS_BYTEALIGNCLIENT or CS_BYTEALIGNWINDOW
mov wc.lpfnWndProc, offset DlgProc
mov wc.cbClsExtra, NULL
mov wc.cbWndExtra, NULL
m2m wc.hInstance,hInst
mov wc.hbrBackground, COLOR_BTNFACE+1
mov wc.lpszClassName, S("EnumWindow")
invoke LoadIcon, NULL, IDI_APPLICATION
mov wc.hIcon, eax
mov wc.hIconSm, eax
invoke LoadCursor, NULL, IDC_ARROW
mov wc.hCursor, eax
invoke RegisterClassEx, addr wc
mov Wwd, 425
mov Wht, 305
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, S("EnumWindow"),\
S("test_list"), WS_OVERLAPPEDWINDOW,\
Wtx,Wty,Wwd,Wht,NULL, NULL, hInst, NULL
mov hWnd, eax
invoke ShowWindow, hWnd, SW_SHOWNORMAL
invoke UpdateWindow, hWnd
.while TRUE
invoke GetMessage, addr msg, NULL, 0, 0
.break .if (!eax)
invoke TranslateMessage, addr msg
invoke DispatchMessage, addr msg
.endw
mov eax, msg.wParam
ret
WinMain endp
;>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
start:
invoke GetModuleHandle,NULL
mov hInstance,eax
invoke InitCommonControls
invoke GetCommandLine
invoke WinMain, hInstance ,NULL, eax, SW_SHOWDEFAULT
invoke ExitProcess,0
;>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
end start
attachment is exe.
[attachment deleted by admin]
thanks for your help :U
but there was a mistake
i wantend to have an other colour when i choose a line with mouse courser than blue, like red or any other color
i mean as example downthemeall (firefox) color
greets
ragdog
hi,ragdog
i can't understand your meaning truly. please give me a listview bitmap what you want.
hi
screenshot is added
ragdog
[attachment deleted by admin]
hi,ragdog
to use the method for setting row's color on listview maybe can't finish,this only adapt to some static rows color.(i'm trying...)
the Ralist demos on the forum to show how setting some dynamic rows color on listview. search it...
it looks to be complicated.
hi,ragdog
the attachement is worked code.
double Left click for setting color.
double Right click for Cancel color.
[attachment deleted by admin]
thanks for your work and help!
can change the color if I also a select a line with a one mouse click is original blue can change this color?
a screenshot is added
greets
ragdog
[attachment deleted by admin]
hi,ragdog
here is a code written by donkey. its Parameters is GoAsm, translated into Masm.
[attachment deleted by admin]
hi six_L
exactly that is it :U
thanks for you help and patience
greets
ragdog