OnCtlColor
-
Hi Jochen, danke das funktioniert. Allerdings wird meine Combobox
nicht mit der neuen Farbe überzeichnet.Hier mal der ganze Code aus der OnCtlColor:
HBRUSH hbr = CDialog::OnCtlColor(pDC, pWnd, nCtlColor); if(nCtlColor == CTLCOLOR_EDIT) { if(farbe=="1") { if (pWnd->GetDlgCtrlID() == IDC_EDIT1) { pDC->SetTextColor(RGB(0,51,255)); } if (pWnd->GetDlgCtrlID() == IDC_EDIT2) { pDC->SetTextColor(RGB(0,51,255)); } }else { if (pWnd->GetDlgCtrlID() == IDC_EDIT1) { pDC->SetTextColor(RGB(204,0,51)); } if (pWnd->GetDlgCtrlID() == IDC_EDIT2) { pDC->SetTextColor(RGB(204,0,51)); } } } if(nCtlColor == CTLCOLOR_LISTBOX) { if(farbe=="1") { if (pWnd->GetDlgCtrlID() == IDC_COMBO1) { pDC->SetTextColor(RGB(0,51,255)); } if (pWnd->GetDlgCtrlID() == IDC_COMBO2) { pDC->SetTextColor(RGB(0,51,255)); } if (pWnd->GetDlgCtrlID() == IDC_COMBO3) { pDC->SetTextColor(RGB(0,51,255)); } if (pWnd->GetDlgCtrlID() == IDC_COMBO4) { pDC->SetTextColor(RGB(0,51,255)); } }else { if (pWnd->GetDlgCtrlID() == IDC_COMBO1) { pDC->SetTextColor(RGB(204,0,51)); } if (pWnd->GetDlgCtrlID() == IDC_COMBO2) { pDC->SetTextColor(RGB(204,0,51)); } if (pWnd->GetDlgCtrlID() == IDC_COMBO3) { pDC->SetTextColor(RGB(204,0,51)); } if (pWnd->GetDlgCtrlID() == IDC_COMBO4) { pDC->SetTextColor(RGB(204,0,51)); } } } return hbr;
-
Ist denn CTLCOLOR_LISTBOX überhaupt richtig bei ner ComboBox?
-
Ja! Eine ComboBox versendet zwei Arten von CtlColor Nachricten. Einmal für das Edit-Control und einmal für das List-Control.
-
Hi Martin,
dann frag ich mich, warum sich bei mir der Text in der Combo farblich nicht
verändert. Ich starte den Aufruf überGetDlgItem(IDC_COMBO1)->Invalidate(1);
-
Edit: Antwort gelöscht, weil irreleant... sorry!
-
Hi Martin,
leider auch ohne die "1" keine Veränderung. Meine Comboboxen werden textmäßig
nicht eingefärbt.
-
Sry, aber ich habe es noch nicht zum laufen gebracht. *push*
In der Hoffnung jemand von euch kann helfen.
-
Martin Richter schrieb:
Ja! Eine ComboBox versendet zwei Arten von CtlColor Nachricten. Einmal für das Edit-Control und einmal für das List-Control.
Ich meine mich düster zu erinnern, daß die beiden Teile ihre eigenen IDs bekommen.
@Shark: Kannst du mal mit TRACE verfolgen, für welche Controls es aufgerufen wird?
PS: Was ich in der MSDN gefunden habe, könnte auch weiterhelfen:
OnCtlColor will not be called for the list box of a drop-down combo box because the drop-down list box is actually a child of the combo box and not a child of the window. To change the color of the drop-down list box, create a CComboBox with an override of OnCtlColor that checks for CTLCOLOR_LISTBOX in the nCtlColor parameter. In this handler, the SetBkColor member function must be used to set the background color for the text.
-
Hi CStoll,
wenn ich es richtig verstanden habe soll ich es also so versuchen:
if(nCtlColor == CTLCOLOR_LISTBOX) { pDC->SetBkColor(RGB(204,0,51)); }Auch hier gibts leider keine Veränderung. TRACE prüfe ich gleich mal...
-
Nein! Du musst eine eigene CComboBox Klasse erzeugen die OnCtlColor behandelt und diese musst Du für den subclass verwenden.
-
Wobei mir subclassen noch etwas fremd ist...Gibt's dazu hier ein kleines
Tutorial?