Hi,
based on this link http://www.freevbcode.com/code/TreeViewGradient.zip
I'm trying to put a gradient background to the treeview control in \masm32\icztutes\tute19.

This is the wndproc of the subclassed treeview control.

.data
vert TRIVERTEX <0,0,0F000h,0f000h,0F000h,0>
TRIVERTEX <100,100,0,0,0f000h,0>
gRect GRADIENT_RECT <0,1>
bPainting dd FALSE

.data?
OldTreeViewProc dd ?

.code
NewTreeViewProc proc hWnd:dword, uMsg:dword, wParam:dword, lParam:dword
local TVDC :dword
local TempDC :dword
local oldBMP :dword
local TempBMP :dword
local ps :PAINTSTRUCT
local r: RECT

.if uMsg==WM_PAINT
.if bPainting==FALSE
mov bPainting, TRUE
invoke BeginPaint, hWnd, addr ps

invoke CreateCompatibleDC, ps.hdc
mov TempDC, eax

;create offscreen dc, bmp
invoke GetClientRect, hWnd, addr r
invoke CreateCompatibleBitmap, ps.hdc, r.right, r.bottom
mov TempBMP, eax
invoke SelectObject, TempDC, TempBMP
mov oldBMP, eax

;paint on memDC
invoke CallWindowProc, OldTreeViewProc, hWnd, WM_PAINT, TempDC, lParam

;Do gradient fill
mov eax, offset vert + sizeof(TRIVERTEX)
mov ecx,r.right
mov ,ecx
add eax, 4
mov ecx, r.bottom
mov ,ecx
invoke GradientFill, ps.hdc,addr vert,2,addr gRect,1,GRADIENT_FILL_RECT_V

;do transparent BitBlt
invoke GetSysColor, COLOR_WINDOW
invoke TransparentBlt, ps.hdc, 0, 0, r.right, r.bottom, TempDC, 0, 0, r.right, r.bottom, eax

;free handles
invoke SelectObject, TempDC, oldBMP
invoke DeleteObject, TempBMP
invoke DeleteDC, TempDC

invoke EndPaint, hWnd, addr ps
mov bPainting, FALSE
mov eax, 0
ret
.endif

.elseif uMsg==WM_ERASEBKGND
mov eax, 1
ret

.elseif (uMsg==WM_HSCROLL) || (uMsg==WM_VSCROLL) || (uMsg==WM_MOUSEWHEEL)
invoke InvalidateRect, hWnd, 0, FALSE
.else
.endif
invoke CallWindowProc, OldTreeViewProc, hWnd, uMsg, wParam, lParam
ret
NewTreeViewProc endp


For some reason that doesn't work.
Another problem I've noticed is that the WM_PAINT message is not always called when there is a change in the treeview control (i.e. expand or collapse items).

Any idea?

Thanks.
Posted on 2005-07-03 05:06:35 by Gismo