- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Hi,
I am trying to get 'colored' buttons according to the
code below.
1) I create a 'main' window hWnd
2) I create a number of buttons ButtonWnd(i) to move
around hWnd to different locations depending on
some calculated results
my problem is that I would like to set different colors
to the buttons instead of the gray default one.
I have tried to respond to the WM_CTLCOLORBTN message
without success.
I do not have any text on the buttons, I just use them
as push-button-like check boxes.
How do I proceed to get colored buttons?
/bjorn
a stripped down code snippet follows:
I am trying to get 'colored' buttons according to the
code below.
1) I create a 'main' window hWnd
2) I create a number of buttons ButtonWnd(i) to move
around hWnd to different locations depending on
some calculated results
my problem is that I would like to set different colors
to the buttons instead of the gray default one.
I have tried to respond to the WM_CTLCOLORBTN message
without success.
I do not have any text on the buttons, I just use them
as push-button-like check boxes.
How do I proceed to get colored buttons?
/bjorn
a stripped down code snippet follows:
...
!main windows
iflag=IOR(WS_CLIPCHILDREN, &
IOR(WS_OVERLAPPEDWINDOW,WS_SIZEBOX))
hWnd = CreateWindowEx(0, &
lpszClassName, &
szCosTitle, &
int(iflag), &
0, &
0, &
cxWnd, &
cyWnd, &
NULL, &
hmenu, &
hInstance, &
NULL &
)
...
iflag = IOR(BS_AUTOCHECKBOX, IOR(BS_PUSHLIKE, &
IOR(WS_VISIBLE, WS_CHILD)))
do i=1,n
!buttons
ButtonhWnd(i) = CreateWindowEx(0, &
"BUTTON"C, &
""C, &
iflag, &
100, &
100, &
10, &
10, &
hWnd, &
NULL, &
hInstance, &
0 &
)
enddo
integer(4) function &
MainWndProc( hWnd, mesg, wParam, lParam )
...
select case ( mesg )
case (WM_CREATE)
hBluebrush = CreateSolidBrush( RGB(0,0,255) )
case (WM_CTLCOLORBTN)
hdcButton = wParam;
hwndButton = lParam;
i = SelectObject( hdcButton, hBluebrush )
i = SetBkColor( hdcButton, RGB(0,0,255) )
MainWndProc = hBluebrush !return blue brush
return
case (WM_DESTROY)
bret = DeleteObject( hBluebrush )
call PostQuitMessage( 0 )
case DEFAULT
MainWndProc = &
DefWindowProc( hWnd, mesg, wParam, lParam )
return
end select
MainWndProc = 0
return
end function MainWndProc
Link Copied
3 Replies
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
The best you can get is a bitmap or icon attached to the button with BS_BITMAP or BS_ICON style (see recent thread ). The feature you discovered is by design. Remarks on WM_CTLCOLORBTN in the help aren't very clear, though.
A more complicated alternative would be to use owner-draw buttons (BS_OWNERDRAW) but that would require that you do all drawing by yourself
when processing WM_DRAWITEM; (but DrawFrameControl(DFC_BUTTON, DFC_BUTTONPUSH,...) might be very helpful with that).
HTH
Jugoslav
A more complicated alternative would be to use owner-draw buttons (BS_OWNERDRAW) but that would require that you do all drawing by yourself
when processing WM_DRAWITEM; (but DrawFrameControl(DFC_BUTTON, DFC_BUTTONPUSH,...) might be very helpful with that).
HTH
Jugoslav
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Documentation on WM_CTLCOLORBTN is very spotty, and would lead one to believe that this message works as described. But it doesn't; a hunt through the various archives and books turns up a comment from Petzold in his Win95 book (still valuable) that WM_CTLCOLORBTN only works with owner-draw buttons, which is of course a nonsensical and totally useless situation. Go figure. As Jugoslav has noted, making buttons with bitmaps does work, and is very easy.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
thanks folks!
ICONS works OK
regs
/Bjrn
ICONS works OK
regs
/Bjrn

Reply
Topic Options
- Subscribe to RSS Feed
- Mark Topic as New
- Mark Topic as Read
- Float this Topic for Current User
- Bookmark
- Subscribe
- Printer Friendly Page