Window Backgrounds--I'm sick of brushes

This is a discussion on Window Backgrounds--I'm sick of brushes within the Windows Programming forums, part of the Platform Specific Boards category; okay, I always see all these windows apps with source and they have the background in the window that the ...

  1. #1
    Intranasal Heroin User Xterria's Avatar
    Join Date
    Sep 2001
    Location
    Buffalo, NY
    Posts
    1,035

    Window Backgrounds--I'm sick of brushes

    okay, I always see all these windows apps with source and they have the background in the window that the user sets in the display options. in other words just he default background color. When I look in the source code for the background they have 'COLOR_WINDOW' instead of 'BLACK_BRUSH' and stuff. When I do that, my window is transparent. How come? can someone help me?

  2. #2
    zen
    zen is offline
    of Zen Hall zen's Avatar
    Join Date
    Aug 2001
    Posts
    1,007
    You want 'COLOR_WINDOW+1'.
    zen

  3. #3
    the Corvetter
    Join Date
    Sep 2001
    Posts
    1,584
    Where would you put 'COLOR_WINDOW + 1'? In the window class' hbrBackground field? And can you just keep adding numbers to make different colors (COLOR_WINDOW + 2)?

    --Garfield the Great
    1978 Silver Anniversary Corvette

  4. #4
    Guest Sebastiani's Avatar
    Join Date
    Aug 2001
    Location
    Waterloo, Texas
    Posts
    5,643
    No, I want RGB!

    How do we load color this way?
    Code:
    if( numeric_limits< byte >::digits != bits_per_byte )
        error( "program requires bits_per_byte-bit bytes" );
    24bbs.cpp

  5. #5
    zen
    zen is offline
    of Zen Hall zen's Avatar
    Join Date
    Aug 2001
    Posts
    1,007
    HBRUSH hb=CreateSolidBrush(RGB(x,y,z));

    Then use hb as your WNDCLASS background.
    zen

  6. #6
    Just one more wrong move. -KEN-'s Avatar
    Join Date
    Aug 2001
    Posts
    3,230
    Ok, I figured it out...

    for your wndclass (or wndclassex) structure's hbrbackground, do this:

    wndclass.hbrBackground = CreateSolidBrush(0);

    then whenever you want to change it, call:

    DeleteObject((HBRUSH)SetClassLong(hwnd, GCL_HBRBACKGROUND,
    (LONG)CreateSolidBrush(RGB(255,0,0))));

    you can change the RGB(255,0,0) to whatever RGB value you want.

    here's an example program

    Code:
    #include <windows.h>
    
    LRESULT CALLBACK WndProc(HWND hWnd, UINT uMsg, WPARAM wParam, 
    	LPARAM lParam);
    
    
    int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, 
    	PSTR pszCmdLine, int iShowCmd)
    {
    	WNDCLASS wc;
    	MSG msg;
    	HWND hWnd;
    
    	wc.style = 0;
    	wc.cbClsExtra = 0;
    	wc.cbWndExtra = 0;
    	wc.hbrBackground = CreateSolidBrush(0);
    	wc.hCursor = LoadCursor(NULL, IDC_ARROW);
    	wc.hIcon = LoadIcon(NULL, IDI_APPLICATION);
    	wc.hInstance = hInstance;
    	wc.lpfnWndProc = WndProc;
    	wc.lpszMenuName = NULL;
    	wc.lpszClassName = "Colors!";
    
    	RegisterClass(&wc);
    
    	hWnd = CreateWindowEx(0, "Colors!", 
    		"Pretty Colors", WS_OVERLAPPEDWINDOW, 
    		CW_USEDEFAULT, CW_USEDEFAULT, CW_USEDEFAULT, 
    		CW_USEDEFAULT, NULL, NULL, hInstance, NULL);
    
    	ShowWindow(hWnd, iShowCmd);
    	UpdateWindow(hWnd);
    
    	while (GetMessage(&msg, NULL, 0, 0))
    	{
    		TranslateMessage(&msg);
    		DispatchMessage(&msg);
    	}
    
    	return 0;
    }
    
    
    LRESULT WINAPI WndProc(HWND hwnd, UINT msg, WPARAM wParam, 
    	LPARAM lParam)
    {
    
        switch(msg)
        {
    	case WM_CREATE:
    		DeleteObject((HBRUSH)SetClassLong(hwnd, GCL_HBRBACKGROUND, 
    			(LONG)CreateSolidBrush(RGB(255,0,0))));
    		return 0;
        case WM_CLOSE:
            PostQuitMessage(0);
            return 0;
        }
        return DefWindowProc(hwnd, msg, wParam,lParam);
    }

  7. #7
    Intranasal Heroin User Xterria's Avatar
    Join Date
    Sep 2001
    Location
    Buffalo, NY
    Posts
    1,035
    thanks guys, but how do you make your background the default windows color? COLOR_WINDOW+1 just gives me white. mine is a light blue color(Windows 2000 default)

  8. #8
    Just one more wrong move. -KEN-'s Avatar
    Join Date
    Aug 2001
    Posts
    3,230
    COLOR_BTNFACE+1

  9. #9
    Just one more wrong move. -KEN-'s Avatar
    Join Date
    Aug 2001
    Posts
    3,230
    or (COLOR_BTNFACE)+1

  10. #10
    Intranasal Heroin User Xterria's Avatar
    Join Date
    Sep 2001
    Location
    Buffalo, NY
    Posts
    1,035
    thanks ken, but it still isn't giving me the default background

  11. #11
    zen
    zen is offline
    of Zen Hall zen's Avatar
    Join Date
    Aug 2001
    Posts
    1,007
    'COLOR_WINDOW+1' will give the default window background(client area) colour as specified by the user in control panel/display properties/appearance. Are you sure you mean the default window backdound?
    zen

  12. #12
    Intranasal Heroin User Xterria's Avatar
    Join Date
    Sep 2001
    Location
    Buffalo, NY
    Posts
    1,035
    ok ok....'application background'
    I think thats techniqual enough huh
    Last edited by Xterria; 11-04-2001 at 06:02 PM.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. C or C++
    By AcerN30 in forum Game Programming
    Replies: 41
    Last Post: 05-30-2008, 06:57 PM
  2. Just starting Windows Programming, School me!
    By Shamino in forum Windows Programming
    Replies: 17
    Last Post: 02-22-2008, 07:14 AM
  3. WM_CAPTION causing CreateWindowEx() to fail.
    By Necrofear in forum Windows Programming
    Replies: 8
    Last Post: 04-06-2007, 08:23 AM
  4. 6 measly errors
    By beene in forum Game Programming
    Replies: 11
    Last Post: 11-14-2006, 10:06 AM
  5. OpenGL Window
    By Morgul in forum Game Programming
    Replies: 1
    Last Post: 05-15-2005, 12:34 PM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21