farbe von static-feld
-
vielleicht bin ich auch nur zu doof, aber:
wie kann ich die farbe von nem textcontrol feld einstellen (ich hätts gern weiß, nicht schwarz)
-
Versuchs so:
if(pWnd->GetDlgCtrlID() == ID_DEINES_STATIC_FELD) { pDC->SetTextColor(RGB(255,255,255)); }
In die OnCtlColor
Gruß
:: NoName ::
-
hmmm, wenn ich die parent funktion aufrufe gibts den fehler: error C2248: 'CWnd::OnCtlColor': Kein Zugriff auf protected Element, dessen Deklaration in der Klasse "CWnd" erfolgte
der quellcode ist
afx_msg HBRUSH OnCtlColor(CDC* pDC, CWnd* pWnd, UINT nCtlColor) { HBRUSH hbr = CDialog::OnCtlColor(pDC, pWnd, nCtlColor); if(pWnd->GetDlgCtrlID() == IDC_STATIC_DIALOUT) { pDC->SetTextColor(RGB(255,255,255)); } return hbr; }
-
Die Funktion muss Member der Dialogklasse sein!
-
jo, danke. war aber auch schon spät ...
trotzdem gehts nicht. er tut einfach nix. bitte um hilfe.
-
Eine Checkliste:
- Hast du ON_WM_CTLCOLOR in deiner Message-Map?
- Ist es wirklich eine Static-Kontrolle?
- Hat sie wirklich die ID IDC_STATIC_DIALOUT?
-
probiers mal so:
ChildHandle->GetDlgItem(IDC_STATIC); StaticHandle->RedrawWindow(); dc = StaticHandle->GetDC(); StaticHandle->GetClientRect(rect); CBrush* lbrush = new CBrush; lbrush->CreateSolidBrush(RGB(255,255,255)); dc->SelectObject(&lbrush); dc->FillRect(rect, lbrush);
dabei gelten folgende deklarationen:
CWnd* MainHandle, *ChildHandle, *StaticHandle; CDC* dc;
so klappts bei mir zumindest.
-
@Uwe P...
danke, aber: Ja, Ja, Ja
sieht gut aus, aber wo bekomme ich die ganzen handles her? ich hab doch nur den dialog
-
oje, sorry.
@uwe
ist doch keine static kontrolle. ich hab ganz vergessen, dass ich das ding als CTransparentStatic genommen hab (hab ich mir irgendwo ausm internet geholt). ich hab das jetzt wieder rückgängig gemacht und jetzt ist die schrift weiß. nur der hintergrund ist jetzt halt nicht mehr transparent. gibts da eine lösung?
-
Setz mal in der WM_CTLCOLOR folgendes:
pDC->SetBkMode(TRANSPARENT);
Gruß
:: NoName ::P.S. Keine Ahnung obs funktioniert ...
-
geht leider nicht
-
Dann erweitere doch die CTransparentStatic-Klasse so, dass sie den Text auch weiß darstellen kann!
-
Genau, super Idee ! Poste mal den Code der Klasse CTransparentStatic !
Gruß
:: NoName ::
-
oje, da merkt man wieder, das ich totaler anfänger bin. ich hab mal wieder keine ahnung.
Poste mal den Code der Klasse CTransparentStatic !
// TransparentStatic.cpp : implementation file // #include "stdafx.h" //#include "TransparentStaticTest.h" #include "TransparentStatic.h" // CTransparentStatic IMPLEMENT_DYNAMIC(CTransparentStatic, CStatic) CTransparentStatic::CTransparentStatic() { } CTransparentStatic::~CTransparentStatic() { } BEGIN_MESSAGE_MAP(CTransparentStatic, CStatic) ON_WM_PAINT() END_MESSAGE_MAP() // CTransparentStatic message handlers void CTransparentStatic::OnPaint() { CPaintDC dc(this); // device context for painting // Where to draw text CRect client_rect; GetClientRect(client_rect); // Get the caption CString szText; GetWindowText(szText); // Get the font CFont *pFont, *pOldFont; pFont = GetFont(); pOldFont = dc.SelectObject(pFont); // Map "Static Styles" to "Text Styles" #define MAP_STYLE(src, dest) if(dwStyle & (src)) dwText |= (dest) #define NMAP_STYLE(src, dest) if(!(dwStyle & (src))) dwText |= (dest) DWORD dwStyle = GetStyle(), dwText = 0; MAP_STYLE( SS_RIGHT, DT_RIGHT ); MAP_STYLE( SS_CENTER, DT_CENTER ); MAP_STYLE( SS_CENTERIMAGE, DT_VCENTER | DT_SINGLELINE ); MAP_STYLE( SS_NOPREFIX, DT_NOPREFIX ); MAP_STYLE( SS_WORDELLIPSIS, DT_WORD_ELLIPSIS ); MAP_STYLE( SS_ENDELLIPSIS, DT_END_ELLIPSIS ); MAP_STYLE( SS_PATHELLIPSIS, DT_PATH_ELLIPSIS ); NMAP_STYLE( SS_LEFTNOWORDWRAP | SS_CENTERIMAGE | SS_WORDELLIPSIS | SS_ENDELLIPSIS | SS_PATHELLIPSIS, DT_WORDBREAK ); // Set transparent background dc.SetBkMode(TRANSPARENT); // Draw the text dc.DrawText(szText, client_rect, dwText); // Select old font dc.SelectObject(pOldFont); }
-
Also,
soweit ich das überblicken kann, müsstest du eigentlich nur dc.SetTextColor(RGB(255,255,255)); am Ende des Quellcodes setzen :
// Set transparent background dc.SetBkMode(TRANSPARENT); dc.SetTextColor(RGB(255,255,255)); // Draw the text dc.DrawText(szText, client_rect, dwText); // Select old font dc.SelectObject(pOldFont);
Teste mal...
-
hey super. danke