<?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[DrawTransparentBitmap]]></title><description><![CDATA[<p>Hi,</p>
<p>ich hab den Code hier mal hier im Forum gesehen:</p>
<pre><code class="language-cpp">void DrawTransparentBitmap(HDC hdc, HBITMAP hBitmap, short xStart, short yStart, COLORREF cTransparentColor)
{
	BITMAP     bm;
	COLORREF   cColor;
	HBITMAP    bmAndBack, bmAndObject, bmAndMem, bmSave;
	HBITMAP    bmBackOld, bmObjectOld, bmMemOld, bmSaveOld;
	HDC        hdcMem, hdcBack, hdcObject, hdcTemp, hdcSave;
	POINT      ptSize;

	hdcTemp = CreateCompatibleDC(hdc);
	SelectObject(hdcTemp, hBitmap);   // Select the bitmap

	GetObject(hBitmap, sizeof(BITMAP), (LPSTR)&amp;bm);
	ptSize.x = bm.bmWidth;        // Get width of bitmap
	ptSize.y = bm.bmHeight;       // Get height of bitmap
	DPtoLP(hdcTemp, &amp;ptSize, 1);  // Convert from device
							// to logical points

	// Create some DCs to hold temporary data.
	hdcBack   = CreateCompatibleDC(hdc);
	hdcObject = CreateCompatibleDC(hdc);
	hdcMem    = CreateCompatibleDC(hdc);
	hdcSave   = CreateCompatibleDC(hdc);

	// Create a bitmap for each DC. DCs are required for a number of
	// GDI functions.

	// Monochrome DC
	bmAndBack   = CreateBitmap(ptSize.x, ptSize.y, 1, 1, NULL);

	// Monochrome DC
	bmAndObject = CreateBitmap(ptSize.x, ptSize.y, 1, 1, NULL);

	bmAndMem    = CreateCompatibleBitmap(hdc, ptSize.x, ptSize.y);
	bmSave      = CreateCompatibleBitmap(hdc, ptSize.x, ptSize.y);

	// Each DC must select a bitmap object to store pixel data.
	bmBackOld   = static_cast&lt;HBITMAP&gt;(SelectObject(hdcBack, bmAndBack));
	bmObjectOld = static_cast&lt;HBITMAP&gt;(SelectObject(hdcObject, bmAndObject));
	bmMemOld    = static_cast&lt;HBITMAP&gt;(SelectObject(hdcMem, bmAndMem));
	bmSaveOld   = static_cast&lt;HBITMAP&gt;(SelectObject(hdcSave, bmSave));

	// Set proper mapping mode.
	SetMapMode(hdcTemp, GetMapMode(hdc));

	// Save the bitmap sent here, because it will be overwritten.
	BitBlt(hdcSave, 0, 0, ptSize.x, ptSize.y, hdcTemp, 0, 0, SRCCOPY);

	// Set the background color of the source DC to the color.
	// contained in the parts of the bitmap that should be transparent
	cColor = SetBkColor(hdcTemp, cTransparentColor);

	// Create the object mask for the bitmap by performing a BitBlt
	// from the source bitmap to a monochrome bitmap.
	BitBlt(hdcObject, 0, 0, ptSize.x, ptSize.y, hdcTemp, 0, 0,
		SRCCOPY);

	// Set the background color of the source DC back to the original
	// color.
	SetBkColor(hdcTemp, cColor);

	// Create the inverse of the object mask.
	BitBlt(hdcBack, 0, 0, ptSize.x, ptSize.y, hdcObject, 0, 0,
		NOTSRCCOPY);

	// Copy the background of the main DC to the destination.
	BitBlt(hdcMem, 0, 0, ptSize.x, ptSize.y, hdc, xStart, yStart,
		SRCCOPY);

	// Mask out the places where the bitmap will be placed.
	BitBlt(hdcMem, 0, 0, ptSize.x, ptSize.y, hdcObject, 0, 0, SRCAND);

	// Mask out the transparent colored pixels on the bitmap.
	BitBlt(hdcTemp, 0, 0, ptSize.x, ptSize.y, hdcBack, 0, 0, SRCAND);

	// XOR the bitmap with the background on the destination DC.
	BitBlt(hdcMem, 0, 0, ptSize.x, ptSize.y, hdcTemp, 0, 0, SRCPAINT);

	// Copy the destination to the screen.
	BitBlt(hdc, xStart, yStart, ptSize.x, ptSize.y, hdcMem, 0, 0,
		SRCCOPY);

	// Place the original bitmap back into the bitmap sent here.
	BitBlt(hdcTemp, 0, 0, ptSize.x, ptSize.y, hdcSave, 0, 0, SRCCOPY);

	// Delete the memory bitmaps.
	DeleteObject(SelectObject(hdcBack, bmBackOld));
	DeleteObject(SelectObject(hdcObject, bmObjectOld));
	DeleteObject(SelectObject(hdcMem, bmMemOld));
	DeleteObject(SelectObject(hdcSave, bmSaveOld));

	// Delete the memory DCs.
	DeleteDC(hdcMem);
	DeleteDC(hdcBack);
	DeleteDC(hdcObject);
	DeleteDC(hdcSave);
	DeleteDC(hdcTemp);
}
</code></pre>
<p>leider werden bei mir nur schwarze Rechtecke gezeichnet!!! <img
      src="https://www.c-plusplus.net/forum/plugins/nodebb-plugin-emoji/emoji/emoji-one/1f61e.png?v=ab1pehoraso"
      class="not-responsive emoji emoji-emoji-one emoji--disappointed_face"
      title="=("
      alt="😞"
    /></p>
<p>Muss ich noch was machen ausser die Funktion aufrufen?</p>
]]></description><link>https://www.c-plusplus.net/forum/topic/80044/drawtransparentbitmap</link><generator>RSS for Node</generator><lastBuildDate>Mon, 13 Apr 2026 08:17:37 GMT</lastBuildDate><atom:link href="https://www.c-plusplus.net/forum/topic/80044.rss" rel="self" type="application/rss+xml"/><pubDate>Fri, 16 Jul 2004 14:39:33 GMT</pubDate><ttl>60</ttl><item><title><![CDATA[Reply to DrawTransparentBitmap on Fri, 16 Jul 2004 14:39:33 GMT]]></title><description><![CDATA[<p>Hi,</p>
<p>ich hab den Code hier mal hier im Forum gesehen:</p>
<pre><code class="language-cpp">void DrawTransparentBitmap(HDC hdc, HBITMAP hBitmap, short xStart, short yStart, COLORREF cTransparentColor)
{
	BITMAP     bm;
	COLORREF   cColor;
	HBITMAP    bmAndBack, bmAndObject, bmAndMem, bmSave;
	HBITMAP    bmBackOld, bmObjectOld, bmMemOld, bmSaveOld;
	HDC        hdcMem, hdcBack, hdcObject, hdcTemp, hdcSave;
	POINT      ptSize;

	hdcTemp = CreateCompatibleDC(hdc);
	SelectObject(hdcTemp, hBitmap);   // Select the bitmap

	GetObject(hBitmap, sizeof(BITMAP), (LPSTR)&amp;bm);
	ptSize.x = bm.bmWidth;        // Get width of bitmap
	ptSize.y = bm.bmHeight;       // Get height of bitmap
	DPtoLP(hdcTemp, &amp;ptSize, 1);  // Convert from device
							// to logical points

	// Create some DCs to hold temporary data.
	hdcBack   = CreateCompatibleDC(hdc);
	hdcObject = CreateCompatibleDC(hdc);
	hdcMem    = CreateCompatibleDC(hdc);
	hdcSave   = CreateCompatibleDC(hdc);

	// Create a bitmap for each DC. DCs are required for a number of
	// GDI functions.

	// Monochrome DC
	bmAndBack   = CreateBitmap(ptSize.x, ptSize.y, 1, 1, NULL);

	// Monochrome DC
	bmAndObject = CreateBitmap(ptSize.x, ptSize.y, 1, 1, NULL);

	bmAndMem    = CreateCompatibleBitmap(hdc, ptSize.x, ptSize.y);
	bmSave      = CreateCompatibleBitmap(hdc, ptSize.x, ptSize.y);

	// Each DC must select a bitmap object to store pixel data.
	bmBackOld   = static_cast&lt;HBITMAP&gt;(SelectObject(hdcBack, bmAndBack));
	bmObjectOld = static_cast&lt;HBITMAP&gt;(SelectObject(hdcObject, bmAndObject));
	bmMemOld    = static_cast&lt;HBITMAP&gt;(SelectObject(hdcMem, bmAndMem));
	bmSaveOld   = static_cast&lt;HBITMAP&gt;(SelectObject(hdcSave, bmSave));

	// Set proper mapping mode.
	SetMapMode(hdcTemp, GetMapMode(hdc));

	// Save the bitmap sent here, because it will be overwritten.
	BitBlt(hdcSave, 0, 0, ptSize.x, ptSize.y, hdcTemp, 0, 0, SRCCOPY);

	// Set the background color of the source DC to the color.
	// contained in the parts of the bitmap that should be transparent
	cColor = SetBkColor(hdcTemp, cTransparentColor);

	// Create the object mask for the bitmap by performing a BitBlt
	// from the source bitmap to a monochrome bitmap.
	BitBlt(hdcObject, 0, 0, ptSize.x, ptSize.y, hdcTemp, 0, 0,
		SRCCOPY);

	// Set the background color of the source DC back to the original
	// color.
	SetBkColor(hdcTemp, cColor);

	// Create the inverse of the object mask.
	BitBlt(hdcBack, 0, 0, ptSize.x, ptSize.y, hdcObject, 0, 0,
		NOTSRCCOPY);

	// Copy the background of the main DC to the destination.
	BitBlt(hdcMem, 0, 0, ptSize.x, ptSize.y, hdc, xStart, yStart,
		SRCCOPY);

	// Mask out the places where the bitmap will be placed.
	BitBlt(hdcMem, 0, 0, ptSize.x, ptSize.y, hdcObject, 0, 0, SRCAND);

	// Mask out the transparent colored pixels on the bitmap.
	BitBlt(hdcTemp, 0, 0, ptSize.x, ptSize.y, hdcBack, 0, 0, SRCAND);

	// XOR the bitmap with the background on the destination DC.
	BitBlt(hdcMem, 0, 0, ptSize.x, ptSize.y, hdcTemp, 0, 0, SRCPAINT);

	// Copy the destination to the screen.
	BitBlt(hdc, xStart, yStart, ptSize.x, ptSize.y, hdcMem, 0, 0,
		SRCCOPY);

	// Place the original bitmap back into the bitmap sent here.
	BitBlt(hdcTemp, 0, 0, ptSize.x, ptSize.y, hdcSave, 0, 0, SRCCOPY);

	// Delete the memory bitmaps.
	DeleteObject(SelectObject(hdcBack, bmBackOld));
	DeleteObject(SelectObject(hdcObject, bmObjectOld));
	DeleteObject(SelectObject(hdcMem, bmMemOld));
	DeleteObject(SelectObject(hdcSave, bmSaveOld));

	// Delete the memory DCs.
	DeleteDC(hdcMem);
	DeleteDC(hdcBack);
	DeleteDC(hdcObject);
	DeleteDC(hdcSave);
	DeleteDC(hdcTemp);
}
</code></pre>
<p>leider werden bei mir nur schwarze Rechtecke gezeichnet!!! <img
      src="https://www.c-plusplus.net/forum/plugins/nodebb-plugin-emoji/emoji/emoji-one/1f61e.png?v=ab1pehoraso"
      class="not-responsive emoji emoji-emoji-one emoji--disappointed_face"
      title="=("
      alt="😞"
    /></p>
<p>Muss ich noch was machen ausser die Funktion aufrufen?</p>
]]></description><link>https://www.c-plusplus.net/forum/post/562249</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/562249</guid><dc:creator><![CDATA[Der_Knob]]></dc:creator><pubDate>Fri, 16 Jul 2004 14:39:33 GMT</pubDate></item><item><title><![CDATA[Reply to DrawTransparentBitmap on Fri, 16 Jul 2004 16:38:55 GMT]]></title><description><![CDATA[<p>Ich habe mir den Code jetzt nicht genauers angeschaut, aber wie rufst du die Funktion auf? Und hast du mal die verschiedenen Rückgabewerte kontrolliert?</p>
]]></description><link>https://www.c-plusplus.net/forum/post/562330</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/562330</guid><dc:creator><![CDATA[flenders]]></dc:creator><pubDate>Fri, 16 Jul 2004 16:38:55 GMT</pubDate></item><item><title><![CDATA[Reply to DrawTransparentBitmap on Sat, 17 Jul 2004 17:31:22 GMT]]></title><description><![CDATA[<p>alos alle werte sind gefühlt... keiner davon ist NULL oder so ...</p>
]]></description><link>https://www.c-plusplus.net/forum/post/562808</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/562808</guid><dc:creator><![CDATA[Der_Knob]]></dc:creator><pubDate>Sat, 17 Jul 2004 17:31:22 GMT</pubDate></item><item><title><![CDATA[Reply to DrawTransparentBitmap on Mon, 19 Jul 2004 13:22:07 GMT]]></title><description><![CDATA[<p>wie meinst du das mit aufrufen?</p>
<p>Hab ne Klasse dafür... und die Werte sind beim Aufruf der Funktion gefüllt...</p>
]]></description><link>https://www.c-plusplus.net/forum/post/563730</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/563730</guid><dc:creator><![CDATA[Der_Knob]]></dc:creator><pubDate>Mon, 19 Jul 2004 13:22:07 GMT</pubDate></item><item><title><![CDATA[Reply to DrawTransparentBitmap on Mon, 19 Jul 2004 17:49:28 GMT]]></title><description><![CDATA[<p>Was genau übergibst du der Funktion? Zeig doch mal den Code, wie du das Ganze eingebunden hast <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/563948</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/563948</guid><dc:creator><![CDATA[flenders]]></dc:creator><pubDate>Mon, 19 Jul 2004 17:49:28 GMT</pubDate></item><item><title><![CDATA[Reply to DrawTransparentBitmap on Tue, 20 Jul 2004 20:36:08 GMT]]></title><description><![CDATA[<p>ok, das ist nicht ganz so einfach... ich hab das in classen gebaut:<br />
Hier mal nur der &quot;wichtige&quot; teil</p>
<pre><code class="language-cpp">class CGButton
{
private:
	HDC				hdcButton;
	HWND				hwnd;
	HBITMAP			hBitmap;
	HINSTANCE			hInstance;

	[...]
public:
	CGButton(HWND HWnd, HINSTANCE HInstance, int iWM_MessageCode, int PICTURE_1, int iXPosition, int iYPosition, int iHeight, int iWidth);
	~CGButton();
	void			SetButtonPics(int PICTURE);

	void			PaintButton();
	void			PaintButton(HDC hdc);
	[...]
};

//****SetButtonPics()****//
//Zum setzen der Bilder und zum ändern der Position und Größe
void CGButton::SetButtonPics(int PICTURE)
{
	HDC		hdc;

	hdc = GetDC(hwnd);

	hBitmap = (HBITMAP)LoadImage(hInstance,MAKEINTRESOURCE(PICTURE),IMAGE_BITMAP,0,0,LR_CREATEDIBSECTION);

	hdcButton = CreateCompatibleDC(hdc);
	SelectObject(hdcButton, hBitmap);

	DeleteObject(hBitmap);
	ReleaseDC(hwnd,hdc);
}

//****PaintButton()****//
//Zum Zeichnen des Buttons
void CGButton::PaintButton(HDC hdc)
{
	if (Visible == TRUE)
	{
		DrawTransparentBitmap(hdc, hBitmap, sSize.XPosition, sSize.YPosition, Color);
		if (PaintStatus == BUTTON_2)
		{
			HPEN		hPen, hOldPen;

			hPen = CreatePen (PS_SOLID, 1, GetSysColor(COLOR_APPWORKSPACE));
			hOldPen = (HPEN) SelectObject(hdc, hPen);

			MoveToEx(hdc,sSize.XPosition, sSize.YPosition, NULL);
			LineTo(hdc, sSize.XPosition + sSize.Width - 1, sSize.YPosition);
			LineTo(hdc, sSize.XPosition + sSize.Width - 1, sSize.YPosition + sSize.Height  - 1);
			LineTo(hdc, sSize.XPosition, sSize.YPosition + sSize.Height  - 1);
			LineTo(hdc, sSize.XPosition, sSize.YPosition);

			DeleteObject(SelectObject(hdc, hOldPen));
		}
	}
}

//****PaintButton()****//
//Zum Zeichnen des Buttons
void CGButton::PaintButton()
{
	HDC		hdc;

	if (Visible == TRUE)
	{
		hdc = GetDC(hwnd);
		PaintButton(hdc);
		ReleaseDC(hwnd,hdc);
	}
}
</code></pre>
]]></description><link>https://www.c-plusplus.net/forum/post/564749</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/564749</guid><dc:creator><![CDATA[Der_Knob]]></dc:creator><pubDate>Tue, 20 Jul 2004 20:36:08 GMT</pubDate></item><item><title><![CDATA[Reply to DrawTransparentBitmap on Wed, 21 Jul 2004 14:30:02 GMT]]></title><description><![CDATA[<p>Lösche keine Objekte, die in einen Geräte-Kontext eingesetzt sind!<br />
(Man hört sich das auf deutsch scheiße an)</p>
]]></description><link>https://www.c-plusplus.net/forum/post/565277</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/565277</guid><dc:creator><![CDATA[D*niel *chumann]]></dc:creator><pubDate>Wed, 21 Jul 2004 14:30:02 GMT</pubDate></item><item><title><![CDATA[Reply to DrawTransparentBitmap on Wed, 21 Jul 2004 14:51:48 GMT]]></title><description><![CDATA[<p>du meinst:</p>
<p>DeleteObject(hBitmap);</p>
<p>=&gt; stimmt das passt nicht. ich probier das mal aus, dann meld ich mich nochmal</p>
]]></description><link>https://www.c-plusplus.net/forum/post/565289</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/565289</guid><dc:creator><![CDATA[Der_Knob]]></dc:creator><pubDate>Wed, 21 Jul 2004 14:51:48 GMT</pubDate></item><item><title><![CDATA[Reply to DrawTransparentBitmap on Thu, 22 Jul 2004 06:33:51 GMT]]></title><description><![CDATA[<p>bringt auch nichts <img
      src="https://www.c-plusplus.net/forum/plugins/nodebb-plugin-emoji/emoji/emoji-one/1f61e.png?v=ab1pehoraso"
      class="not-responsive emoji emoji-emoji-one emoji--disappointed_face"
      title=":("
      alt="😞"
    /></p>
]]></description><link>https://www.c-plusplus.net/forum/post/565589</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/565589</guid><dc:creator><![CDATA[Der_Knob]]></dc:creator><pubDate>Thu, 22 Jul 2004 06:33:51 GMT</pubDate></item><item><title><![CDATA[Reply to DrawTransparentBitmap on Thu, 22 Jul 2004 09:13:30 GMT]]></title><description><![CDATA[<p>Warum setzt du eigentlich hBitmap in einen Geräte Kontext ein, den du niemals verwendest? DrawTranspar... setzt das Bitmap ja auch in einen DC ein, bzw. versucht es, aber ich glaube es schafft es nicht, weil das Bitmap schon in einem anderen DC selektiert ist.<br />
Wenn das auch nicht hilft, musst du halt mal alle Rückgabewerte kontrollieren, dann findest du auch allein den Fehler.</p>
]]></description><link>https://www.c-plusplus.net/forum/post/565721</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/565721</guid><dc:creator><![CDATA[D*niel *chumann]]></dc:creator><pubDate>Thu, 22 Jul 2004 09:13:30 GMT</pubDate></item><item><title><![CDATA[Reply to DrawTransparentBitmap on Thu, 22 Jul 2004 11:31:26 GMT]]></title><description><![CDATA[<p>D@niel $chumann schrieb:</p>
<blockquote>
<p>Warum setzt du eigentlich hBitmap in einen Geräte Kontext ein, den du niemals verwendest? DrawTranspar... setzt das Bitmap ja auch in einen DC ein, bzw. versucht es, aber ich glaube es schafft es nicht, weil das Bitmap schon in einem anderen DC selektiert ist.</p>
</blockquote>
<p>mh... das hab ich nicht gewusst...</p>
]]></description><link>https://www.c-plusplus.net/forum/post/565928</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/565928</guid><dc:creator><![CDATA[Der_Knob]]></dc:creator><pubDate>Thu, 22 Jul 2004 11:31:26 GMT</pubDate></item><item><title><![CDATA[Reply to DrawTransparentBitmap on Thu, 22 Jul 2004 11:32:49 GMT]]></title><description><![CDATA[<p>und das war mein Fehler <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="😃"
    /></p>
<p>Sorry, das hab ich echt nicht gewusst <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>
<p>Danke!!!</p>
]]></description><link>https://www.c-plusplus.net/forum/post/565929</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/565929</guid><dc:creator><![CDATA[Der_Knob]]></dc:creator><pubDate>Thu, 22 Jul 2004 11:32:49 GMT</pubDate></item><item><title><![CDATA[Reply to DrawTransparentBitmap on Thu, 22 Jul 2004 18:41:33 GMT]]></title><description><![CDATA[<p>Ich habe da auch gleich mal ne Frage: Wieso benutzt du nicht TransparentBlt<br />
Ich weiß zwar selber nicht wie das Funktioniert aber vielleicht klappt es ja bei dir.</p>
]]></description><link>https://www.c-plusplus.net/forum/post/566341</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/566341</guid><dc:creator><![CDATA[The_incredible_Guest]]></dc:creator><pubDate>Thu, 22 Jul 2004 18:41:33 GMT</pubDate></item><item><title><![CDATA[Reply to DrawTransparentBitmap on Fri, 23 Jul 2004 07:04:29 GMT]]></title><description><![CDATA[<p>Ich benutze es nicht, weil das JETZT funktioniert <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="😃"
    /></p>
<p>Ansonsten gerne...</p>
]]></description><link>https://www.c-plusplus.net/forum/post/566523</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/566523</guid><dc:creator><![CDATA[Der_Knob]]></dc:creator><pubDate>Fri, 23 Jul 2004 07:04:29 GMT</pubDate></item></channel></rss>