Thread: Window Backgrounds--I'm sick of brushes

  1. #1
    "The Oldest Member Here" Xterria's Avatar
    Join Date
    Sep 2001
    Location
    Buffalo, NY
    Posts
    1,039

    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
    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,708
    No, I want RGB!

    How do we load color this way?
    Code:
    #include <cmath>
    #include <complex>
    bool euler_flip(bool value)
    {
        return std::pow
        (
            std::complex<float>(std::exp(1.0)), 
            std::complex<float>(0, 1) 
            * std::complex<float>(std::atan(1.0)
            *(1 << (value + 2)))
        ).real() < 0;
    }

  5. #5
    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,227
    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
    "The Oldest Member Here" Xterria's Avatar
    Join Date
    Sep 2001
    Location
    Buffalo, NY
    Posts
    1,039
    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,227
    COLOR_BTNFACE+1

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

  10. #10
    "The Oldest Member Here" Xterria's Avatar
    Join Date
    Sep 2001
    Location
    Buffalo, NY
    Posts
    1,039
    thanks ken, but it still isn't giving me the default background

  11. #11
    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
    "The Oldest Member Here" Xterria's Avatar
    Join Date
    Sep 2001
    Location
    Buffalo, NY
    Posts
    1,039
    ok ok....'application background'
    I think thats techniqual enough huh
    Last edited by Xterria; 11-04-2001 at 07: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, 08: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, 11:06 AM
  5. OpenGL Window
    By Morgul in forum Game Programming
    Replies: 1
    Last Post: 05-15-2005, 12:34 PM