<?xml version="1.0" encoding="UTF-8"?><rss xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:atom="http://www.w3.org/2005/Atom" version="2.0"><channel><title><![CDATA[OnCtlColor]]></title><description><![CDATA[<p>Hi,</p>
<p>in einer Anwendung würde ich gerne den Text in einem Editcontrol<br />
je nach gedrücktem Button andersfarbig darstellen lassen.</p>
<p>Mein Versuch klappte nur teilweise. Und zwar wird nur beim Start der<br />
Anwendung die Textfarbe beeinflusst. Nicht aber, wenn ich z.B. Button1<br />
drücke.</p>
<pre><code class="language-cpp">HBRUSH CTestDlg::OnCtlColor(CDC* pDC, CWnd* pWnd, UINT nCtlColor)
{

HBRUSH hbr = CDialog::OnCtlColor(pDC, pWnd, nCtlColor);
if(nCtlColor == CTLCOLOR_EDIT)
{
	if(farbe==&quot;1&quot;)//farbe ist ein CString
	{
		if (pWnd-&gt;GetDlgCtrlID() == IDC_EDIT2) 
		{
			pDC-&gt;SetTextColor(RGB(10,110,255));
		}
	}else
	{
		if (pWnd-&gt;GetDlgCtrlID() == IDC_EDIT2) 
		{

			pDC-&gt;SetTextColor(RGB(255,10,55));
		}
	}
}

return hbr;

}
</code></pre>
<p>In meinem Buttonaufruf setze ich einfach die Variable der Klasse (CString farbe) auf z.B.&quot;0&quot;.<br />
Die Textfarbe ändert sich aber leider nicht. OnCtlColor wird doch, wie ich gelesen habe nicht von mir aufgerufen oder?</p>
]]></description><link>https://www.c-plusplus.net/forum/topic/203303/onctlcolor</link><generator>RSS for Node</generator><lastBuildDate>Sun, 05 Apr 2026 18:57:25 GMT</lastBuildDate><atom:link href="https://www.c-plusplus.net/forum/topic/203303.rss" rel="self" type="application/rss+xml"/><pubDate>Mon, 21 Jan 2008 12:56:13 GMT</pubDate><ttl>60</ttl><item><title><![CDATA[Reply to OnCtlColor on Mon, 21 Jan 2008 12:56:13 GMT]]></title><description><![CDATA[<p>Hi,</p>
<p>in einer Anwendung würde ich gerne den Text in einem Editcontrol<br />
je nach gedrücktem Button andersfarbig darstellen lassen.</p>
<p>Mein Versuch klappte nur teilweise. Und zwar wird nur beim Start der<br />
Anwendung die Textfarbe beeinflusst. Nicht aber, wenn ich z.B. Button1<br />
drücke.</p>
<pre><code class="language-cpp">HBRUSH CTestDlg::OnCtlColor(CDC* pDC, CWnd* pWnd, UINT nCtlColor)
{

HBRUSH hbr = CDialog::OnCtlColor(pDC, pWnd, nCtlColor);
if(nCtlColor == CTLCOLOR_EDIT)
{
	if(farbe==&quot;1&quot;)//farbe ist ein CString
	{
		if (pWnd-&gt;GetDlgCtrlID() == IDC_EDIT2) 
		{
			pDC-&gt;SetTextColor(RGB(10,110,255));
		}
	}else
	{
		if (pWnd-&gt;GetDlgCtrlID() == IDC_EDIT2) 
		{

			pDC-&gt;SetTextColor(RGB(255,10,55));
		}
	}
}

return hbr;

}
</code></pre>
<p>In meinem Buttonaufruf setze ich einfach die Variable der Klasse (CString farbe) auf z.B.&quot;0&quot;.<br />
Die Textfarbe ändert sich aber leider nicht. OnCtlColor wird doch, wie ich gelesen habe nicht von mir aufgerufen oder?</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1440553</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1440553</guid><dc:creator><![CDATA[Sharkyx]]></dc:creator><pubDate>Mon, 21 Jan 2008 12:56:13 GMT</pubDate></item><item><title><![CDATA[Reply to OnCtlColor on Mon, 21 Jan 2008 13:07:54 GMT]]></title><description><![CDATA[<p>Hallo!</p>
<p>Wenn du einen Button drückst, wird kein OnPaint Event o.ä. für andere Fenster aufgerufen. Du musst dann deinem CEdit mitteilen, dass es sich neu zeichnen soll.</p>
<p>Könntest beispielsweise ein Invalidate an das CEdit schicken.</p>
<p>Gruß Jochen</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1440564</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1440564</guid><dc:creator><![CDATA[::Jochen]]></dc:creator><pubDate>Mon, 21 Jan 2008 13:07:54 GMT</pubDate></item><item><title><![CDATA[Reply to OnCtlColor on Mon, 21 Jan 2008 15:20:20 GMT]]></title><description><![CDATA[<p>Hi Jochen, danke das funktioniert. Allerdings wird meine Combobox<br />
nicht mit der neuen Farbe überzeichnet.</p>
<p>Hier mal der ganze Code aus der OnCtlColor:</p>
<pre><code class="language-cpp">HBRUSH hbr = CDialog::OnCtlColor(pDC, pWnd, nCtlColor);

if(nCtlColor == CTLCOLOR_EDIT)
{
	if(farbe==&quot;1&quot;)
	{
		if (pWnd-&gt;GetDlgCtrlID() == IDC_EDIT1) 
		{
			pDC-&gt;SetTextColor(RGB(0,51,255));
		}

		if (pWnd-&gt;GetDlgCtrlID() == IDC_EDIT2) 
		{
			pDC-&gt;SetTextColor(RGB(0,51,255));
		}

	}else
	{
		if (pWnd-&gt;GetDlgCtrlID() == IDC_EDIT1) 
		{
			pDC-&gt;SetTextColor(RGB(204,0,51));
		}
		if (pWnd-&gt;GetDlgCtrlID() == IDC_EDIT2) 
		{
			pDC-&gt;SetTextColor(RGB(204,0,51));
		}
	}
}

if(nCtlColor == CTLCOLOR_LISTBOX)
{

	if(farbe==&quot;1&quot;)
	{
		if (pWnd-&gt;GetDlgCtrlID() == IDC_COMBO1) 
		{
			pDC-&gt;SetTextColor(RGB(0,51,255));
		}

		if (pWnd-&gt;GetDlgCtrlID() == IDC_COMBO2) 
		{
			pDC-&gt;SetTextColor(RGB(0,51,255));
		}

		if (pWnd-&gt;GetDlgCtrlID() == IDC_COMBO3) 
		{
			pDC-&gt;SetTextColor(RGB(0,51,255));
		}

		if (pWnd-&gt;GetDlgCtrlID() == IDC_COMBO4) 
		{
			pDC-&gt;SetTextColor(RGB(0,51,255));
		}

	}else
	{
		if (pWnd-&gt;GetDlgCtrlID() == IDC_COMBO1) 
		{
			pDC-&gt;SetTextColor(RGB(204,0,51));
		}
		if (pWnd-&gt;GetDlgCtrlID() == IDC_COMBO2) 
		{
			pDC-&gt;SetTextColor(RGB(204,0,51));
		}

		if (pWnd-&gt;GetDlgCtrlID() == IDC_COMBO3) 
		{
			pDC-&gt;SetTextColor(RGB(204,0,51));
		}
		if (pWnd-&gt;GetDlgCtrlID() == IDC_COMBO4) 
		{
			pDC-&gt;SetTextColor(RGB(204,0,51));
		}

	}

}

return hbr;
</code></pre>
]]></description><link>https://www.c-plusplus.net/forum/post/1440696</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1440696</guid><dc:creator><![CDATA[Sharkyx]]></dc:creator><pubDate>Mon, 21 Jan 2008 15:20:20 GMT</pubDate></item><item><title><![CDATA[Reply to OnCtlColor on Mon, 21 Jan 2008 18:24:56 GMT]]></title><description><![CDATA[<p>Ist denn CTLCOLOR_LISTBOX überhaupt richtig bei ner ComboBox?</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1440839</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1440839</guid><dc:creator><![CDATA[xyungelöst]]></dc:creator><pubDate>Mon, 21 Jan 2008 18:24:56 GMT</pubDate></item><item><title><![CDATA[Reply to OnCtlColor on Tue, 22 Jan 2008 07:43:39 GMT]]></title><description><![CDATA[<p>Ja! Eine ComboBox versendet zwei Arten von CtlColor Nachricten. Einmal für das Edit-Control und einmal für das List-Control.</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1441056</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1441056</guid><dc:creator><![CDATA[Martin Richter]]></dc:creator><pubDate>Tue, 22 Jan 2008 07:43:39 GMT</pubDate></item><item><title><![CDATA[Reply to OnCtlColor on Tue, 22 Jan 2008 08:03:19 GMT]]></title><description><![CDATA[<p>Hi Martin,</p>
<p>dann frag ich mich, warum sich bei mir der Text in der Combo farblich nicht<br />
verändert. Ich starte den Aufruf über</p>
<pre><code class="language-cpp">GetDlgItem(IDC_COMBO1)-&gt;Invalidate(1);
</code></pre>
]]></description><link>https://www.c-plusplus.net/forum/post/1441069</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1441069</guid><dc:creator><![CDATA[Sharkyx]]></dc:creator><pubDate>Tue, 22 Jan 2008 08:03:19 GMT</pubDate></item><item><title><![CDATA[Reply to OnCtlColor on Tue, 22 Jan 2008 09:18:19 GMT]]></title><description><![CDATA[<p>Edit: Antwort gelöscht, weil irreleant... sorry!</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1441094</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1441094</guid><dc:creator><![CDATA[Martin Richter]]></dc:creator><pubDate>Tue, 22 Jan 2008 09:18:19 GMT</pubDate></item><item><title><![CDATA[Reply to OnCtlColor on Tue, 22 Jan 2008 09:23:52 GMT]]></title><description><![CDATA[<p>Hi Martin,</p>
<p>leider auch ohne die &quot;1&quot; keine Veränderung. Meine Comboboxen werden textmäßig<br />
nicht eingefärbt.</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1441100</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1441100</guid><dc:creator><![CDATA[Sharkyx]]></dc:creator><pubDate>Tue, 22 Jan 2008 09:23:52 GMT</pubDate></item><item><title><![CDATA[Reply to OnCtlColor on Thu, 24 Jan 2008 07:56:59 GMT]]></title><description><![CDATA[<p>Sry, aber ich habe es noch nicht zum laufen gebracht. *push*<br />
In der Hoffnung jemand von euch kann helfen.</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1442513</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1442513</guid><dc:creator><![CDATA[Sharkyx]]></dc:creator><pubDate>Thu, 24 Jan 2008 07:56:59 GMT</pubDate></item><item><title><![CDATA[Reply to OnCtlColor on Thu, 24 Jan 2008 08:14:29 GMT]]></title><description><![CDATA[<p>Martin Richter schrieb:</p>
<blockquote>
<p>Ja! Eine ComboBox versendet zwei Arten von CtlColor Nachricten. Einmal für das Edit-Control und einmal für das List-Control.</p>
</blockquote>
<p>Ich meine mich düster zu erinnern, daß die beiden Teile ihre eigenen IDs bekommen.</p>
<p>@Shark: Kannst du mal mit TRACE verfolgen, für welche Controls es aufgerufen wird?</p>
<p>PS: Was ich in der MSDN gefunden habe, könnte auch weiterhelfen:</p>
<blockquote>
<p>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.</p>
</blockquote>
]]></description><link>https://www.c-plusplus.net/forum/post/1442524</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1442524</guid><dc:creator><![CDATA[CStoll]]></dc:creator><pubDate>Thu, 24 Jan 2008 08:14:29 GMT</pubDate></item><item><title><![CDATA[Reply to OnCtlColor on Thu, 24 Jan 2008 10:14:43 GMT]]></title><description><![CDATA[<p>Hi CStoll,</p>
<p>wenn ich es richtig verstanden habe soll ich es also so versuchen:</p>
<pre><code class="language-cpp">if(nCtlColor == CTLCOLOR_LISTBOX)
{
pDC-&gt;SetBkColor(RGB(204,0,51)); 
}
</code></pre>
<p>Auch hier gibts leider keine Veränderung. TRACE prüfe ich gleich mal...</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1442609</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1442609</guid><dc:creator><![CDATA[Sharkyx]]></dc:creator><pubDate>Thu, 24 Jan 2008 10:14:43 GMT</pubDate></item><item><title><![CDATA[Reply to OnCtlColor on Thu, 24 Jan 2008 10:33:51 GMT]]></title><description><![CDATA[<p>Nein! Du musst eine eigene CComboBox Klasse erzeugen die OnCtlColor behandelt und diese musst Du für den subclass verwenden.</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1442623</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1442623</guid><dc:creator><![CDATA[Martin Richter]]></dc:creator><pubDate>Thu, 24 Jan 2008 10:33:51 GMT</pubDate></item><item><title><![CDATA[Reply to OnCtlColor on Thu, 24 Jan 2008 11:02:12 GMT]]></title><description><![CDATA[<p>Wobei mir subclassen noch etwas fremd ist...Gibt's dazu hier ein kleines<br />
Tutorial?</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1442645</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1442645</guid><dc:creator><![CDATA[Sharkyx]]></dc:creator><pubDate>Thu, 24 Jan 2008 11:02:12 GMT</pubDate></item></channel></rss>