Thread: Windows background

  1. #1
    Registered User
    Join Date
    Mar 2007
    Posts
    7

    Windows background

    is there any way to change the background of a windows application?
    thanks in advance.

  2. #2
    Guest Sebastiani's Avatar
    Join Date
    Aug 2001
    Location
    Waterloo, Texas
    Posts
    5,708
    yes.
    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;
    }

  3. #3
    Registered User Joelito's Avatar
    Join Date
    Mar 2005
    Location
    Tijuana, BC, México
    Posts
    310
    Quote Originally Posted by Sebastiani View Post
    yes.
    Agree ^^
    * PC: Intel Core 2 DUO E6550 @ 2.33 GHz with 2 GB RAM: Archlinux-i686 with xfce4.
    * Laptop: Intel Core 2 DUO T6600 @ 2.20 GHz with 4 GB RAM: Archlinux-x86-64 with xfce4.

  4. #4
    Registered User
    Join Date
    Apr 2007
    Posts
    102
    lol maybe, I can be more specific than the other two fellas there..

    The window proprerty when you set up a window called.
    windowClass.hbrBackground;
    can be set to other colors previoiusly defined in windows.h
    I'm not sure of all of the possibilities, but it has to be of the HBRUSH type.

    try googling it.
    My Favorite Programming Line:
    Code:
    #define true ((rand() % 2) ? true : false)

  5. #5
    Registered User
    Join Date
    Dec 2005
    Location
    Canada
    Posts
    267
    @JJRMJR
    He only asked if it were possible

    OS: Windows 7, XUbuntu 11.10, Arch Linux
    IDE: CodeBlocks
    Compiler: GCC

  6. #6
    and the hat of int overfl Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    39,659
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper.

  7. #7
    Registered User
    Join Date
    Mar 2007
    Posts
    7
    i want to be able to change the color to something other than gray, white, or black. i am currently making a program intended for children, and it would be more appealing if it were colorful.

  8. #8
    Guest Sebastiani's Avatar
    Join Date
    Aug 2001
    Location
    Waterloo, Texas
    Posts
    5,708
    one way is to handle the WM_ERASEBKGND message by selecting an HBRUSH into the target window's device context, then calling PatBlt() to paint to the window, and finally returning 1 (ie: true) from the callback procedure to indicate that you do not want the operating system to clear the window with the default brush.
    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;
    }

  9. #9
    Registered User
    Join Date
    Mar 2005
    Location
    Juneda
    Posts
    291
    Also you can setup the background color on the 'WNDCLASSEX' struct (before register it), take a lok at the 'hbrBackground' parameter: it's an HBRUSH type, so you can assign any color in this type

    Code:
    //for a white background:
    wc.hbrBackground=HBRUSH)GetStockObject(WHITE_BRUSH);
    //or in red:
    wc.hbrBackground=(HBRUSH)CreateSolidBrush(0x000000ff);
    I think that the right way for the second method is to create a global brush, and free it before quit the program

    Code:
    static HBRUSH red=(HBRUSH)CreateSolidBrush(0x000000ff);
    
    WINAPI WinMain(...)
    {
    WNDCLASSEX wc;
    ...
    wc.hbrBackground=red;
    ...
    
    MakeTheLoopHere();
    
    //free all and return
    DeleteObject(red);
    return msg.wParam;
    }
    (I have omited a lot of code, only left the important part). The 'reb' brush is declared as global, and before end I free the memory used.


    Hope that helps.
    Niara

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. how to make a windows application
    By crvenkapa in forum C++ Programming
    Replies: 3
    Last Post: 03-26-2007, 09:59 AM
  2. Script errors - bool unrecognized and struct issues
    By ulillillia in forum Windows Programming
    Replies: 10
    Last Post: 12-18-2006, 04:44 AM
  3. Question..
    By pode in forum Windows Programming
    Replies: 12
    Last Post: 12-19-2004, 07:05 PM
  4. SDL and Windows
    By nickname_changed in forum Windows Programming
    Replies: 14
    Last Post: 10-24-2003, 12:19 AM
  5. Manipulating the Windows Clipboard
    By Johno in forum Windows Programming
    Replies: 2
    Last Post: 10-01-2002, 09:37 AM