Archived

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

Winapi background color

This topic is 5586 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

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.

Share this post


Link to post
Share on other sites
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.

Share this post


Link to post
Share on other sites
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

Share this post


Link to post
Share on other sites
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]

Share this post


Link to post
Share on other sites
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 :-)

Share this post


Link to post
Share on other sites
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

Share this post


Link to post
Share on other sites
Darn. I''ve never had that problem before, at all. All I can suggest is what I suggested before: experiment around with putting your code in a different function, with calling it at different times, or from different locations in the program.

Share this post


Link to post
Share on other sites
Update the parent BEFORE the children.
That is, call UpdateWindow(hwndParent);
And then call UpdateWindow(GetDlgItem(hwndParent,1));

Or, use WS_CLIPCHILDREN window style on the parent.

EDIT : Got it clearer.

[edited by - Coincoin on August 29, 2002 5:43:41 PM]

Share this post


Link to post
Share on other sites