My application has a start dialog box with an image that fills the entire dialog. In addition, there is a CStatic control that displays some variable information for the user. I made a transparent CStatic using the following code:
HBRUSH CStartbildDlg::OnCtlColor(CDC* pDC, CWnd* pWnd, UINT nCtlColor) { if(pWnd->GetDlgCtrlID() == IDC_STATIC_INFO) { pDC->SetBkMode(TRANSPARENT); return reinterpret_cast<HBRUSH>(::GetStockObject(NULL_BRUSH)); } else return CDialog::OnCtlColor(pDC, pWnd, nCtlColor); }
When I change the text of a static control using GetDlgItem(IDC_STATIC_INFO)->SetWindowText , the new text overlaps the old text (the old text is not deleted). I tried to redraw the background to call the SetWindowText image using GetDlgItem(IDC_STATIC_BILD)->Invalidate() , but then the info text is displayed (neither old nor new).
Do you know how I can make static control transparent so that I can also override it with new text?
Thank you for your help!
Solution: Method 2 (adapted) from Sanja's codeproject-link worked for me.
GetDlgItem(IDC_STATIC_INFO)->SetWindowText(tmp); CRect rect; GetDlgItem(IDC_STATIC_INFO)->GetWindowRect(&rect); ScreenToClient(&rect); InvalidateRect(&rect); UpdateWindow();
source share