Thread: Problems with BitBlt

  1. #1
    Registered User
    Join Date
    Nov 2001
    Posts
    202

    Problems with BitBlt

    I'm trying to make a program with a framebuffer but Im having problems with BitBlt. Its giving me very wierd displays.
    It is just meant to copy the memhdc over hdc and draw hdc but its giving me various displays depending on the amount of calls to it.

    1 call: works correctly except redaws over entire window not just client area.

    2 call: tries to fit entire desktop into client area

    3 call:redraws entire window into client area

    4 call: same as 2

    5 call: works fine

    This is not the only set of calls I get but this is the most common and most sets include the same things only in different order. This is my BitBlt call:
    BitBlt(hdc, 0, 0, clientWidth, clientHeight, memhdc, 0, 0, SRCCOPY) ;

    clientWidth and clientHeight is initilized in WM_CREATE to the height and width of the Client area respectivly.
    Also if I have the window in the background it doesnt re-paint as seemingly random part of my window

    Any help would be most appreciated

    Sincerly,
    Isometric
    "Christ died for our sins. Dare we make his martyrdom meaningless by not committing them?"

  2. #2
    S­énior Member
    Join Date
    Jan 2002
    Posts
    982
    Are clientWidth and clientHeight global variables or declared static?

    You may have to post more code, your BitBlt() looks ok.

  3. #3
    Registered User
    Join Date
    Nov 2001
    Posts
    202
    They're Global. What code should I post?WM_PAINT or one of the drawing functions?
    "Christ died for our sins. Dare we make his martyrdom meaningless by not committing them?"

  4. #4
    S­énior Member
    Join Date
    Jan 2002
    Posts
    982
    >What code should I post?

    Anything that may be causing it .

  5. #5
    Guest Sebastiani's Avatar
    Join Date
    Aug 2001
    Location
    Waterloo, Texas
    Posts
    5,708
    Well how are you loading memhdc?

    Should go somethin like:

    hdc = GetDC(hwnd);

    //ENCAPSULATE THE BELOW IN A FUNCTION...

    memhdc = CreateCompatibleDC(hdc);
    hbit = CreateCompatibleBitmap(hdc, width, height);
    hbrush = GetStockObject(WHITE_BRUSH);
    SelectObject(memhdc, hbrush);
    SelectObject(memhdc, hbit);
    PatBlt(memhdc, width, height, PATCOPY);
    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;
    }

  6. #6
    Registered User
    Join Date
    Nov 2001
    Posts
    202
    acturally all I was doing was creating a compatible hdc before anything was written but I'll try it your way. I assume I should call the function before every BitBlt correct?
    "Christ died for our sins. Dare we make his martyrdom meaningless by not committing them?"

  7. #7
    train spotter
    Join Date
    Aug 2001
    Location
    near a computer
    Posts
    3,868
    On Init (WM_CREATE or WM_INIT)
    Get the DC of the screen
    Create two compatible HDC's incl BMP's (make them the same) Use the function above
    Paint them white

    When you need to draw; (HDC_1)
    Clear hdc (paint it white)
    Do all drawing
    When finished BitBlt (HDC_1 -> HDC_2)
    Call for a paint msg

    In paint (response to WM_PAINT msg)
    BitBlt (HDC_2 -> hdc from BeginPaint() )


    Use this in the paint function BEFORE the call to BeginPaint(). This MUST be done before BeginPaint() valiates the update rect.
    Code:
    	GetUpdateRect(hWnd, &theRect, 0);
    	if (IsRectEmpty(&theRect))
    	{
    		GetClientRect(hWnd,&theRect);
    	}
    NOTE: HDC_1 is never drawn to the screen.
    Last edited by novacain; 02-05-2002 at 09:23 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

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. No clue how to make a code to solve problems!
    By ctnzn in forum C Programming
    Replies: 8
    Last Post: 10-16-2008, 02:59 AM
  2. C Pointers Problems
    By mhelal in forum C Programming
    Replies: 8
    Last Post: 01-10-2007, 06:35 AM
  3. String Manipulation problems -_-
    By Astra in forum C Programming
    Replies: 5
    Last Post: 12-13-2006, 05:48 PM
  4. Rendering problems (DirectX?)
    By OnionKnight in forum Tech Board
    Replies: 0
    Last Post: 08-17-2006, 12:17 PM
  5. DJGPP problems
    By stormswift in forum C Programming
    Replies: 2
    Last Post: 02-26-2002, 04:35 PM