how do i make this a different color..

This is a discussion on how do i make this a different color.. within the Windows Programming forums, part of the Platform Specific Boards category; hey, i have a "login" window for this program i'm writing. the login is locally, not very secure, etc. but ...

  1. #1
    Shibby willc0de4food's Avatar
    Join Date
    Mar 2005
    Location
    MI
    Posts
    378

    how do i make this a different color..

    hey, i have a "login" window for this program i'm writing. the login is locally, not very secure, etc. but i dont need it to be fort knox as this is my first time playing around with such methods. however, my question is about something that irritates me to no end...on my login window, theres the window, menu, edit box, and button. you can see it here:
    http://img.photobucket.com/albums/v4...hy85/login.jpg
    the background of the login window is white. i would like to paint it a different color. i know how to create a brush..but i dont know how to modify the color of that area. right now for HWND's that i have declared, theres one for the main window, one for the login button, one for the edit box, and one for the status bar.

    so..how do i do it? thanks.
    Registered Linux User #380033. Be counted: http://counter.li.org

  2. #2
    train spotter
    Join Date
    Aug 2001
    Location
    near a computer
    Posts
    3,859
    In your paint handler you could create a brush and use FillRect(), Rectangle() or similar on the RECT in the PAINTSTRUCT or on the client area.

    Try CreatePatternBrush() using an image......

    Or (simplified) load an image, CreateCompatibleDC(), CreateCompatibleBitmap() and BitBlt() the image to the PAINTSTRUCT hdc.
    "Man alone suffers so excruciatingly in the world that he was compelled to invent laughter."
    Friedrich Nietzsche

    "I spent a lot of my money on booze, birds and fast cars......the rest I squandered."
    George Best

    "If you are going through hell....keep going."
    Winston Churchill

  3. #3
    Registered User
    Join Date
    Sep 2004
    Location
    California
    Posts
    3,246
    Some pseudo code of what your WM_PAINT event handler would look like:
    Code:
    HDC hdc, hdcMem;
    HBITMAP hbmMem;
    HANDLE hOld;
    hdc = BeginPaint(hwnd,&ps);
    /* Create an off-screen DC for double-buffering */
    hdcMem = CreateCompatibleDC(hdc);
    hbmMem = CreateCompatibleBitmap(hdc, width, height);
    hOld   = SelectObject(hdcMem, hbmMem);
    FillRect(hdcMem,&rClient,(HBRUSH)COLOR_WINDOW);
    /* Transfer the off-screen DC to the screen */
    BitBlt(hdc, 0, 0, width, height, hdcMem, 0, 0, SRCCOPY);
    /* Free-up the off-screen DC */
    SelectObject(hdcMem, hOld);
    DeleteObject(hbmMem);
    DeleteDC(hdcMem);
    EndPaint(hwnd,&ps);
    Change the FillRect() HBRUSH value to the color you want. You can use CreateSolidBrush() to create a brush with the color value you want.

  4. #4
    Shibby willc0de4food's Avatar
    Join Date
    Mar 2005
    Location
    MI
    Posts
    378
    thanks guys
    the pseudo code was a big help in making it work. this is what it looks like now:
    http://img.photobucket.com/albums/v4...5/loginyay.jpg
    Registered Linux User #380033. Be counted: http://counter.li.org

  5. #5
    Registered User Queatrix's Avatar
    Join Date
    Apr 2005
    Posts
    1,342
    Something else you could always do is set the windows background color in it's class before creating it.

  6. #6
    Shibby willc0de4food's Avatar
    Join Date
    Mar 2005
    Location
    MI
    Posts
    378
    mm...huh? / how?

    the program is a text editor..and i dont want the edit box to be non-white after the user logs in, i just want the window non-white for the login screen. that still work?

    thanks
    Registered Linux User #380033. Be counted: http://counter.li.org

  7. #7
    Registered User Queatrix's Avatar
    Join Date
    Apr 2005
    Posts
    1,342
    Think about it, if you make the windows background color in it's class before creating it, the window would be black in the login screen. But once the login screen is over and the edit box comes up, (this is assuming that the edit box covers your whole screen.) you wouldn't even be able to tell that the screen is black to begin with, it's not like the edit boxs background is clear, it's white. (If it's not owner drawn that is.)

  8. #8
    Registered User
    Join Date
    Sep 2004
    Location
    California
    Posts
    3,246
    this is assuming that the edit box covers your whole screen.
    And assuming he makes an edit box at all. What if he outputs his text with TextOut()?

  9. #9
    Shibby willc0de4food's Avatar
    Join Date
    Mar 2005
    Location
    MI
    Posts
    378
    ahh..yea..forgot about that.
    *shrug*
    all ways work. here's what my main window looks like:
    http://img.photobucket.com/albums/v4...chy85/main.jpg
    Registered Linux User #380033. Be counted: http://counter.li.org

  10. #10
    Registered User Queatrix's Avatar
    Join Date
    Apr 2005
    Posts
    1,342
    bithub, here Will-Code-For-Food said:
    Quote Originally Posted by willc0de4food
    mm...huh? / how?

    the program is a text editor..and i dont want the edit box to be non-white after the user logs in, i just want the window non-white for the login screen. that still work?

    thanks
    Why would he have spoken of an edit box it if there isn't any?

  11. #11
    Shibby willc0de4food's Avatar
    Join Date
    Mar 2005
    Location
    MI
    Posts
    378
    mm...on a side note, how do i determine what error code i'm getting from a windows function? like if i have LONG errorcode; and then i DO get an error code, so i have errorcode = GetLastError(); how would i figure out what error i'm getting? like if i output it to a file and i use %ld as the conversion specifier...i get a bunch of numbers like -2146893816 but if i do %c then i get 

    lol thanks
    Registered Linux User #380033. Be counted: http://counter.li.org

  12. #12
    carry on JaWiB's Avatar
    Join Date
    Feb 2003
    Location
    Seattle, WA
    Posts
    1,972
    Did you look at this or probably easier look up the error code
    "Think not but that I know these things; or think
    I know them not: not therefore am I short
    Of knowing what I ought."
    -John Milton, Paradise Regained (1671)

    "Work hard and it might happen."
    -XSquared

  13. #13
    Shibby willc0de4food's Avatar
    Join Date
    Mar 2005
    Location
    MI
    Posts
    378
    dude, why does there have to be so many parameters for EVERYTHING ? it would be nice if you could just be like EncryptText(sourceText, destText, encryptType); or FormatMessage(soIcanReadIt); hahaha

    k, i'm done ranting thank you.


    but yea..the error i got was returned from a CryptGetKey() function and the value of it that i had printed was negative and started with a 2. those error codes are all positive and end at 15999, lol
    Registered Linux User #380033. Be counted: http://counter.li.org

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Binary Search Trees Part III
    By Prelude in forum A Brief History of Cprogramming.com
    Replies: 16
    Last Post: 10-02-2004, 04:00 PM
  2. "Cannot make pipe"
    By crepincdotcom in forum C Programming
    Replies: 5
    Last Post: 08-16-2004, 01:43 PM
  3. Question about atheists
    By gcn_zelda in forum A Brief History of Cprogramming.com
    Replies: 160
    Last Post: 08-11-2003, 12:50 PM
  4. 'functions' in make?
    By mart_man00 in forum C Programming
    Replies: 1
    Last Post: 06-21-2003, 03:16 PM
  5. Just one Question?
    By Irish-Slasher in forum C++ Programming
    Replies: 6
    Last Post: 02-12-2002, 10:19 AM

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