Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 297
  • Last Modified:

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);
}
0
cophi
Asked:
cophi
  • 4
  • 4
1 Solution
 
AndyAinscowCommented:
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
 
AndyAinscowCommented:
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
 
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
Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
AndyAinscowCommented:
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
 
AndyAinscowCommented:
To refund put a question into community support with a link to this question asking for a PAQ/refund.
0
 
GranModCommented:
Closed, 500 points refunded.
GranMod
The Experts Exchange
Community Support Moderator of all Ages
0

Featured Post

Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

  • 4
  • 4
Tackle projects and never again get stuck behind a technical roadblock.
Join Now