Painting the background of a window

This is a discussion on Painting the background of a window within the Windows Programming forums, part of the Platform Specific Boards category; I want to paint the background of a window black, but i cant seem to find a function that will ...

  1. #1
    Registered User
    Join Date
    Mar 2006
    Posts
    150

    Painting the background of a window

    I want to paint the background of a window black, but i cant seem to find a function that will do this in the documentation. SetBkColor only paints certain things like the background of text drawn with TextOut (). Can anyone point me in the right direction for doing this?
    HA! I WIN!

  2. #2
    Registered User
    Join Date
    Mar 2006
    Posts
    150
    nevermind, guys. once again, a little intuitive thinking and poking found me the solution fairly quickly. i found out that u can set the hbrBackground parameter of the WNDCLASSEX struct to CreateSolidBrush (RGB (0,0,0)) and u get a black background!!! Thanks 4 checkin on me anyhow!
    HA! I WIN!

  3. #3
    Registered User
    Join Date
    Mar 2006
    Posts
    150
    Ok, now the question is how do i change the font? i want to change the font for TextOut () to be Courier new, but there doesnt seem to be a SetFont or ChangeFont function listed anywhere.
    HA! I WIN!

  4. #4
    Reverse Engineer maxorator's Avatar
    Join Date
    Aug 2005
    Location
    Estonia
    Posts
    2,318
    To create a font object, use CreateFont(), then:
    Code:
    hOldFont=SelectObject(hYourDC,hYourFont);
    //your code
    SelectObject(hYourDC,hOldFont);
    "The Internet treats censorship as damage and routes around it." - John Gilmore

  5. #5
    Registered User
    Join Date
    Mar 2006
    Posts
    150
    So, how can i specify courier new? does the system load these fonts automatically, or do i have to do it myself? and if i do, how do i do it? And one other thing... what type of font is used in the MS-DOS prompt? if anyone knows that, i cant seem to figure it out. in the font selector, the default font just says raster fonts. how do i simulate that font?
    Last edited by xixpsychoxix; 01-23-2009 at 10:10 AM.
    HA! I WIN!

  6. #6
    and the Hat of Guessing tabstop's Avatar
    Join Date
    Nov 2007
    Posts
    14,185
    So you would use CreateFont as mentioned above had you read the post.

  7. #7
    Registered User
    Join Date
    Mar 2005
    Location
    Juneda
    Posts
    287
    A comment to the first part: maybe you will be interested on get some of the default colors instead of generating a brush (you won't have to delete the object):

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

    I think the de prompt font is System; take a look at the link pointed by tabstop and then apply it as says maxorator.

    Hope that helps
    Niara

  8. #8
    Registered User
    Join Date
    Mar 2006
    Posts
    150
    I've been reading that link on the CreateFont () function now for more than an hour, but i cant seem to figure out how to get the font to look exactly as i want it. What specifies the size of the font? and is that size in pixels? I'm really bad with fonts. If the size is in logical units, how do i convert that to pixel units? say i want to make a font that was 8 pixels by 12 pixels. how could i do that conversion between logical units and pixels?
    Last edited by xixpsychoxix; 01-23-2009 at 12:39 PM.
    HA! I WIN!

  9. #9
    and the Hat of Guessing tabstop's Avatar
    Join Date
    Nov 2007
    Posts
    14,185
    Quote Originally Posted by xixpsychoxix View Post
    I've been reading that link on the CreateFont () function now for more than an hour, but i cant seem to figure out how to get the font to look exactly as i want it. What specifies the size of the font? and is that size in pixels? I'm really bad with fonts.
    So you've been reading for an hour and you haven't got to the fourth line of the page yet? The one that says "int nHeight"? The documentation suggests the unit is pixels. (It says you want to take points * (pixels/in) / 72, and there are 72 points to the inch.....)

  10. #10
    Registered User
    Join Date
    Mar 2006
    Posts
    150
    thats funny, i dont recall it taking that long to get to the fourth line.. and, oh yeah, i must have just missed the part where it said about pixel height conversion, cuz i didnt try to use that with poor results... i dont know why ur suggesting that i dont read, but i tried all the examples on that particular page and they didnt yield the results i was looking for, otherwise i would not have asked. i suppose i could try again, and perhaps adjust my other code...

    In case this helps anyone, what i am trying to do is simulate a DOS box using a window. I want to be able to put a string on the window and make it look as though you are using the DOS prompt in 80x25 mode with 8x12 raster characters, and when you maximize the window, the font will adjust it's scale accordingly. I just have no idea how to work with font or do this. If anyone can tell me how this might work, i would be very appreciative.
    Last edited by xixpsychoxix; 01-23-2009 at 04:27 PM.
    HA! I WIN!

  11. #11
    train spotter
    Join Date
    Aug 2001
    Location
    near a computer
    Posts
    3,856
    Quote Originally Posted by xixpsychoxix View Post
    In case this helps anyone, what i am trying to do is simulate a DOS box using a window. I want to be able to put a string on the window and make it look as though you are using the DOS prompt in 80x25 mode with 8x12 raster characters, and when you maximize the window, the font will adjust it's scale accordingly. I just have no idea how to work with font or do this. If anyone can tell me how this might work, i would be very appreciative.
    Use a ratio to screen size based on experimentation, using your screen at differing resolutions.

    Then your app can;

    At start up
    find the screen size [GetDeviceCaps() with HORZRES|VERTRES]
    Create your window and fonts relative to the screen size

    handle WM_SIZE msgs
    recreate your GDI objects relative to the new size
    redraw the entire window.

    [Be VERY careful not to create any GDI leaks!]

    StrechBlt() is an alternative (from a mem DC, as in double buffering), but results with text are not good.
    "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

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. WM_CAPTION causing CreateWindowEx() to fail.
    By Necrofear in forum Windows Programming
    Replies: 8
    Last Post: 04-06-2007, 08:23 AM
  2. 6 measly errors
    By beene in forum Game Programming
    Replies: 11
    Last Post: 11-14-2006, 10:06 AM
  3. Linking OpenGL in Dev-C++
    By linkofazeroth in forum Game Programming
    Replies: 4
    Last Post: 09-13-2005, 10:17 AM
  4. OpenGL Window
    By Morgul in forum Game Programming
    Replies: 1
    Last Post: 05-15-2005, 12:34 PM
  5. problem with open gl engine.
    By gell10 in forum Game Programming
    Replies: 1
    Last Post: 08-21-2003, 04:10 AM

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