user3012804
user3012804

Reputation: 81

change the background color of button created using Createwindow command

Hello I want to change the background color of button. Here is my code for button

 hwndTemp = CreateWindow(TEXT("BUTTON"), Str("Settings"),
    WS_CHILDWINDOW|WS_VISIBLE|WS_TABSTOP|BS_TEXT|BS_PUSHBUTTON|WS_CLIPSIBLINGS,
    0, 0, 0, 0, hwndMain, (HMENU)ID_SETTINGS, 0, 0);
SendMessage(hwndTemp, WM_SETFONT, (WPARAM)GetStockObject(DEFAULT_GUI_FONT), TRUE);

There are 3 or 4 more button and i want to apply the change to every one of them. And all of them have different (HMENU) name.

Upvotes: 2

Views: 2062

Answers (1)

ScottMcP-MVP
ScottMcP-MVP

Reputation: 10415

The button controls that are native to Windows do not have a background color property you can change. And WM_CTLCOLORBTN does not work (and has never worked). You can customize the appearance of your buttons with the BS_OWNERDRAW style or the newer NM_CUSTOMDRAW message. It is not as simple as setting the background color: You have to draw the entire button.

There are quite a few examples of these techniques at codeproject:

http://www.codeproject.com/Articles/3269/Native-Win32-Theme-aware-Owner-draw-Controls-witho

http://www.codeproject.com/Articles/12340/CImageButtonWithStyle-Buttons-using-Images-with-XP

Upvotes: 7

Related Questions