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:confused:
Any help would be most appreciated
Are clientWidth and clientHeight global variables or declared static?
You may have to post more code, your BitBlt() looks ok.
They're Global. What code should I post?WM_PAINT or one of the drawing functions?
>What code should I post?
Anything that may be causing it :) .
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);
PatBlt(memhdc, width, height, PATCOPY);
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?
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.
NOTE: HDC_1 is never drawn to the screen.
GetUpdateRect(hWnd, &theRect, 0);