• ### Announcements

#### Archived

This topic is now archived and is closed to further replies.

# winAPI control coloring

## Recommended Posts

I''ve been looking through all the seemingly useful functions available etc. Yet I can''t seem to get my dialog box''s background color to change from the default. Also, I want to change the font/style of the text entered into my control (edit box specifically) within this dialog. I tried the following at the dialog initialization: hdc = GetDC(hwnd); //for the dialog itself OR hdc = GetDC(GetDlgItem(hwnd, IDC_CONTROL1)); //for control COLORREF Background = RGB(intvalue1, intvalue2, intvalue3); SetBkColor(hdc, Background); // for the background SetTextColor(hdc, g_rgbBackground); //for the text Neither seems to even try to work. Isn''t it possible to change a dialog''s default bgcolor? and text in an edit control without using DrawText() etc?

##### Share on other sites
To change the background colour, the window class (that is the WNDCLASSEX structure) for the window has a member, hbrBackground which determines the brush used to draw the background. Set this to whatever you need.

To change the font, send the control the WM_SETFONT message.

codeka.com - Just click it.

##### Share on other sites
That would work for a standard window, however not for a dialog box right? I don''t have a normal window, winmain returns a dialog procedure call. Also, seting the font of an edit box sets the entire body of text to one font regardless of when it was entered. I''m trying to get separate pieces of text entered into an edit box at varying fonts/colors sort of like the way instant message windows do by having a username as a color and the message as another type of text. So simply setting the fonts via messaging etc wont work. Is there anyway to do this with a normal edit box or is it only possible with richedit. And if so, how can one be created via resource or runtime? (MSDN''s pages on richedit are all missing)

##### Share on other sites
That would work for a standard window, however not for a dialog box right? I don''t have a normal window, winmain returns a dialog procedure call. Also, seting the font of an edit box sets the entire body of text to one font regardless of when it was entered. I''m trying to get separate pieces of text entered into an edit box at varying fonts/colors sort of like the way instant message windows do by having a username as a color and the message as another type of text. So simply setting the fonts via messaging etc wont work. Is there anyway to do this with a normal edit box or is it only possible with richedit. And if so, how can one be created via resource or runtime? (MSDN''s pages on richedit are all missing)

##### Share on other sites
A tutorial at Winprog explains how to change a dialog''s background color.

I will not make a list of links... I will not make a list of links... I will not make a list of links...

• ## Partner Spotlight

• ### Forum Statistics

• Total Topics
627664
• Total Posts
2978522

• 10
• 10
• 12
• 22
• 13