<?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[Probleme mit subclassing von button -&amp;gt; repaint funktioniert nicht]]></title><description><![CDATA[<p>Moin,</p>
<p>ich habe den nachfolgenden Code und nachfolgendes Problem:</p>
<p>Ich subclasse einen Button. Kein Problem. Wenn ich jetzt aber versuche, ein Bitmap draufzumalen, erschein... nichts. Weiß (Hintergrundfarbe). Sobald ich auf den Button klicke (da wo er sein sollte) wird ein grau Umrandeter Radio-punkt angezeigt. Aber nicht der Rest.</p>
<p>Jetzt natürlich meine Frage: Warum? Wo liegt das Problem? Was amche ich falsch?</p>
<p>Schonmal viel Spaß( <img
      src="https://www.c-plusplus.net/forum/plugins/nodebb-plugin-emoji/emoji/emoji-one/1f603.png?v=ab1pehoraso"
      class="not-responsive emoji emoji-emoji-one emoji--grinning_face_with_big_eyes"
      title=":D"
      alt="😃"
    /> ), euer ItsNotYou</p>
<pre><code class="language-cpp">LRESULT CALLBACK WndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam)
{
	static HANDLE hSeite = 0;
	static HDC hDCSeite = 0;

	static HWND hButton1;
	static HWND hButton2;

	switch(message)
	{
	case WM_CREATE:
		{
			hDCSeite = CreateCompatibleDC(0);

			hSeite = LoadImage(GetModuleHandle(NULL), &quot;seite.bmp&quot;, IMAGE_BITMAP, 0, 0, LR_DEFAULTCOLOR | LR_LOADFROMFILE);

			SelectObject(hDCSeite, hSeite);

			hButton1 = CreateWindow(&quot;button&quot;, &quot;test1&quot;, WS_CHILD | WS_VISIBLE | WS_GROUP | WS_TABSTOP | BS_AUTORADIOBUTTON, 10, 10, 100, 100, hWnd, NULL, ((LPCREATESTRUCT)lParam)-&gt;hInstance, NULL);
			hButton2 = CreateWindow(&quot;button&quot;, &quot;test2&quot;, WS_CHILD | WS_VISIBLE | /*WS_GROUP |*/ BS_AUTORADIOBUTTON, 10, 110, 100, 100, hWnd, NULL, ((LPCREATESTRUCT)lParam)-&gt;hInstance, NULL);

			PrevWndProcButton = SetWindowLongPtr(hButton1, GWLP_WNDPROC, (LONG_PTR)ButtonProc);

			return(0);
		}
	case WM_PAINT:
		{
			PAINTSTRUCT ps;
			BeginPaint(hWnd, &amp;ps);
			{
				RECT rect;
				GetClientRect(hWnd, &amp;rect);

				for(int count = 0; count &lt; rect.bottom; count++)
				{
					BitBlt(ps.hdc, 0, count, 10, 1, hDCSeite, 0, 0, SRCCOPY);
				}
			}
			EndPaint(hWnd, &amp;ps);

			return(0);
		}
	case WM_DESTROY:
		{
			SetWindowLongPtr(hButton1, GWLP_WNDPROC, PrevWndProcButton);
			PostQuitMessage(0);
			return(0);
		}
	}

	return DefWindowProc(hWnd, message, wParam, lParam);
}

//---------------------------------------------------------

LRESULT CALLBACK ButtonProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam)
{
	static HANDLE hSeite = 0;
	static HDC hDCSeite = 0;

	switch(message)
	{
	case WM_CREATE:
		{
			hDCSeite = CreateCompatibleDC(0);

			hSeite = LoadImage(GetModuleHandle(NULL), &quot;back.bmp&quot;, IMAGE_BITMAP, 0, 0, LR_DEFAULTCOLOR | LR_LOADFROMFILE);

			SelectObject(hDCSeite, hSeite);

			break;
		}
	case WM_PAINT:
		{
			PAINTSTRUCT ps;

			BeginPaint(hWnd, &amp;ps);
			{
				BitBlt(ps.hdc, 0, 0, 100, 100, hDCSeite, 0, 0, SRCCOPY);
			}
			EndPaint(hWnd, &amp;ps);

			break;
		}
	}

	return CallWindowProc((WNDPROC)PrevWndProcButton, hWnd, message, wParam, lParam);
}
</code></pre>
]]></description><link>https://www.c-plusplus.net/forum/topic/123766/probleme-mit-subclassing-von-button-gt-repaint-funktioniert-nicht</link><generator>RSS for Node</generator><lastBuildDate>Tue, 07 Jul 2026 01:14:06 GMT</lastBuildDate><atom:link href="https://www.c-plusplus.net/forum/topic/123766.rss" rel="self" type="application/rss+xml"/><pubDate>Wed, 19 Oct 2005 18:26:03 GMT</pubDate><ttl>60</ttl><item><title><![CDATA[Reply to Probleme mit subclassing von button -&amp;gt; repaint funktioniert nicht on Wed, 19 Oct 2005 18:26:03 GMT]]></title><description><![CDATA[<p>Moin,</p>
<p>ich habe den nachfolgenden Code und nachfolgendes Problem:</p>
<p>Ich subclasse einen Button. Kein Problem. Wenn ich jetzt aber versuche, ein Bitmap draufzumalen, erschein... nichts. Weiß (Hintergrundfarbe). Sobald ich auf den Button klicke (da wo er sein sollte) wird ein grau Umrandeter Radio-punkt angezeigt. Aber nicht der Rest.</p>
<p>Jetzt natürlich meine Frage: Warum? Wo liegt das Problem? Was amche ich falsch?</p>
<p>Schonmal viel Spaß( <img
      src="https://www.c-plusplus.net/forum/plugins/nodebb-plugin-emoji/emoji/emoji-one/1f603.png?v=ab1pehoraso"
      class="not-responsive emoji emoji-emoji-one emoji--grinning_face_with_big_eyes"
      title=":D"
      alt="😃"
    /> ), euer ItsNotYou</p>
<pre><code class="language-cpp">LRESULT CALLBACK WndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam)
{
	static HANDLE hSeite = 0;
	static HDC hDCSeite = 0;

	static HWND hButton1;
	static HWND hButton2;

	switch(message)
	{
	case WM_CREATE:
		{
			hDCSeite = CreateCompatibleDC(0);

			hSeite = LoadImage(GetModuleHandle(NULL), &quot;seite.bmp&quot;, IMAGE_BITMAP, 0, 0, LR_DEFAULTCOLOR | LR_LOADFROMFILE);

			SelectObject(hDCSeite, hSeite);

			hButton1 = CreateWindow(&quot;button&quot;, &quot;test1&quot;, WS_CHILD | WS_VISIBLE | WS_GROUP | WS_TABSTOP | BS_AUTORADIOBUTTON, 10, 10, 100, 100, hWnd, NULL, ((LPCREATESTRUCT)lParam)-&gt;hInstance, NULL);
			hButton2 = CreateWindow(&quot;button&quot;, &quot;test2&quot;, WS_CHILD | WS_VISIBLE | /*WS_GROUP |*/ BS_AUTORADIOBUTTON, 10, 110, 100, 100, hWnd, NULL, ((LPCREATESTRUCT)lParam)-&gt;hInstance, NULL);

			PrevWndProcButton = SetWindowLongPtr(hButton1, GWLP_WNDPROC, (LONG_PTR)ButtonProc);

			return(0);
		}
	case WM_PAINT:
		{
			PAINTSTRUCT ps;
			BeginPaint(hWnd, &amp;ps);
			{
				RECT rect;
				GetClientRect(hWnd, &amp;rect);

				for(int count = 0; count &lt; rect.bottom; count++)
				{
					BitBlt(ps.hdc, 0, count, 10, 1, hDCSeite, 0, 0, SRCCOPY);
				}
			}
			EndPaint(hWnd, &amp;ps);

			return(0);
		}
	case WM_DESTROY:
		{
			SetWindowLongPtr(hButton1, GWLP_WNDPROC, PrevWndProcButton);
			PostQuitMessage(0);
			return(0);
		}
	}

	return DefWindowProc(hWnd, message, wParam, lParam);
}

//---------------------------------------------------------

LRESULT CALLBACK ButtonProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam)
{
	static HANDLE hSeite = 0;
	static HDC hDCSeite = 0;

	switch(message)
	{
	case WM_CREATE:
		{
			hDCSeite = CreateCompatibleDC(0);

			hSeite = LoadImage(GetModuleHandle(NULL), &quot;back.bmp&quot;, IMAGE_BITMAP, 0, 0, LR_DEFAULTCOLOR | LR_LOADFROMFILE);

			SelectObject(hDCSeite, hSeite);

			break;
		}
	case WM_PAINT:
		{
			PAINTSTRUCT ps;

			BeginPaint(hWnd, &amp;ps);
			{
				BitBlt(ps.hdc, 0, 0, 100, 100, hDCSeite, 0, 0, SRCCOPY);
			}
			EndPaint(hWnd, &amp;ps);

			break;
		}
	}

	return CallWindowProc((WNDPROC)PrevWndProcButton, hWnd, message, wParam, lParam);
}
</code></pre>
]]></description><link>https://www.c-plusplus.net/forum/post/896455</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/896455</guid><dc:creator><![CDATA[ItsNotYou]]></dc:creator><pubDate>Wed, 19 Oct 2005 18:26:03 GMT</pubDate></item><item><title><![CDATA[Reply to Probleme mit subclassing von button -&amp;gt; repaint funktioniert nicht on Wed, 19 Oct 2005 22:30:08 GMT]]></title><description><![CDATA[<p>Wenn die alte Fensterprozedur WM_PAINT verarbeitet ruft sie nochmal Begin-/EndPaint auf <img
      src="https://www.c-plusplus.net/forum/plugins/nodebb-plugin-emoji/emoji/emoji-one/1f644.png?v=ab1pehoraso"
      class="not-responsive emoji emoji-emoji-one emoji--face_with_rolling_eyes"
      title=":rolling_eyes:"
      alt="🙄"
    /></p>
]]></description><link>https://www.c-plusplus.net/forum/post/896635</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/896635</guid><dc:creator><![CDATA[D*niel *chumann]]></dc:creator><pubDate>Wed, 19 Oct 2005 22:30:08 GMT</pubDate></item><item><title><![CDATA[Reply to Probleme mit subclassing von button -&amp;gt; repaint funktioniert nicht on Thu, 20 Oct 2005 14:23:56 GMT]]></title><description><![CDATA[<p>und das sorgt wofür? dafür das der button nicht gezeichnet wird?</p>
]]></description><link>https://www.c-plusplus.net/forum/post/896865</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/896865</guid><dc:creator><![CDATA[ItsNotYou]]></dc:creator><pubDate>Thu, 20 Oct 2005 14:23:56 GMT</pubDate></item><item><title><![CDATA[Reply to Probleme mit subclassing von button -&amp;gt; repaint funktioniert nicht on Thu, 20 Oct 2005 14:29:45 GMT]]></title><description><![CDATA[<p>Nein, daß der von dir frisch gezeichnete Inhalt wieder überpinselt wird <img
      src="https://www.c-plusplus.net/forum/plugins/nodebb-plugin-emoji/emoji/emoji-one/1f609.png?v=ab1pehoraso"
      class="not-responsive emoji emoji-emoji-one emoji--winking_face"
      title=";)"
      alt="😉"
    /> Wenn du etwas selber komplett erledigt hast, brauchst du nicht mehr auf die Standardimplementierung zurückgreifen.</p>
]]></description><link>https://www.c-plusplus.net/forum/post/896873</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/896873</guid><dc:creator><![CDATA[CStoll]]></dc:creator><pubDate>Thu, 20 Oct 2005 14:29:45 GMT</pubDate></item><item><title><![CDATA[Reply to Probleme mit subclassing von button -&amp;gt; repaint funktioniert nicht on Thu, 20 Oct 2005 14:36:10 GMT]]></title><description><![CDATA[<p>was sollte ich stattdessen machen? das bitmap soll aufn button, (ziemlich) egal wie</p>
]]></description><link>https://www.c-plusplus.net/forum/post/896882</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/896882</guid><dc:creator><![CDATA[ItsNotYou]]></dc:creator><pubDate>Thu, 20 Oct 2005 14:36:10 GMT</pubDate></item><item><title><![CDATA[Reply to Probleme mit subclassing von button -&amp;gt; repaint funktioniert nicht on Thu, 20 Oct 2005 14:45:10 GMT]]></title><description><![CDATA[<p>bau dir doch deine ButtonProc so auf wie die WndProc:</p>
<pre><code class="language-cpp">case WM_PAINT:
  //... Button zeichnen
  return 0;
</code></pre>
<p>In dem Block steht alles drin, was dein Programm zum Zeichnen wissen muß, damit ist die Nachrichtenbehandlung fertig.</p>
<p>(eventuell müsstest du den Rückgabewert noch anpassen - aber da kann dir die WinAPI-Doku eher weiterhelfen)</p>
]]></description><link>https://www.c-plusplus.net/forum/post/896886</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/896886</guid><dc:creator><![CDATA[CStoll]]></dc:creator><pubDate>Thu, 20 Oct 2005 14:45:10 GMT</pubDate></item><item><title><![CDATA[Reply to Probleme mit subclassing von button -&amp;gt; repaint funktioniert nicht on Thu, 20 Oct 2005 15:10:38 GMT]]></title><description><![CDATA[<p>im sourcecode kann man sehen, dass wndproc u. buttonproc gleich aufgebaut sind, allerdings tritt dann das oben beschriebene problem auf. lasse ich das beginpaint weg, erscheint zwar der button komplett, aber ohne bitmap</p>
]]></description><link>https://www.c-plusplus.net/forum/post/896911</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/896911</guid><dc:creator><![CDATA[ItsNotYou]]></dc:creator><pubDate>Thu, 20 Oct 2005 15:10:38 GMT</pubDate></item><item><title><![CDATA[Reply to Probleme mit subclassing von button -&amp;gt; repaint funktioniert nicht on Thu, 20 Oct 2005 15:20:24 GMT]]></title><description><![CDATA[<p>das Problem ist eben, daß sie NICHT komplett gleich aufgebaut sind:</p>
<pre><code class="language-cpp">// etwas vereinfacht:
WndProc(...)
{
  switch(message)
  {
  case WM_xxx:
    // handle Message xxx
    return 0; // verlässt die Funktion
  case WM_yyy:
    // handle Message yyy
    return 0;
  //...
  }
  return DefWindowProc(...); // nur aufgerufen, wenn keiner der case... aktiv wurde
}

ButtonProc(...)
{
  switch(message)
  {
  case WM_xxx:
    // handle Message xxx
    break; // verlässt nicht die Funktion, sondern nur den switch()
  //...
  }
  return CallWindowProc(...); // in jedem Fall nach deiner Nachrichtenbehandlung aufgerufen
}
</code></pre>
]]></description><link>https://www.c-plusplus.net/forum/post/896920</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/896920</guid><dc:creator><![CDATA[CStoll]]></dc:creator><pubDate>Thu, 20 Oct 2005 15:20:24 GMT</pubDate></item><item><title><![CDATA[Reply to Probleme mit subclassing von button -&amp;gt; repaint funktioniert nicht on Thu, 20 Oct 2005 15:38:26 GMT]]></title><description><![CDATA[<p>das heißt, ich sollte bei einem button die WM_PAINT-Nachricht VOLLKOMMEN alleine übernehmen... Achso...</p>
<p>ok, ich probiers</p>
]]></description><link>https://www.c-plusplus.net/forum/post/896939</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/896939</guid><dc:creator><![CDATA[ItsNotYou]]></dc:creator><pubDate>Thu, 20 Oct 2005 15:38:26 GMT</pubDate></item><item><title><![CDATA[Reply to Probleme mit subclassing von button -&amp;gt; repaint funktioniert nicht on Thu, 20 Oct 2005 15:43:41 GMT]]></title><description><![CDATA[<p>ich habe jetzt den fehler gefunden! die WM_CREATE-nachricht wird nicht aufgerufen (warum auch immer), ich habe die sachen aus der wm_create einfach beim ersten aufruf der wm_paint machen lass -&gt; geht</p>
<p>danke für eure hilfe, auch wenn der fehler letztlich woanders lag</p>
]]></description><link>https://www.c-plusplus.net/forum/post/896947</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/896947</guid><dc:creator><![CDATA[ItsNotYou]]></dc:creator><pubDate>Thu, 20 Oct 2005 15:43:41 GMT</pubDate></item><item><title><![CDATA[Reply to Probleme mit subclassing von button -&amp;gt; repaint funktioniert nicht on Sat, 22 Oct 2005 12:03:59 GMT]]></title><description><![CDATA[<p>Naja, das ist so nicht richtig.<br />
Das WM_CREATE wird auch bei den Buttons aufgerufen, nur landen diese Aufrufe nicht in Deiner eigenen WndProc, was aber ganz einfach daran liegt, dass Du die WndProc ja erst nach dem Aufruf von CreateWindow (also nach dem Erstellen) änderst.</p>
]]></description><link>https://www.c-plusplus.net/forum/post/898624</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/898624</guid><dc:creator><![CDATA[mantiz]]></dc:creator><pubDate>Sat, 22 Oct 2005 12:03:59 GMT</pubDate></item><item><title><![CDATA[Reply to Probleme mit subclassing von button -&amp;gt; repaint funktioniert nicht on Sat, 22 Oct 2005 13:17:16 GMT]]></title><description><![CDATA[<p>ok wie auch immer, ich weiß jetzt wo mein fehler lag.</p>
<p>danke für die hilfe,</p>
<p>euer ItsNotYou</p>
]]></description><link>https://www.c-plusplus.net/forum/post/898683</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/898683</guid><dc:creator><![CDATA[ItsNotYou]]></dc:creator><pubDate>Sat, 22 Oct 2005 13:17:16 GMT</pubDate></item></channel></rss>