How to preserve background after TextOut?

This is a discussion on How to preserve background after TextOut? within the Windows Programming forums, part of the Platform Specific Boards category; After I call TextOut, it creates whitespace under the text over my colorful background??? very annoying! Any ideas?...

  1. #1
    Guest Sebastiani's Avatar
    Join Date
    Aug 2001
    Location
    Waterloo, Texas
    Posts
    5,703

    How to preserve background after TextOut?

    After I call TextOut, it creates whitespace under the text over my colorful background???

    very annoying!

    Any ideas?
    Code:
    #include <cmath>
    #include <complex>
    bool 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;
    }

  2. #2
    &TH of undefined behavior Fordy's Avatar
    Join Date
    Aug 2001
    Posts
    5,789
    Have you tried SetBkColor()??

  3. #3
    Guest Sebastiani's Avatar
    Join Date
    Aug 2001
    Location
    Waterloo, Texas
    Posts
    5,703
    No, but will it work if the background is a loaded bitmap?

    Anyway thanks for the tip, I'll try it as soon as I can get to my compiler...(sigh) one week away....!
    Code:
    #include <cmath>
    #include <complex>
    bool 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
    &TH of undefined behavior Fordy's Avatar
    Join Date
    Aug 2001
    Posts
    5,789
    I've not tried it, but you could try;

    Code:
    SetBkMode(hdc,TRANSPARENT);

  5. #5
    Guest Sebastiani's Avatar
    Join Date
    Aug 2001
    Location
    Waterloo, Texas
    Posts
    5,703
    Ok I'll definately try it...

    Thanks fordy...
    Code:
    #include <cmath>
    #include <complex>
    bool 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;
    }

  6. #6
    Registered User minime6696's Avatar
    Join Date
    Aug 2001
    Posts
    267

    Smile Cool :)

    Hey, I wu'z wondering that 1 2,

    Thx, SPH

  7. #7
    Registered User Dual-Catfish's Avatar
    Join Date
    Sep 2001
    Posts
    802
    Your device context will always be set to the default background color when it's created. If you change it, you must also 'tell' the device context what color it is, or it will print using the default background color. You can do as Fordy said, or you can call:

    CDC::SetBkColor(COLORREF color);
    (easiest way to do this would be using the RGB(0,0,0) macro)

    This function will return the previous color the device context was using.

    I just finished reading a chapter all about this, gotta show off my knowledge

  8. #8
    Sebas
    Guest
    Yes but again, the problem is, my background is a bitmap I've loaded!
    I do have a little experience using bitshifting on bitmaps upon other bitmaps(such as background), but I do not *grok* how to do this with text created with TextOut....arghh!

  9. #9
    Registered User Dual-Catfish's Avatar
    Join Date
    Sep 2001
    Posts
    802
    Then CDC::SetBkMode(TRANSPARENT); should work. Does it? or did you get a chance to try it yet?

  10. #10
    Guest Sebastiani's Avatar
    Join Date
    Aug 2001
    Location
    Waterloo, Texas
    Posts
    5,703
    Unfortunately, I'll be away from my compiler for a few days, but, yes I will try it.

    Also, if it doesn't work, I think i know what will...it's a little worked-up, but it may be the only solution:

    -Calculate the area/position of the rect that the text will occupy
    -Copy this area of the background to a temp DC
    -TextOut the text
    -OR the stored pixels onto the text area

    This operation could easily be encapsulated in a function....

    ...will update y'all either way....

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. My first "real" windows app
    By JoshR in forum Windows Programming
    Replies: 2
    Last Post: 07-28-2005, 07:40 AM
  2. Windows background color
    By Exile in forum Windows Programming
    Replies: 2
    Last Post: 01-23-2005, 06:55 AM
  3. Detect Close of a background process
    By Schwarzhelm in forum C Programming
    Replies: 1
    Last Post: 11-05-2003, 12:46 AM
  4. Background Colour in Windows API
    By Vicked in forum Windows Programming
    Replies: 2
    Last Post: 04-14-2003, 03:49 AM
  5. how to set the background colour of a static box?
    By Cobras2 in forum Windows Programming
    Replies: 2
    Last Post: 08-01-2002, 04:57 PM

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