Cześć, mam dziwny problem. Napisałem sobie przeźroczystego labela w MFC, który dodatkowo ma opcję zawijania wiersza, jeśli tekst jest za długi. I teraz jest taka sytuacja, że jak zmieniam tekst w jednym labelu, to wszystko śmiga pięknie. A jak w dwóch innych, to tekst się nie odświeża i labele pozostają puste. Dopiero jeśli wykonam na nich operacje ShowWindow(SW_HIDE) i ShowWindow(SW_SHOW) (czyli po prostu ukryję i pokażę), to tekst jest widoczny.

Oto istotne części labela:

 BEGIN_MESSAGE_MAP(CLiteStatic, CStatic)
	ON_WM_CTLCOLOR_REFLECT()
	ON_MESSAGE(WM_SETTEXT, &CLiteStatic::OnSetText)
	ON_WM_ERASEBKGND()
END_MESSAGE_MAP()

void CLiteStatic::PreSubclassWindow()
{
	CStatic::PreSubclassWindow();
	assert(m_hWnd != NULL);

//muszę zapamiętać domyślne style, bo potem je zmieniam
	m_styles = GetWindowLong(m_hWnd, GWL_STYLE);
	m_exStyles = GetWindowLong(m_hWnd, GWL_EXSTYLE);
}

afx_msg LRESULT CLiteStatic::OnSetText(WPARAM wParam, LPARAM lParam)
{
	if(m_isWrapable) //to jest pole, które mówi o tym, czy tekst ma się zawijać (domyślnie true)
	{
		CString str = (LPWSTR)lParam;

//pozbywam się enterów, bo zawijam po długości stringa, a nie po enterach - takie założenie
		int c = str.Replace(L"\r\n", L" ");
		c += str.Replace(L'\n', L' ');
		c += str.Replace(L'\r', L' ');
		if(c > 0)
		{
			SetWindowText(str);
			return TRUE;
		}


		//check if text fits in the label
		CRect thisRect;
		GetWindowRect(&thisRect);

		//calculate text rect

		Gdiplus::Font f(GetDC()->GetSafeHdc(), (HFONT)GetFont()->GetSafeHandle());
		Gdiplus::RectF resultRect;
		Gdiplus::Graphics g(GetDC()->GetSafeHdc());			
		g.MeasureString((LPCWSTR)str, (INT)str.GetLength(), &f, Gdiplus::PointF(0, 0), &resultRect);


		if((int)std::ceilf(resultRect.Width) > thisRect.Width())
		{
			//text is wider than label, so make label wrapable
			LONG currStyles = GetWindowLong(m_hWnd, GWL_STYLE);
			currStyles &= ~SS_CENTERIMAGE;
			currStyles &= ~SS_ENDELLIPSIS;
			currStyles &= ~SS_LEFTNOWORDWRAP;
			currStyles &= ~SS_PATHELLIPSIS;
			currStyles &= ~SS_SIMPLE;
			currStyles &= ~SS_WORDELLIPSIS;

			SetWindowLong(m_hWnd, GWL_STYLE, currStyles);
		} else
			SetWindowLong(m_hWnd, GWL_STYLE, m_styles);
	} else
		SetWindowLong(m_hWnd, GWL_STYLE, m_styles);
	
	LRESULT Result = Default();

	Invalidate();
	UpdateWindow();
	return Result;
}

//przeźroczystość
afx_msg HBRUSH CLiteStatic::CtlColor(CDC* pDC, UINT nCtlColor)
{
	pDC->SetBkMode(TRANSPARENT);
	return (HBRUSH)GetStockObject(NULL_BRUSH);
}

BOOL CLiteStatic::OnEraseBkgnd(CDC* pDC)
{
	if (m_bmp.GetSafeHandle() == NULL)
	{
		CRect Rect;
		GetWindowRect(&Rect);
		CWnd *pParent = GetParent();
		ASSERT(pParent);
		pParent->ScreenToClient(&Rect);    //convert our co-ordinates
		//to our parents

		//copy what's on the parents at this point
		CDC *pParentDC = pParent->GetDC();
		CDC MemDC;
		MemDC.CreateCompatibleDC(pParentDC);
		m_bmp.CreateCompatibleBitmap(pParentDC,Rect.Width(),Rect.Height());
		CBitmap *pOldBmp = MemDC.SelectObject(&m_bmp);

		MemDC.BitBlt(0,0,Rect.Width(),Rect.Height(),pParentDC,Rect.left,
			Rect.top,SRCCOPY);

		MemDC.SelectObject(pOldBmp);

		pParent->ReleaseDC(pParentDC);
	}
	else    //copy what we copied off the parent the first time
		//back onto the parent
	{
		CRect Rect;
		GetClientRect(Rect);
		CDC MemDC;
		MemDC.CreateCompatibleDC(pDC);
		CBitmap *pOldBmp = MemDC.SelectObject(&m_bmp);
		pDC->BitBlt(0,0,Rect.Width(),Rect.Height(),&MemDC,0,0,SRCCOPY);
		MemDC.SelectObject(pOldBmp);
	}
	return TRUE;
}

Tekst na takim labelu ustawiam normalnie:

 m_static.SetWindowText("Siema");

Ktoś ma jakiś pomysł dlaczego tak się dzieje?