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:
WM_CTLCOLORBTN
WM_CTLCOLORDIALOG
WM_CTLCOLOREDIT
WM_CTLCOLORSTATIC
WM_CTLCOLORLISTBOX
WM_CTLCOLRMSGBOX
WM_CTLCOLORSCROLLBAR
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
ret
.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,
mdevries.
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:
WM_CTLCOLORBTN
WM_CTLCOLORDIALOG
WM_CTLCOLOREDIT
WM_CTLCOLORSTATIC
WM_CTLCOLORLISTBOX
WM_CTLCOLRMSGBOX
WM_CTLCOLORSCROLLBAR
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
ret
.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,
mdevries.
you need to set BS_OWNERDRAW to button style
DlgProc:
WM_DRAWITEM handler
DlgProc:
.elseif eax==WM_DRAWITEM
invoke OnDrawItem,wParam,lParam
WM_DRAWITEM handler
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
.else
invoke DrawEdge,.hdc,addr .rcItem,EDGE_RAISED,BF_RECT? ?
.endif
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
.endif
.endif
assume ebx:nothing
ret
OnDrawItem endp
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,
mdevries.
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,
mdevries.