Problems with BitBlt

This is a discussion on Problems with BitBlt within the Windows Programming forums, part of the Platform Specific Boards category; I'm trying to make a program with a framebuffer but Im having problems with BitBlt. Its giving me very wierd ...

  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,600
    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:
    if( numeric_limits< byte >::digits != bits_per_byte )
        error( "program requires bits_per_byte-bit bytes" );
    24bbs.cpp

  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,855
    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 08: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, 05:35 AM
  3. String Manipulation problems -_-
    By Astra in forum C Programming
    Replies: 5
    Last Post: 12-13-2006, 04: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, 03:35 PM

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