Thread: window painting background

  1. #1
    Registered User
    Join Date
    Dec 2001
    Posts
    29

    Question window painting background

    Ok, I have a simple app that can draw lines and shapes, etc..

    It draws to the screen DC and to a frame buffer memory DC which I use to keep track of what has been drawn.

    Now, to the problem.. when the screen is redrawn (when my window proc handles WM_PAINT) it redraws everything correctly, except for some reason the background is black (when it should be white).

    It is redrawn using a simple BitBlt from the memory to the screen.

    I'll post some code if its really needed, but I would think someone could figure this out without it.

    Thanks for any advice.

  2. #2
    train spotter
    Join Date
    Aug 2001
    Location
    near a computer
    Posts
    3,868
    Realy need some code.

    Are you creating compatible bitmaps in both HDC's of the right size?

    What flag are you using for the type of drawing (last param in BitBlt() )? use SRCCOPY

    Are you painting the bmp's white at any stage?

    Are you BitBlt() ing the screen dc to the frame buffer before calling for a WP_PAINT?

    Use this to paint the buffer white.
    Code:
    BitBlt(hdcBuffer, 0, 0, iWidth, iHeight, hdcBuffer, 0, 0, WHITENESS);
    "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
    Dec 2001
    Posts
    29
    Yes, I have bitmaps on both side..
    Yes, i'm using SRCCOPY.
    I don't know what you mean by painting the bitmaps white... this is a simple painting app, so you can choose any color of brush if thats what you mean.. but besides for that, no.
    Yes, before the call to WM_PAINT there is a call to BitBlt to copy the screen to the memory DC.

    I'm not sure how to do the code formatting thing.. but here is what I have in WM_PAINT:

    else if(Message==WM_PAINT)
    {
    PAINTSTRUCT psStruct;
    hDc=BeginPaint(hwnd,&psStruct);

    BitBlt(hDc,0,0,nWidth,nHeight,hDcMem,0,0,SRCCOPY);

    EndPaint(hwnd,&psStruct);
    return 0;
    }

    hDc is just my screen DC, and hDcMem is obviously my frame buffer (mem). nWidth and nHeight were gathered using GetDeviceCaps.

    Everything is displayed properly.. just the background is black, so i'm not sure what would cause that. I'm new to doing GDI stuff so its possible I just missed something.

    Hope that helps some..
    As usual, any help is appreciated

  4. #4
    train spotter
    Join Date
    Aug 2001
    Location
    near a computer
    Posts
    3,868
    When the bitmaps are created using a call to
    CreateCompatibleBitmap() or similar they contain an image full of rubbish, random values in each pixcell.

    Mine have blackish distortion in them at start so I paint them white (or another colour). They need to be 'initialised', you would not use a variable without first initialising its contents.

    The bitmap was created at the same size as nWidth, nHeight?



    http://www.cprogramming.com/cboard/s...threadid=10866
    has a zip of a graphing program (not working) with a functioning frame buffer system. (graphfix.zip not graph.zip)

    Try adding that WHITENESS line right at the start fo drawing a graph and see if it helps.
    Last edited by novacain; 02-21-2002 at 10:09 PM.
    "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

  5. #5
    Registered User
    Join Date
    Dec 2001
    Posts
    29

    Post

    K.. I think i've got it covered now.

    See, the image was fine besides for it starting out black.. so like you said, I now just fill it white when its created.. and then the problem is pretty much gone.

    I guess I just assumed the image would automatically be white or transparent.

    Thanks for the help.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. C or C++
    By AcerN30 in forum Game Programming
    Replies: 41
    Last Post: 05-30-2008, 06:57 PM
  2. WM_CAPTION causing CreateWindowEx() to fail.
    By Necrofear in forum Windows Programming
    Replies: 8
    Last Post: 04-06-2007, 08:23 AM
  3. 6 measly errors
    By beene in forum Game Programming
    Replies: 11
    Last Post: 11-14-2006, 11:06 AM
  4. OpenGL Window
    By Morgul in forum Game Programming
    Replies: 1
    Last Post: 05-15-2005, 12:34 PM
  5. opengl code not working
    By Unregistered in forum Windows Programming
    Replies: 4
    Last Post: 02-14-2002, 10:01 PM