Win32 CStatusBar pane flicker problem

drjackool 956 Reputation points
2021-03-10T09:56:10.193+00:00

Hi
I update a CStatusBar pane inside a loop using SetPaneText() method and set update flag to TRUE but the text is flickers! also i called UpdateWindow() and RedrawWindow() after SetPaneText but problem so exist!

I also return TRUE on erase background but following happens:
76583-image-2021-03-11-081135.png
Thanks

C++
C++
A high-level, general-purpose programming language, created as an extension of the C programming language, that has object-oriented, generic, and functional features in addition to facilities for low-level memory manipulation.
3,537 questions
{count} votes

2 answers

Sort by: Most helpful
  1. Lorin Geisendorfer 6 Reputation points
    2021-03-22T14:35:51.25+00:00

    This is common problem with CStatusBar the trick is to SetBkMode(TRANSPARENT) a custom draw class example

    void CStatusBarTreeEx::DrawItem(LPDRAWITEMSTRUCT lpDrawItemStruct)
    {
    AFX_STATUSPANE* pPane = GetTreePane(lpDrawItemStruct->itemID);

    if(pPane) 
    {   
        // now draw the text if required
        if(!pPane->strText.IsEmpty())
        {
            CDC dc;
            CRect rect;
            int oldBkMode;
            COLORREF oldTextColor;
    
            UINT nFormat = DT_LEFT|DT_SINGLELINE|DT_EXPANDTABS|DT_NOPREFIX|DT_VCENTER;  
            rect = lpDrawItemStruct->rcItem;
            dc.Attach(lpDrawItemStruct->hDC);
    
            oldTextColor = dc.SetTextColor(theApp.m_clrThemeBtnText);
            oldBkMode    = dc.SetBkMode(TRANSPARENT); 
    
            dc.DrawText(pPane->strText, pPane->strText.GetLength(), rect, nFormat);
    
            dc.SetTextColor(oldTextColor);
            dc.SetBkMode(oldBkMode);
            dc.Detach();
        }
    }
    

    }

    1 person found this answer helpful.
    0 comments No comments

  2. SM 416 Reputation points
    2021-03-10T16:30:56.667+00:00

    Did you try handling WM_ERASEBKGND and return TRUE from your statusbar class?

    0 comments No comments