Chnage Look of Win32 Buttons

It has come to my attention that when I program in Win32 and create buttons, they look like the ones that run on Windows XP. How do you make them (the buttons) look like Windows 7 or Vista at the least? Also, if you run the calculator that comes with your computer, you'll notice that the buttons turn gold when you hover over them, here is an image:

http://imageshack.us/photo/my-images/40/buttonsv.png/

Please help me, any information would be appreciated.

Thanks in advance!
If memory serves, you need to put some kind of manifest file in the project directory before you build, but that may have only been with wxWidgets.

What compiler are you using?
Last edited on
Thanks for the reply, I am using Microsoft VC++ 2008 and 2010.

I did solve the problem with making the buttons look like they are Windows Vista/7. However, I still could not seem to figure out how to change their colors and sizes.

For those of you how are wondering, just add this line to your compiler and it will make the buttons look like they are Windows Vista/7.

1
2
3
#pragma comment(linker,"\"/manifestdependency:type='win32' \
name='Microsoft.Windows.Common-Controls' version='6.0.0.0' \
processorArchitecture='*' publicKeyToken='6595b64144ccf1df' language='*'\"") 



Please reply, thanks again.
I thought the size of a button was whatever you set it to when you created it? Or changed it to using MoveWindow?

To change the color of a button, it's parent can handle WM_CTLCOLORBTN
http://msdn.microsoft.com/en-us/library/bb761849(v=vs.85).aspx

(To really customize the look of a button, e.g. give it a custom shape, you need to use owner draw: see MSDN entries for WM_DRAWITEM and DRAWITEMSTRUCT)

I am a bit unsure of the interaction of themes and WM_CTLCOLORBTN.

Andy

P.S. if you're using message relection, adjust approach accordingly
Last edited on
Thank you for replying.

I tried using WM_CTLCOLERBTN, but i was unsure how to get it to work. I have tried almost everything I can think of and searched all over the web.

Do you have any idea on how to use it?

Thanks.
Sorry, it's been a while since I've tried to do this to a push button... I usually colour other controls. It turns out that the WM_CTLCOLORBTN mechanism doesn't work for push buttons.

So it looks like the WM_DRAWITEM approach is the only one available :-(

Andy

From MSDN entry for WM_CTLCOLORBTN Notification

By default, the DefWindowProc function selects the default system colors for the button. Buttons with the BS_PUSHBUTTON, BS_DEFPUSHBUTTON, or BS_PUSHLIKE styles do not use the returned brush. Buttons with these styles are always drawn with the default system colors. Drawing push buttons requires several different brushes-face, highlight, and shadow-but the WM_CTLCOLORBTN message allows only one brush to be returned. To provide a custom appearance for push buttons, use an owner-drawn button.


Last edited on
Ehhh, I don't know how I will figure out how to do it.


Thanks anyway.
When a WM_DRAWITEM message arrives it provides you with all the info you need to draw the button (like whether is pushed, etc.), plus the device context to use.

There are functions which can do some of the fork for you: FillRect, FrameRect. And if you are happy enough with standard color edges, DrawEdge (I've never tried to change the color of the edges.)

This project might help you understand the process.

Owner-draw icon buttons in plain C (no MFC)
http://www.codeproject.com/KB/buttons/odib.aspx

And this one : it's in MFC, but the MFC class methods are pretty each to associate with their GDI equivalents

Color Button
http://www.codeproject.com/KB/buttons/ColorButton.aspx
Last edited on
Topic archived. No new replies allowed.