Archived

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

winAPI control coloring

This topic is 5702 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

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 this post


Link to post
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.

Look in MSDN for more info about these two things...


codeka.com - Just click it.

Share this post


Link to post
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 this post


Link to post
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 this post


Link to post
Share on other sites