Click here to Skip to main content
15,899,754 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Sir,

I had text data which I display on the window. Now I want to avoid the flickering of that data. I tried with the memory device context even though I am not able to avoid the flickering. Here is my sample code for it. If anyone can find a solution, please help me.
C++
CDC m_pDC;
m_bitmap.SetBitmapBits(R2_WHITE,RGB(0,0,0));
GetClientRect(&rect);
m_pDC.CreateCompatibleDC(&dc);
m_bitmap.CreateBitmap (rect.Width(), rect.Height(),0,0,NULL);
m_pDC.SelectObject(&m_bitmap);
m_pDc.TextOut((1 - m_nHScrollBarPos) * m_cxChar , i * m_cyChar, szFormatted);
m_bitmap.DeleteObject();
    dc.BitBlt(rect.left,rect.top,rect.Width(),rect.Height(),&m_pDC,rect.left,rect.top,SRCCOPY);
::ReleaseDC(m_hWnd, m_pDC.GetSafeHdc());

Thank you,
sarfaraz
Posted
Updated 6-Feb-11 20:20pm
v2

you need to silence the WM_ERASEBKGND[^] message by handling it and simply returning FALSE.

This paints over everything, which is the cause of your flickering.

Then you need to actually erase the background in your WM_PAINT (or equivalent message for your control) as part of the memory DC. (This would simply be FillRect()[^] with a brush of white or whatever colour (perhaps COLOR_BTNFACE))
 
Share this answer
 
Comments
JF2015 7-Feb-11 3:48am    
Very good advice!
Indivara 7-Feb-11 4:19am    
Reply from OP
"Thank you Andrew, I got it now..."
 
Share this answer
 
Comments
Sergey Alexandrovich Kryukov 7-Feb-11 2:42am    
If it is about double buffering, it should help (I voted "5").
There are two points to it: 1) double buffering; 2) partial invalidation (GDI has regions that support all set-theory primitive operations, so one can calculate which part of picture to invalidate). Do you have something on regions and invalidation? I used to do it (in native), but now it's too long reach for me...
--SA
Indivara 7-Feb-11 4:22am    
Thanks Sergey, that was what it was.
Sorry, haven't got anything at hand, not my region of expertise, I only know the basic stuff...
Sergey Alexandrovich Kryukov 7-Feb-11 21:20pm    
I see. I always avoided MFC stuff and still think I was right.
--SA

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900