<?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[Seltsames bitmap problem]]></title><description><![CDATA[<p>also ich poste erstmal den code:</p>
<pre><code class="language-cpp">// bildverarbeitung2.cpp : Definiert den Einsprungpunkt für die Anwendung.
//

#include &quot;stdafx.h&quot;
#include &lt;windows.h&gt;

LRESULT CALLBACK WndProc (HWND, UINT, WPARAM, LPARAM);

HBITMAP hBitmap;
BITMAP bitmap;
HDC            hdc, hdcMem ;
HINSTANCE      hInstance ;
PAINTSTRUCT    ps ;

HBITMAP loadImg(char* path)
{
	if(HBITMAP ret = (HBITMAP)LoadImage(0,path,IMAGE_BITMAP,0,0,LR_LOADFROMFILE))
		return ret;
	else
		return NULL;

}
HDC getScreenShot()
{
	return GetDC(0);
}
HBITMAP getBitmapScreenShot()
{
	HDC screen = getScreenShot();
	HDC hdcCompatible = CreateCompatibleDC(screen); 
	HBITMAP screenBitmap = CreateCompatibleBitmap(screen, GetDeviceCaps(screen, HORZRES), GetDeviceCaps(screen, VERTRES));
	SelectObject(hdcCompatible, screenBitmap);
	BitBlt(hdcCompatible,0,0, GetDeviceCaps(screen, HORZRES), GetDeviceCaps(screen, VERTRES), screen, 0,0,SRCCOPY) ;
	return screenBitmap;
}
HDC getBitmapHDC(HBITMAP img)
{
	HDC hdcImage = CreateCompatibleDC(GetDC(0));
	SelectObject(hdcImage,img);
	return hdcImage;
}
SIZE getBitmapSize(HBITMAP img)
{

	BITMAP imgInfo;
	GetObject(img, sizeof(BITMAP), (LPSTR)&amp;imgInfo);
	SIZE ret;
	ret.cx = imgInfo.bmWidth;
	ret.cy = imgInfo.bmHeight;
	return ret;
}
HBITMAP getHDCScaled(float xscale, float yscale, HDC source)
{
	HDC hdcScaled = getScreenShot(); 
	HBITMAP hbmScaled = CreateCompatibleBitmap(source, 
                    GetDeviceCaps(source, HORZRES) * xscale, 
                    GetDeviceCaps(source, VERTRES) * yscale); 
	SelectObject(hdcScaled, hbmScaled);
	StretchBlt(hdcScaled, 
                     0, 0, 
                     GetDeviceCaps(source, HORZRES) * xscale,  GetDeviceCaps(source, VERTRES) * yscale, 
                     source, 
                     0, 0, 
                     GetDeviceCaps(source, HORZRES), GetDeviceCaps(source, VERTRES), 
                     SRCCOPY); 
	return hbmScaled;

}
int WINAPI WinMain (HINSTANCE hInstance, HINSTANCE hPrevInstance,
                    PSTR szCmdLine, int iCmdShow)
{
     static char szAppName[] = &quot;Name&quot; ;
     HWND        hwnd ;
     MSG         msg ;
     WNDCLASSEX  wndclass ;

     wndclass.cbSize        = sizeof (wndclass) ;
     wndclass.style         = CS_HREDRAW | CS_VREDRAW ;
     wndclass.lpfnWndProc   = WndProc ;
     wndclass.cbClsExtra    = 0 ;
     wndclass.cbWndExtra    = 0 ;
     wndclass.hInstance     = hInstance ;
     wndclass.hIcon         = LoadIcon (NULL, IDI_APPLICATION) ;
     wndclass.hCursor       = LoadCursor (NULL, IDC_ARROW) ;
     wndclass.hbrBackground = (HBRUSH) GetStockObject (WHITE_BRUSH) ;
     wndclass.lpszMenuName  = NULL ;
     wndclass.lpszClassName = szAppName ;
     wndclass.hIconSm       = LoadIcon (NULL, IDI_APPLICATION) ;

     RegisterClassEx (&amp;wndclass) ;

     hwnd = CreateWindow (szAppName, &quot;Fenstername&quot;, WS_OVERLAPPEDWINDOW,
			  CW_USEDEFAULT, CW_USEDEFAULT, CW_USEDEFAULT, CW_USEDEFAULT,
			  NULL, NULL, hInstance, NULL) ;	

     ShowWindow (hwnd, iCmdShow) ;
     UpdateWindow (hwnd) ;

     while (GetMessage (&amp;msg, NULL, 0, 0))
          {
          TranslateMessage (&amp;msg) ;
          DispatchMessage (&amp;msg) ;
          }
     return msg.wParam ;
}

LRESULT CALLBACK WndProc (HWND hwnd, UINT iMsg, WPARAM wParam, LPARAM lParam)
{
     switch (iMsg)
          {
          case WM_CREATE :
			  {
					hInstance = ((LPCREATESTRUCT) lParam)-&gt;hInstance ;
					HDC scrShot = getScreenShot();
					hBitmap = getHDCScaled(0.4, 0.4, scrShot);

					GetObject (hBitmap, sizeof (BITMAP), &amp;bitmap) ;
			  }
               return 0 ;

          case WM_PAINT :
			  {
				  hdc = BeginPaint (hwnd, &amp;ps) ;

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

				  BitBlt (hdc, 100, 100, bitmap.bmWidth, bitmap.bmHeight, hdcMem, 0, 0, SRCCOPY) ;

				  EndPaint (hwnd, &amp;ps) ;
               return 0 ;
			  }

          case WM_DESTROY :
			   DeleteDC (hdcMem) ;
			   DeleteObject (hBitmap) ;
               PostQuitMessage (0) ;
               return 0 ;
          }

     return DefWindowProc (hwnd, iMsg, wParam, lParam) ;
}
</code></pre>
<p>nunja, wenn ich das aufrufe wird in der oberen linken bildschirmecke tatsächlich ein screenshot mit der größe 0.4 gezeichnet. dieser befindet sich aber nicht im fenster und wird auch nur 1 mal gezeichnet...nähmlich ganz am anfang oO</p>
]]></description><link>https://www.c-plusplus.net/forum/topic/182339/seltsames-bitmap-problem</link><generator>RSS for Node</generator><lastBuildDate>Tue, 07 Jul 2026 14:05:33 GMT</lastBuildDate><atom:link href="https://www.c-plusplus.net/forum/topic/182339.rss" rel="self" type="application/rss+xml"/><pubDate>Wed, 23 May 2007 20:21:09 GMT</pubDate><ttl>60</ttl><item><title><![CDATA[Reply to Seltsames bitmap problem on Wed, 23 May 2007 20:21:09 GMT]]></title><description><![CDATA[<p>also ich poste erstmal den code:</p>
<pre><code class="language-cpp">// bildverarbeitung2.cpp : Definiert den Einsprungpunkt für die Anwendung.
//

#include &quot;stdafx.h&quot;
#include &lt;windows.h&gt;

LRESULT CALLBACK WndProc (HWND, UINT, WPARAM, LPARAM);

HBITMAP hBitmap;
BITMAP bitmap;
HDC            hdc, hdcMem ;
HINSTANCE      hInstance ;
PAINTSTRUCT    ps ;

HBITMAP loadImg(char* path)
{
	if(HBITMAP ret = (HBITMAP)LoadImage(0,path,IMAGE_BITMAP,0,0,LR_LOADFROMFILE))
		return ret;
	else
		return NULL;

}
HDC getScreenShot()
{
	return GetDC(0);
}
HBITMAP getBitmapScreenShot()
{
	HDC screen = getScreenShot();
	HDC hdcCompatible = CreateCompatibleDC(screen); 
	HBITMAP screenBitmap = CreateCompatibleBitmap(screen, GetDeviceCaps(screen, HORZRES), GetDeviceCaps(screen, VERTRES));
	SelectObject(hdcCompatible, screenBitmap);
	BitBlt(hdcCompatible,0,0, GetDeviceCaps(screen, HORZRES), GetDeviceCaps(screen, VERTRES), screen, 0,0,SRCCOPY) ;
	return screenBitmap;
}
HDC getBitmapHDC(HBITMAP img)
{
	HDC hdcImage = CreateCompatibleDC(GetDC(0));
	SelectObject(hdcImage,img);
	return hdcImage;
}
SIZE getBitmapSize(HBITMAP img)
{

	BITMAP imgInfo;
	GetObject(img, sizeof(BITMAP), (LPSTR)&amp;imgInfo);
	SIZE ret;
	ret.cx = imgInfo.bmWidth;
	ret.cy = imgInfo.bmHeight;
	return ret;
}
HBITMAP getHDCScaled(float xscale, float yscale, HDC source)
{
	HDC hdcScaled = getScreenShot(); 
	HBITMAP hbmScaled = CreateCompatibleBitmap(source, 
                    GetDeviceCaps(source, HORZRES) * xscale, 
                    GetDeviceCaps(source, VERTRES) * yscale); 
	SelectObject(hdcScaled, hbmScaled);
	StretchBlt(hdcScaled, 
                     0, 0, 
                     GetDeviceCaps(source, HORZRES) * xscale,  GetDeviceCaps(source, VERTRES) * yscale, 
                     source, 
                     0, 0, 
                     GetDeviceCaps(source, HORZRES), GetDeviceCaps(source, VERTRES), 
                     SRCCOPY); 
	return hbmScaled;

}
int WINAPI WinMain (HINSTANCE hInstance, HINSTANCE hPrevInstance,
                    PSTR szCmdLine, int iCmdShow)
{
     static char szAppName[] = &quot;Name&quot; ;
     HWND        hwnd ;
     MSG         msg ;
     WNDCLASSEX  wndclass ;

     wndclass.cbSize        = sizeof (wndclass) ;
     wndclass.style         = CS_HREDRAW | CS_VREDRAW ;
     wndclass.lpfnWndProc   = WndProc ;
     wndclass.cbClsExtra    = 0 ;
     wndclass.cbWndExtra    = 0 ;
     wndclass.hInstance     = hInstance ;
     wndclass.hIcon         = LoadIcon (NULL, IDI_APPLICATION) ;
     wndclass.hCursor       = LoadCursor (NULL, IDC_ARROW) ;
     wndclass.hbrBackground = (HBRUSH) GetStockObject (WHITE_BRUSH) ;
     wndclass.lpszMenuName  = NULL ;
     wndclass.lpszClassName = szAppName ;
     wndclass.hIconSm       = LoadIcon (NULL, IDI_APPLICATION) ;

     RegisterClassEx (&amp;wndclass) ;

     hwnd = CreateWindow (szAppName, &quot;Fenstername&quot;, WS_OVERLAPPEDWINDOW,
			  CW_USEDEFAULT, CW_USEDEFAULT, CW_USEDEFAULT, CW_USEDEFAULT,
			  NULL, NULL, hInstance, NULL) ;	

     ShowWindow (hwnd, iCmdShow) ;
     UpdateWindow (hwnd) ;

     while (GetMessage (&amp;msg, NULL, 0, 0))
          {
          TranslateMessage (&amp;msg) ;
          DispatchMessage (&amp;msg) ;
          }
     return msg.wParam ;
}

LRESULT CALLBACK WndProc (HWND hwnd, UINT iMsg, WPARAM wParam, LPARAM lParam)
{
     switch (iMsg)
          {
          case WM_CREATE :
			  {
					hInstance = ((LPCREATESTRUCT) lParam)-&gt;hInstance ;
					HDC scrShot = getScreenShot();
					hBitmap = getHDCScaled(0.4, 0.4, scrShot);

					GetObject (hBitmap, sizeof (BITMAP), &amp;bitmap) ;
			  }
               return 0 ;

          case WM_PAINT :
			  {
				  hdc = BeginPaint (hwnd, &amp;ps) ;

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

				  BitBlt (hdc, 100, 100, bitmap.bmWidth, bitmap.bmHeight, hdcMem, 0, 0, SRCCOPY) ;

				  EndPaint (hwnd, &amp;ps) ;
               return 0 ;
			  }

          case WM_DESTROY :
			   DeleteDC (hdcMem) ;
			   DeleteObject (hBitmap) ;
               PostQuitMessage (0) ;
               return 0 ;
          }

     return DefWindowProc (hwnd, iMsg, wParam, lParam) ;
}
</code></pre>
<p>nunja, wenn ich das aufrufe wird in der oberen linken bildschirmecke tatsächlich ein screenshot mit der größe 0.4 gezeichnet. dieser befindet sich aber nicht im fenster und wird auch nur 1 mal gezeichnet...nähmlich ganz am anfang oO</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1291078</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1291078</guid><dc:creator><![CDATA[pixartist]]></dc:creator><pubDate>Wed, 23 May 2007 20:21:09 GMT</pubDate></item><item><title><![CDATA[Reply to Seltsames bitmap problem on Wed, 23 May 2007 20:29:08 GMT]]></title><description><![CDATA[<ol>
<li>Du released die hBitmap nie aus hdcMem (mittels zweitem SelectObject()!)</li>
<li>Du erzeugst bei jedem WM_PAINT ein neues hdcMem</li>
<li>Generell bist du recht wenig am saubermachen <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=";D"
      alt="😉"
    /></li>
</ol>
<p>(Unter Win95 hättest du nach nen paar WM_PAINT-Aufrufen sofort merkwürdige Grafikfehler, fehlende Symbole oder dir würde sogar das ganze Windows wegschmieren ;D)</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1291080</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1291080</guid><dc:creator><![CDATA[geeky]]></dc:creator><pubDate>Wed, 23 May 2007 20:29:08 GMT</pubDate></item><item><title><![CDATA[Reply to Seltsames bitmap problem on Wed, 23 May 2007 23:47:46 GMT]]></title><description><![CDATA[<p>geeky schrieb:</p>
<blockquote>
<ol>
<li>Du released die hBitmap nie aus hdcMem (mittels zweitem SelectObject()!)</li>
</ol>
</blockquote>
<p>hö ? wie jetzt? versteh ich ned</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1291147</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1291147</guid><dc:creator><![CDATA[pixartist]]></dc:creator><pubDate>Wed, 23 May 2007 23:47:46 GMT</pubDate></item><item><title><![CDATA[Reply to Seltsames bitmap problem on Thu, 24 May 2007 09:41:55 GMT]]></title><description><![CDATA[<p>z.B. mag DeleteObject() das nicht so gerne:</p>
<blockquote>
<p>Do not delete a drawing object (pen or brush) while it is still selected into a DC.</p>
</blockquote>
<p>Nehmen wir mal die WM_PAINT:</p>
<pre><code class="language-cpp">hdc = BeginPaint (hwnd, &amp;ps) ;
hdcMem = CreateCompatibleDC (hdc) ;
SelectObject (hdcMem, hBitmap) ;
BitBlt (hdc, 100, 100, bitmap.bmWidth, bitmap.bmHeight, hdcMem, 0, 0, SRCCOPY) ;
EndPaint (hwnd, &amp;ps) ;
</code></pre>
<p>Du erzeugst hier ein hdcMem-Handle bei jedem WM_PAINT-Aufruf löscht aber bei WM_DESTROY nur jeweils das letzte hdcMem, weil du alle vorigen ja hier in WM_PAINT überschreibst. Gut, Windows räumt bei Programmende eh selber auf, aber wenn deine Anwendung lange läuft steigt die Anzahl der GDI-Handles an und es gibt da von Windows ein Limit!</p>
<p>Dann selektierst du hier hBitmap in das hdcMem, selektierst es aber nirgendswo mehr raus. Einige GDI-Funktionen wie DeleteObject() mögen in-ein-DC-selektierte GDI-Objekte nicht mehr <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=";D"
      alt="😉"
    /></p>
<p>Abgeändert:</p>
<pre><code class="language-cpp">hdc = BeginPaint (hwnd, &amp;ps) ;
hdcMem = CreateCompatibleDC (hdc) ;
HGDIOBJ prevObj=SelectObject (hdcMem, hBitmap) ;
BitBlt (hdc, 100, 100, bitmap.bmWidth, bitmap.bmHeight, hdcMem, 0, 0, SRCCOPY) ;
SelectObject(hdcMem,prevObj);
DeleteDC(hdcMem);
EndPaint (hwnd, &amp;ps) ;
</code></pre>
]]></description><link>https://www.c-plusplus.net/forum/post/1291292</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1291292</guid><dc:creator><![CDATA[geeky]]></dc:creator><pubDate>Thu, 24 May 2007 09:41:55 GMT</pubDate></item></channel></rss>