You create two bitmaps of the same size and bitdepth
one holds the active/visible frame
one holds the new frame you're working on
your OnPaint only blits the invalidated rect from the visible bitmap to the screen.
When your new frame is finished, you flip the pointers/handles to the 2 bitmaps so the "new frame" becomes the visible frame, and the previously visible frame now becomes the new frame bitmap you'll be working on.
Invalidate the entire screen, OnPaint will do the rest
Repeat above 3 steps until whatever end condition is reached.
Hi,
Thanks for your guidance. Sorry I am following the previous approach given in the link which says:
To get rid of the flickering, handle WM_ERASEBKGND and just return TRUE in it.
To get rid of the black, you need to paint the entire memory DC in the color you want before starting to paint your road etc. You can use FillRect for this.
I have added WM_ERASEBKGND. It has removed the flickering but the black color is there as mentioned in that post and the grey color window is also created which slowly engulfs the entire screen.
I dont know how to paint the entire memory DC???
Kindly guide me what should i do.
You should use the codes like the following:
CDC dc;
dc.CreateCompatibleDC(pDC);
CBitmap bmpMem;
bmpMem.CreateCompatibleBitmap(pDC, rectClient.Width(), rectClient.Height());
CBitmap* pBmpOld = dc.SelectObject(&bmpMem);
The parameter for SetTextColor() is of type COLORREF and specifies the colour of the text as an RGB colour value. If the compiler is complaining that 'm_crInActiveTabText' is an undeclared identifer, then you need to determine what colour the text here is required to be set and use that value.
All advice is offered in good faith only. All my code is tested (unless stated explicitly otherwise) with the latest version of Microsoft Visual Studio (using the supported features of the latest standard) and is offered as examples only - not as production quality. I cannot offer advice regarding any other c/c++ compiler/IDE or incompatibilities with VS. You are ultimately responsible for the effects of your programs and the integrity of the machines they run on. Anything I post, code snippets, advice, etc is licensed as Public Domain https://creativecommons.org/publicdomain/zero/1.0/ and can be used without reference or acknowledgement. Also note that I only provide advice and guidance via the forums - and not via private messages!
However I dont have a one line code for filling. There are actually functions and not rectangle and intead they are polygons so i have called these functions
Despite of these changes my program output is exactly same as it was before (output attached). I am still getting the grey window which covers my actual output and i dont want this.
Plz solve this problem. Thanks for your time and guidance.
Hi,
Thanks. I have got solution for my problem: http://social.msdn.microsoft.com/For...orum=vcgeneral
It was same as suggested by Mr. andytim but i was not able to find out that i was doing the double buffereing inside the stationary_car method also.
My altered code (i.e ::OnDraw(...) and stationary_car(...) method) is now:
* The Best Reasons to Target Windows 8
Learn some of the best reasons why you should seriously consider bringing your Android mobile development expertise to bear on the Windows 8 platform.