Flicker free window for ticker

Hi,

I have a custom activex that is basically a ticker(i.e. news ticker)  But the word's keep flashing on the screen.  Anyway to prevent this?

void CTickerAtxCtrl::OnDraw(
                  CDC* pdc, const CRect& rcBounds, const CRect& rcInvalid)
{

      CFont *tFont = new CFont();
      tFont->CreateFont(36, 0, 0, 0, FW_NORMAL, FALSE, FALSE, FALSE, 0, OUT_DEFAULT_PRECIS, CLIP_DEFAULT_PRECIS, DEFAULT_QUALITY, DEFAULT_PITCH | FF_ROMAN, "Times New Roman");

      CFont* pOldFont = (CFont*)pdc->SelectObject(tFont);

      if (m_bNeedToInitRenderer == true) {
            
            m_textLenInPixels = pdc->GetTextExtent(m_ticker).cx;
            m_xPosOfText = rcBounds.right;
            width = rcBounds.right;

            m_bNeedToInitRenderer = false;
      }
      if (m_bCtrlResized == true) {
            Reset();
            m_bCtrlResized = false;
      }

      CRect r = rcBounds;

      if (m_textLenInPixels + m_xPosOfText == 0) {
            Reset();
      }

      r.left = m_xPosOfText--;
      pdc->SetBkColor(white);
      pdc->FillSolidRect(rcBounds, white);
      pdc->SetTextColor(black);
      pdc->DrawText(m_ticker, -1, r, DT_SINGLELINE | DT_VCENTER);

      pdc->SelectObject(pOldFont);
}
cophiAsked:
Who is Participating?
 
GranModCommented:
Closed, 500 points refunded.
GranMod
The Experts Exchange
Community Support Moderator of all Ages
0
 
AndyAinscowFreelance programmer / ConsultantCommented:
One thing that can help is to stop the default  background painting.
Trap the WM_ERASEBKGND and in the stub just return true.
eg.
BOOL CMyWnd::OnEraseBkgnd(CDC* pDC)
{
return TRUE;
}


NOTE - you must repaint the complete control in the OnDraw function
eg.
void CTickerAtxCtrl::OnDraw(
               CDC* pdc, const CRect& rcBounds, const CRect& rcInvalid)
{
CRect rc;
GetClientRect(&rc);
pdc->FillSolidRect(&rc, RGB(255, 0, 0));   <<----------insert colour you want here
0
 
AndyAinscowFreelance programmer / ConsultantCommented:
Why - Windows does drawing in two stages.  First the background then the foreground.  Between the two *could* be a delay - hence the flicker.  Returning true from the WM_ERASEBKGND message handler stops windows doing the first step, you are instructing the OP system that you will do it yourself / have done it yourself.
0
Cloud Class® Course: Microsoft Windows 7 Basic

This introductory course to Windows 7 environment will teach you about working with the Windows operating system. You will learn about basic functions including start menu; the desktop; managing files, folders, and libraries.

 
cophiAuthor Commented:
The text is still flashing....

I captured EraseBkgnd and I am passing back True.  

I am not doing

>>NOTE - you must repaint the complete control in the OnDraw function
>>eg.
>>void CTickerAtxCtrl::OnDraw(
>>               CDC* pdc, const CRect& rcBounds, const CRect& rcInvalid)
>>{
>>CRect rc;
>>GetClientRect(&rc);
>>pdc->FillSolidRect(&rc, RGB(255, 0, 0));   <<----------insert colour you want here

because I assumed my code already took care of that

     pdc->SetBkColor(white);
     pdc->FillSolidRect(rcBounds, white);
     pdc->SetTextColor(black);
     pdc->DrawText(m_ticker, -1, r, DT_SINGLELINE | DT_VCENTER);
0
 
AndyAinscowFreelance programmer / ConsultantCommented:
This will reduce the flashing.  
If you are calling OnDraw 10 times per second it will flash just because of that - make certain you only call OnDraw when you do need to change the display.
0
 
cophiAuthor Commented:
Well since its a ticker... yeah its changing probably 10 times per second, but  I just thought there might be a way to eliminate the flashing.  
0
 
cophiAuthor Commented:
I was able to get rid of flashing by using the following code in the Timer event, incase anyone else out there is trying to create a ticker control/app.

            CPoint ptScroll;
            ptScroll.x = -1;
            ptScroll.y = 0;

            CDC* pDC = GetDC();
            LPtoDP(pDC->m_hDC, &ptScroll, 1);
            pDC->DPtoLP(&ptScroll, 1);
            ReleaseDC(pDC);

            ScrollWindow(ptScroll.x, ptScroll.y, m_rcBounds, m_rcBounds);
0
 
cophiAuthor Commented:
Could I have my pts refunded since I solved it myself.  Thanks!
0
 
AndyAinscowFreelance programmer / ConsultantCommented:
To refund put a question into community support with a link to this question asking for a PAQ/refund.
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.