Thread: Having awful trouble getting background color of window to white

  1. #1
    Shadow12345
    Guest

    Having awful trouble getting background color of window to white

    Hello I am trying to get my program to have a white window, however when I include the following it still doesn't work (shows up black)

    wc.hbrBackground = (HBRUSH)GetStockObject(WHITE_BRUSH);

    and i am not sure what I am doing wrong

    also I have an opengl viewport in my program, I don't know if that is what is messing it up, or if I have supplied enough information for anyone to be able to actually help me at all.

  2. #2
    Registered User
    Join Date
    Apr 2002
    Posts
    1,571
    Try using this in place of your GetStockObject call...

    Code:
    (HBRUSH)(COLOR_WINDOW + 1);
    Edit: Well GetStockObject( WHITE_BRUSH ) should work just as good. Maybe its OpenGL specific like when you fill or clear the back buffer. I haven't done a ton of OpenGL ( only Direct3D ).
    Last edited by MrWizard; 12-13-2002 at 11:09 PM.

  3. #3
    Guest Sebastiani's Avatar
    Join Date
    Aug 2001
    Location
    Waterloo, Texas
    Posts
    5,708
    Sometimes you have to force the brush, ie: call PatBlt() explicitly.

    Try this:

    HBRUSH brush = (HBRUSH)GetStckObject(WHITE_BRUSH);
    HBRUSH old = (HBRUSH)SelectObject(hdc, brush);
    RECT rc; GetClientRect(hwnd, &rc);
    PatBlt(hdc, 0, 0, rc.right-rc.left, rc.bottom-rc.top, PATCOPY);
    SelectObject(hdc, old);
    InvalidateRect(hwnd, &rc, TRUE);

    Or maybe even GL is overwriting yours. That would make things more complicated unless you are using your own paint handler....
    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;
    }

  4. #4
    erstwhile
    Join Date
    Jan 2002
    Posts
    2,227
    >>an opengl viewport<<

    I think you need to change the gl colour; look for glClearColor and set its colour to white eg:
    Code:
    glClearColor(1.0f,1.0f,1.0f,0.5f);
    CProgramming FAQ
    Caution: this person may be a carrier of the misinformation virus.

  5. #5
    Shadow12345
    Guest
    I think you need to change the gl colour; look for glClearColor and set its colour to white eg:
    the point is being able to have the gl color buffer hold any value without worrying about it changing the color of the window.

    here is a picture of the problem, i will then try sebastiani's suggestion

  6. #6
    Guest Sebastiani's Avatar
    Join Date
    Aug 2001
    Location
    Waterloo, Texas
    Posts
    5,708
    Yes but the value of the gl color buffer controls the brush fill, so why not use Kens suggestion to change it. Seems simpler than my solution anyway.
    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;
    }

  7. #7
    Shadow12345
    Guest
    Yes but the value of the gl color buffer controls the brush fill, so why not use Kens suggestion to change it. Seems simpler than my solution anyway.
    I dont exactly know what you mean, I have a feeling the reverse is true also. Whatever color I choose for the glcolor buffer using glClearColor ends up being the color for not only the background in my opengl rendering viewport, but also the background color of the Window as well. I set the glviewport color to green, the window is green, I set the viewport color to black, the window is black. That is my problem.

  8. #8
    Emotionally Unstable DarkViper's Avatar
    Join Date
    Oct 2002
    Posts
    343
    Code:
    WndClass.hbrBackground = (HBRUSH) (COLOR_WINDOW+1);
    that makes it white by default, but how do you make the default window background color to something like red?
    ~DJ DarkViper signing out
    ----------------------------------------
    My Site:
    Black Jaguar Studios

    Languages:
    Fluent English, Starter German, HTML, Javascript, Actionscript, Intermediate PHP

    Verteran Despiser of: ASP, Java, BASIC, Pascal, Cobalt

  9. #9
    Shadow12345
    Guest
    that makes it white by default, but how do you make the default window background color to something like red?
    By looking here:
    Here

  10. #10
    Registered User
    Join Date
    Dec 2002
    Posts
    119
    WndClass.hbrBackground = (HBRUSH) (COLOR_WINDOW+1);--------------------------------------------------------------------------------


    that makes it white by default, but how do you make the default window background color to something like red?

    Use the CreateSolidBrush API and to create a COLORREF use the RGB macro Red would be RGB(255, 0, 0);
    If you speak or are learning Spanish, check out this Spanish and English Dictionary, it is a handy online resource.
    What happens is not as important as how you react to what happens. -Thaddeus Golas

  11. #11
    Registered User
    Join Date
    Dec 2002
    Posts
    20
    WM_PAINT

    SetClassLong(hwnd, GCL_HBRBACKGROUND, (LONG)CreateSolidBrush(RGB(255, 255, 255)));

    is it what u wanted?

  12. #12
    Unregistered Leeman_s's Avatar
    Join Date
    Oct 2001
    Posts
    753
    btw i'd suggest using windows media player vs. winamp. just a personal opinion heh.

  13. #13
    Emotionally Unstable DarkViper's Avatar
    Join Date
    Oct 2002
    Posts
    343
    hey cool! that would work! sweet!

    and btw, i used WinAmp, or kazaa, whichever is most available
    ~DJ DarkViper signing out
    ----------------------------------------
    My Site:
    Black Jaguar Studios

    Languages:
    Fluent English, Starter German, HTML, Javascript, Actionscript, Intermediate PHP

    Verteran Despiser of: ASP, Java, BASIC, Pascal, Cobalt

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. OpenGL and Windows
    By sean345 in forum Game Programming
    Replies: 5
    Last Post: 06-24-2002, 10:14 PM
  2. Tab Controls - API
    By -KEN- in forum Windows Programming
    Replies: 7
    Last Post: 06-02-2002, 09:44 AM
  3. window painting background
    By SushiFugu in forum Windows Programming
    Replies: 4
    Last Post: 02-22-2002, 01:59 AM
  4. opengl code not working
    By Unregistered in forum Windows Programming
    Replies: 4
    Last Post: 02-14-2002, 10:01 PM
  5. Winamp Vis if anyone can help
    By Unregistered in forum Windows Programming
    Replies: 6
    Last Post: 01-27-2002, 12:43 AM