I want to subclass a generic LISTBOX to apply different colours to listbox contents.
The listbox doesn't respond to WM_CTLCOLORLISTBOX message. :(
I guess I have to use SetWindowLONG with GW_STYLE.

.code

PROGRAM_IMAGE_BASE EQU 400000h

start:

Main proc
LOCAL msg :MSG

invoke CreateWindowExW,WS_EX_TOOLWINDOW,
ADDR wsClassName, ADDR wsDisplayName,WS_OVERLAPPEDWINDOW or \
LBS_HASSTRINGS or LBS_WANTKEYBOARDINPUT or \
LBS_DISABLENOSCROLL,\
0,0,350,770,
0,0,PROGRAM_IMAGE_BASE,0


mov hWnd,eax
invoke SetWindowLong,eax,GWL_WNDPROC,ADDR WndProc
mov lpfnWndProc,eax
invoke SendMessage, hWnd,WM_SETREDRAW, 0, NULL
invoke CreateFontIndirectW, ADDR fnt
mov hFont, eax
invoke SendMessageW, hWnd, WM_SETFONT, eax, NULL
invoke OpenSCManager, NULL, NULL, SC_MANAGER_ENUMERATE_SERVICE
test eax, eax
jnz @f
invoke SendMessage, hWnd, LB_ADDSTRING, NULL, OFFSET scMngrErr1
@@:
mov g_hSCMngr, eax

mov enumResumeHndl, 0
invoke EnumServicesStatus, eax, SERVICE_WIN32, SERVICE_ACTIVE, 0, 0, \
OFFSET enumSRVneeded, OFFSET enumSRVret, OFFSET enumResumeHndl
mov ebx, enumSRVneeded
push ebx
push HEAP_ZERO_MEMORY
invoke GetProcessHeap
push eax
call HeapAlloc
mov g_hMem, eax

mov enumResumeHndl, 0
invoke EnumServicesStatus, g_hSCMngr, SERVICE_WIN32, SERVICE_ACTIVE, eax, ebx, \
OFFSET enumSRVneeded, OFFSET enumSRVret, OFFSET enumResumeHndl

test eax, eax
jnz @f
invoke SendMessage, hWnd, LB_ADDSTRING, 0, OFFSET enumSrvErr1
@@:

mov ebx, g_hMem
mov edi, enumSRVret
xor esi, esi

@@:
;mov edx, (ENUM_SERVICE_STATUS ptr ).lpServiceName
mov edx, (ENUM_SERVICE_STATUS ptr ).lpDisplayName
invoke lstrcpy, ADDR buffer, edx
invoke lnstr,ADDR buffer
cmp eax,dwMaxLen
jb ok ;if smaller
mov dwMaxLen,eax ;maximum length
ok:
inc dwCount
invoke SendMessage, hWnd, LB_ADDSTRING, 0, OFFSET buffer
invoke lstrcmp, OFFSET buffer, OFFSET serviceSS
test eax, eax
jnz __next
invoke OpenService, g_hSCMngr, OFFSET serviceSS, SERVICE_ALL_ACCESS
mov g_hOpenSrv, eax
invoke StartService, eax, 0, NULL
test eax, eax
jnz __clean
invoke GetLastError
cmp eax, ERROR_SERVICE_ALREADY_RUNNING
jne __clean
invoke ControlService, g_hOpenSrv, SERVICE_CONTROL_STOP, OFFSET srvStat
__clean:
invoke CloseServiceHandle, g_hOpenSrv
__next:
add ebx, SIZEOF ENUM_SERVICE_STATUS
inc esi
cmp esi, edi
jb @b

push g_hMem
push 0
invoke GetProcessHeap
push eax
call HeapFree
invoke CloseServiceHandle, g_hSCMngr
;invoke SendMessage, hWnd, LB_GETCOUNT, 0, 0
;invoke dwtoa,dwCount,ADDR buffer
;invoke GetErrDescription,eax

;invoke dwtoa,eax,ADDR buffer
;invoke SendMessage, hWnd, LB_ADDSTRING, 0, OFFSET buffer
mov eax,dwCount
lea ebx,[+140] ;listbox width
;invoke dwtoa,eax,ADDR buffer
;invoke SendMessage, hWnd, LB_ADDSTRING, 0, OFFSET buffer
mov eax, dwMaxLen
lea eax,[+67] ;listbox width
invoke SetWindowPos,hWnd,HWND_TOP,0,0,eax,ebx,SWP_SHOWWINDOW
invoke SendMessage, hWnd,WM_SETREDRAW, 1, NULL
invoke ShowWindow,hWnd,SW_SHOWNORMAL
invoke UpdateWindow,hWnd
StartLoop:
invoke GetMessageW,ADDR msg,NULL,NULL,NULL
cmp eax, NULL
je ExitLoop
invoke TranslateMessage, ADDR msg
invoke DispatchMessageW, ADDR msg
jmp StartLoop
ExitLoop:
mov eax, msg.wParam
invoke DeleteObject, hFont
ret
Main endp

WndProc proc hWin :DWORD,
uMsg :DWORD,
wParam :DWORD,
lParam :DWORD

.if uMsg == WM_MOUSEMOVE
invoke SendMessage, hWnd, LB_GETCURSEL,NULL,NULL
mov ebx,eax
invoke SendMessage, hWnd, LB_ITEMFROMPOINT, 0,lParam
LOWORD eax
cmp eax, ebx
je skip
invoke SendMessage, hWnd, LB_SETCURSEL,eax,NULL
skip:
.elseif uMsg == WM_DESTROY
invoke PostQuitMessage,NULL
xor eax,eax
.elseif uMsg ==WM_KEYDOWN
.elseif uMsg ==WM_SYSCOLORCHANGE
invoke GetErrDescription,eax


.endif
invoke CallWindowProcW,lpfnWndProc,hWin,uMsg,wParam,lParam
ret
WndProc endp

end start
Posted on 2003-07-06 16:28:01 by Prahogi
The WM_CTLCLRxxxx messages are sent to the parent of the control not the control itself. Put your color routine in the dilaogs procedure and try it.

i.e.
.ELSEIF uMsg == WM_CTLCOLORLISTBOX

mov eax,wParam
mov hDC,eax
invoke SetTextColor,hDC,0
invoke SetBkMode,hDC,TRANSPARENT
mov eax,hBrush
ret
Posted on 2003-07-06 17:59:09 by donkey
I realize that it was really a lame question.
I should have figured this while reading MSDN
Posted on 2003-07-09 15:17:31 by Prahogi

I realize that it was really a lame question.
I should have figured this while reading MSDN


dont worry donkey used to it becouse of my questions :tongue:
Posted on 2003-07-09 17:44:20 by AceEmbler