Hi all,

You are the specialists. Can you help me: How can I change the colors of a BUTTON on a dialog?
Suppose I want a black button, with white text painted on it. How do I do that.

My WIN32.HLP describes the following messages the parent receives when a control (or a
dialog) is about to be colored:


When I trie coloring an EDIT-box or a STATIC using this message, it works fine.
But when I trie coloring a BUTTON this way it doesn't work at all!
I thought: Maybe I don't receive the WM_CTLCOLORBTN message, so I decided to make this
message visible on the statusbar. The result was: I indeed received the WM_CTLCOLORBTN
message, but something prohibits the BUTTON to be colored the way I want. What am I doing wrong?

This is the way I handle the message:

.elsif uMsg == WM_CTLCOLORBTN
    SBtext 5,"COLORBTN" ;Display the text "COLORBTN" on the Statusbar,
;so I can see that the message was received.
    Invoke SetTextColor,hWnd,wParam,White
    Invoke SetBkColor,hWnd,wParam,Black
    Invoke GetStockObject,BLACK_BRUSH
.elseif uMsg == WM_PAINT

Does someone of you have advice, or a simple working example of a colored button.

I appreciate your help very much.
Thanks in advance.

Friendly regards,
Posted on 2005-03-19 12:58:35 by mdevries
you need to set BS_OWNERDRAW to button style
	.elseif eax==WM_DRAWITEM
invoke OnDrawItem,wParam,lParam


OnDrawItem proc uses ebx idCtl:DWORD,pdis:DWORD
LOCAL tbuff[20h]:byte
mov ebx,pdis
assume ebx:ptr DRAWITEMSTRUCT
.if .CtlType == ODT_BUTTON
invoke SetBkMode,.hdc,TRANSPARENT
Invoke SetBkColor,.hdc,Black
Invoke GetStockObject,BLACK_BRUSH
invoke FillRect,.hdc,addr .rcItem,eax
invoke SetTextColor,.hdc,White
.if (.itemState & ODS_SELECTED)
invoke DrawEdge,.hdc,addr .rcItem,BDR_SUNKEN,BF_RECT
invoke OffsetRect,addr .rcItem,1,1
invoke DrawEdge,.hdc,addr .rcItem,EDGE_RAISED,BF_RECT? ?
invoke GetWindowText,.hwndItem,addr tbuff,sizeof tbuff
lea edx,.rcItem
lea ecx,tbuff
invoke DrawText,.hdc,ecx,eax,edx,DT_CENTER or DT_VCENTER or DT_SINGLELINE or DT_NOCLIP
.if .itemState & ODS_FOCUS
invoke InflateRect,addr .rcItem,-4,-4
invoke DrawFocusRect,.hdc,addr .rcItem
assume ebx:nothing
OnDrawItem endp
Posted on 2005-03-19 17:53:52 by drizz
Hi drizz,

Thanks for your explanation, and example.
My buttons didn't have the OWNERDRAW button style, because I thought a normat button would do. But now I understand it doesn't.

Friendly regards,
Posted on 2005-03-19 23:40:39 by mdevries