This time I am trying to develop some little app. which is able to work a little with images mainly BMP format.
I would like to avoid the annoying flashing the client rect while it is being redrawn when I for eg. move a bitmap.
InvalidateRect(hWnd, NULL, TRUE);
hDC = BeginPaint(hWnd, &ps);
BitBlt(hDC, 0, 0, 640, 480, hOffScreenDC, 0, 0, SRCCOPY);
I saw a programme which used the BitBlt() and it worked without any problem... Mine code does not work, can you tell me why? The code is not correct is it?
It looks like you are redrawing it every time - that will make it flash.
InvalidateRect() generates a WM_PAINT msg.
BeginPaint() gets the invalid rect and HDC ect. It also makes the rect 'valid'.
EndPaint() will clean up the DC, no need to ReleaseDC() it.
The paint struct contains a RECT you can use to limit the area redrawn (will speed up the paint).
Look at WM_ERASEBKGND (IIRC return non zero to show you have processed the msg and do ot want the background redrawn again). This will reduce flicker.
So you can not call InvalidateRect() in a WM_PAINT (it will do nothing or create an infinte loop).
When you want a paint (in response to some other message) use
InvalidateRect()//set invalid rect, generate WM_PAINT msg
UpdateWindow()//post WM_PAINT msg directly to the window/dialog callback (not OS message queue).
So I modified a bit my previous code and it started to work...
Of course this code does not come from only one function but the base of the redrawing is hidden in this code...
hOffScreenDC = CreateCompatibleDC(GetDC(hWnd));
hOffScreenBitmap = CreateCompatibleBitmap(GetDC(hWnd), x, y);
HDC hDC = GetDC(hWnd);
BitBlt(hDC, 0, 0, x y, hOffScreenDC, 0, 0, SRCCOPY);
Even thou thx for help