Winapi background color

Started by
15 comments, last by stranger4u 21 years, 7 months ago
How do I make the background of my window greyish? Like how dialog boxes look like? When I feel in the WNDCLASS background variable I know that I can use brushes that I can get with GetStockObject but they are black or white or whatever.. And then there are COLOR_WINDOW and so on but that''s not helping. I''d like to have either the dialog grey default color or a custom color. I tried to use CreateSolidBrush to get a custm color background but it didn''t work. Then I thought about painting the whole window in a color on every WM_PAINT but wouldn''t that paint over all my controls so you would only see the color? This question must be really stupid, but I can''t figure it out myself.
Advertisement
CreateSolidBrush() is the way.


  HBRUSH hBrush = CreateSolidBrush(RGB(120,120,120));WNDCLASS wndClass;// ...wndClass.hbrBackground = hBrush;// .. program is overDeleteObject(hBrush);  



Goblineye Entertainment
The road to success is always under construction
Goblineye EntertainmentThe road to success is always under construction

  wc.hbrBackground = HBRUSH(COLOR_BTNFACE + 1);  

gives you the default window frame color. I think that''s better than specifying a RGB because the user may change his window settings.

http://roninmagus.hopto.org
acronymfinder.com - Find any acronym you need!
Thanks it''s working, but now I got another (color?) problem. When I create edit fields like this:


  CreateWindow(										   "EDIT", 										   "", 										   WS_CHILD | WS_VISIBLE | WS_BORDER | ES_AUTOHSCROLL,										   100,20,150,20,										   hwnd,										   (HMENU) 1, 										   g_hinstance, 										   NULL);  


They are all in the same color as the background making them invisible. When I click on one though it changes the color to white.
That''s odd. It sounds as though you''re having a paint problem; maybe the edit control isn''t actually even being drawn to the window until it''s clicked. Now...I''m trying to think back to some of my own code...I''ve used edit controls before...dang, can''t really remember anything different from what you''ve done...wait a sec, why are you specifying "(HMENU) 1" as the menu? Edit controls can''t have menus; is that just another kind of "NULL"?
Well, I''m probably not helping any. Just one thing - are you creating your control in the main function, the WindowProc function, or a different one? It shouldn''t make a difference really, but sometimes it might end up that one window (your edit control, f''rinstance) might be created before another (the main window, referred to as hwnd in your code). Other than what I mentioned above, the code you posted is all right.

Twilight Dragon
Win32 API Programmer
www.freewebz.com/j-world
{[JohnE, Chief Architect and Senior Programmer, Twilight Dragon Media{[+++{GCC/MinGW}+++{Code::Blocks IDE}+++{wxWidgets Cross-Platform Native UI Framework}+++
The "menu" is just used to identify the edit box later and I''m creating them when my main windows gets the WM_CREATE message.
Very odd. What you have shouldn't, as far as I know, cause any problems. All I can suggest is perhaps moving the control creation routines to a specialized function, and perhaps calling it after creating the main window, in whatever function that is.
quote:
The "menu" is just used to identify the edit box later

Hmm...how would you do that? If I were doing it, I'd specify a name in the window name parameter of CreateWindow, and use that. Oh well, it's your kettle of fish.

Twilight Dragon
Win32 API Programmer
www.freewebz.com/j-world

[edited by - TDragon on August 29, 2002 4:56:16 PM]
{[JohnE, Chief Architect and Senior Programmer, Twilight Dragon Media{[+++{GCC/MinGW}+++{Code::Blocks IDE}+++{wxWidgets Cross-Platform Native UI Framework}+++
doesn''t help, still the same color as the background.. do i have to "active" them somehow?
quote:Original post by TDragon
Hmm...how would you do that? If I were doing it, I''d specify a name in the window name parameter of CreateWindow, and use that. Oh well, it''s your kettle of fish.


from the msdn help:

HMENU hMenu, // menu handle or child identifier

so it''s not uncommon.. and i just use it because it was in a book :-)
Oh yes, I was going to suggest this, but forgot while I was making snide remarks at someone else somewhere else. Heh heh. But here it is: Use UpdateWindow([handle of the control]) or InvalidateRect([controlhandle], NULL, TRUE). I''m not sure if either of these will work with controls, since what they do is post a WM_PAINT message to the window''s/control''s processing function, but you could give it a try. Which brings to mind another thing: are you assigning the return value of CreateWindow() to anything? In your code it doesn''t look like you are; that might somehow be the problem. CreateWindow() returns an HWND; make a variable like so:
HWND edit1;
and then do:
edit1 = CreateWindow([parameters]);
That help?

Twilight Dragon
Win32 API Programmer
www.freewebz.com/j-world
{[JohnE, Chief Architect and Senior Programmer, Twilight Dragon Media{[+++{GCC/MinGW}+++{Code::Blocks IDE}+++{wxWidgets Cross-Platform Native UI Framework}+++

This topic is closed to new replies.

Advertisement