<?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[window capture]]></title><description><![CDATA[<p>Habe in CodeProject einen schönen Beitrag über den Festhalten eines Bildschirm-Inhalts gefunden, allerdings nur in C#.</p>
<p>Wie würde man das in C++ realisieren, wenn der Handler bekannt ist?</p>
]]></description><link>https://www.c-plusplus.net/forum/topic/161120/window-capture</link><generator>RSS for Node</generator><lastBuildDate>Sat, 18 Jul 2026 13:52:57 GMT</lastBuildDate><atom:link href="https://www.c-plusplus.net/forum/topic/161120.rss" rel="self" type="application/rss+xml"/><pubDate>Tue, 03 Oct 2006 15:11:40 GMT</pubDate><ttl>60</ttl><item><title><![CDATA[Reply to window capture on Tue, 03 Oct 2006 15:11:40 GMT]]></title><description><![CDATA[<p>Habe in CodeProject einen schönen Beitrag über den Festhalten eines Bildschirm-Inhalts gefunden, allerdings nur in C#.</p>
<p>Wie würde man das in C++ realisieren, wenn der Handler bekannt ist?</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1148728</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1148728</guid><dc:creator><![CDATA[Percy2000]]></dc:creator><pubDate>Tue, 03 Oct 2006 15:11:40 GMT</pubDate></item><item><title><![CDATA[Reply to window capture on Tue, 03 Oct 2006 15:31:43 GMT]]></title><description><![CDATA[<p>Meinst du mit 'Handler' einen DC ?</p>
<p>Naja egal...Guck mal <a href="http://www.c-plusplus.net/forum/viewtopic-var-t-is-39400-and-sid-is-1d5419dca2b62211a3add56f8c854a1a.html" rel="nofollow">hier</a>.</p>
<p>An den HDC des Displays kommst du auf jeden Fall so:</p>
<pre><code class="language-cpp">// Dreh- und Angelpunkt ist hier natürlich hWnd:
HDC   hDC;
RECT  rcWindow;
int   iWidth,
      iHeight;
hDC = GetWindowDC(hWnd);
GetWindowRect(hWnd, &amp;rcWindow);
iWidth  = rcWindow.right - rcWindow.left;         
iHeight = rcWindow.bottom - rcWindow.top;

dc2bitmap(hDC, iWidth, iHeight, TEXT(&quot;Bitmap.bmp&quot;));

ReleaseDC(hWnd, hDC);
</code></pre>
]]></description><link>https://www.c-plusplus.net/forum/post/1148737</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1148737</guid><dc:creator><![CDATA[CodeFinder]]></dc:creator><pubDate>Tue, 03 Oct 2006 15:31:43 GMT</pubDate></item><item><title><![CDATA[Reply to window capture on Tue, 03 Oct 2006 17:11:23 GMT]]></title><description><![CDATA[<p>Nein, der den Handler, der sich auf die Applikation bezieht.</p>
<p>HWMD hwnd;</p>
<p>Bin im übrigen ein Stück weitergekommen. Mit diesen Funktionen lässt, sich, wenn man den Handler hat (wie er OpenProcess odgl. gegeben wird), der Inhalt des Bildes abspeichern.<br />
Eine unschöne Einschränkung: Das Window muss während des Aufrufs in den Vordergrund gesetzt werden.</p>
<pre><code>#include &lt;windows.h&gt;
#include &lt;iostream&gt;
#include &lt;string.h&gt;
#include  &lt;conio.h&gt;
#include &lt;tchar.h&gt;
#include &lt;process.h&gt;
#include &lt;fstream&gt;

using namespace std;

HBITMAP CopyScreenToBitmap(LPRECT lpRect)
{
	HDC         hScrDC, hMemDC;         // screen DC and memory DC     
//	HBITMAP     hBitmap; //, 
//	HBITMAP     hBitmap;
//	HBITMAP     hOldBitmap;    // handles to deice-dependent bitmaps     
	int         nX, nY, nX2, nY2;       // coordinates of rectangle to grab     
	int         nWidth, nHeight;        // DIB width and height     
	int         xScrn, yScrn;           // screen resolution      

	HGDIOBJ     hOldBitmap , hBitmap;

		// check for an empty rectangle 
    if (IsRectEmpty(lpRect))       
	   return NULL;      
	   // create a DC for the screen and create     
	   // a memory DC compatible to screen DC          

   hScrDC = CreateDC(&quot;DISPLAY&quot;, NULL, NULL, NULL);     
   hMemDC = CreateCompatibleDC(hScrDC);      // get points of rectangle to grab  

   nX = lpRect-&gt;left;     
   nY = lpRect-&gt;top;     
   nX2 = lpRect-&gt;right;     
   nY2 = lpRect-&gt;bottom;      // get screen resolution      

   xScrn = GetDeviceCaps(hScrDC, HORZRES);     
   yScrn = GetDeviceCaps(hScrDC, VERTRES);      

   //make sure bitmap rectangle is visible      

   if (nX &lt; 0)         
	  nX = 0;     

   if (nY &lt; 0)         
      nY = 0;     

   if (nX2 &gt; xScrn)         
      nX2 = xScrn;     

   if (nY2 &gt; yScrn)         
      nY2 = yScrn;      

   nWidth = nX2 - nX;     
   nHeight = nY2 - nY;      

   // create a bitmap compatible with the screen DC     

   hBitmap = CreateCompatibleBitmap(hScrDC, nWidth, nHeight);      

   // select new bitmap into memory DC     

   hOldBitmap =   SelectObject (hMemDC, hBitmap);      

   // bitblt screen DC to memory DC     

   BitBlt(hMemDC, 0, 0, nWidth, nHeight, hScrDC, nX, nY, SRCCOPY);     

   // select old bitmap back into memory DC and get handle to     
   // bitmap of the screen          

   hBitmap = SelectObject(hMemDC, hOldBitmap);      

   // clean up      

   DeleteDC(hScrDC);     
   DeleteDC(hMemDC);      

   // return handle to the bitmap      

   return (HBITMAP)hBitmap; 

}

HBITMAP CopyWindowToBitmap(HWND hWnd)
{
	HBITMAP     hBitmap = NULL;  // handle to device-dependent bitmap      
	// check for a valid window handle      
	if (!hWnd)         
	    return NULL; 

    RECT    rectWnd; 

  ::GetWindowRect(hWnd, &amp;rectWnd);  
    hBitmap = CopyScreenToBitmap(&amp;rectWnd);

	return hBitmap; 
}

BOOL SaveBitmap(char *name,HBITMAP bitmap)
{
	HDC hdcScreen;		// Device context of the screen
	HWND hwndScreen;	// Desktop window handle
	int i;				// Counts the number of scanlines
	BYTE *bits;			// Pointer to the bitmap's bits
	BITMAPINFOHEADER *info;	// Info structure about this bitmap
	HANDLE fp;			// A file handle
	BITMAPFILEHEADER finfo;	// File info header
	long ctsize,imgsize,pixels;// Various sizes needed to build the file
	DWORD dw;			// Doubleword return code
	char *ptr;			// Pointer used to write the opening BM

	hwndScreen=GetDesktopWindow();
	hdcScreen = GetDC( hwndScreen );

	info = (BITMAPINFOHEADER*)GlobalAlloc(GMEM_FIXED,sizeof(BITMAPFILEHEADER)+(1024*sizeof(RGBQUAD)));
	info-&gt;biSize = sizeof(BITMAPINFOHEADER);
	info-&gt;biBitCount = 0;

	i = GetDIBits( hdcScreen, // handle of device context 
			bitmap, // handle of bitmap 
			0,			// first scan line to set in destination bitmap 
			0,		// number of scan lines to copy 
			NULL, // address of array for bitmap bits 
			(BITMAPINFO*)info,		// address of structure with bitmap data 
			DIB_RGB_COLORS // RGB or palette index
			 );

	if( (info-&gt;biBitCount!=4) &amp;&amp;
		(info-&gt;biBitCount!=8) &amp;&amp;
		(info-&gt;biBitCount!=24) )
		info-&gt;biBitCount=24;
	info-&gt;biCompression=BI_RGB;

	pixels=info-&gt;biWidth*info-&gt;biHeight;
	switch(info-&gt;biBitCount)
	{
		case 4:ctsize=16;imgsize=pixels/2;break;
		case 8:ctsize=256;imgsize=pixels;break;
		case 16:ctsize=0;imgsize=pixels*2;break;
		case 24:ctsize=0;imgsize=pixels*3;break;
		case 32:ctsize=0;imgsize=pixels*4;break;
		default:
			ReleaseDC( hwndScreen,hdcScreen );
			return FALSE;
	}

	bits = (unsigned char*)GlobalAlloc(GMEM_FIXED,imgsize);

	i = GetDIBits( hdcScreen, // handle of device context 
			bitmap, // handle of bitmap 
			0,			// first scan line to set in destination bitmap 
			info-&gt;biHeight,		// number of scan lines to copy 
			bits, // address of array for bitmap bits 
			(BITMAPINFO*)info,		// address of structure with bitmap data 
			DIB_RGB_COLORS // RGB or palette index
			 );

	ptr = (char *)&amp;finfo.bfType;
	ptr[0]='B';
	ptr[1]='M';

	finfo.bfOffBits=sizeof(BITMAPFILEHEADER)+
		sizeof(BITMAPINFOHEADER)+
		(sizeof(RGBQUAD)*ctsize);
	finfo.bfSize=finfo.bfOffBits+imgsize;
	finfo.bfReserved1=0;
    finfo.bfReserved2=0;       

	fp = CreateFile(name,// pointer to name of the file 
		GENERIC_WRITE, // access (read-write) mode 
		0, // share mode 
		NULL, // pointer to security attributes 
		CREATE_ALWAYS,// how to create
		FILE_ATTRIBUTE_NORMAL|FILE_FLAG_SEQUENTIAL_SCAN,// file attributes 
		NULL // handle to file with attributes to copy 
		);

	WriteFile(fp,&amp;finfo,sizeof(BITMAPFILEHEADER),&amp;dw,NULL);
	WriteFile(fp,info,sizeof(BITMAPINFOHEADER)+sizeof(RGBQUAD)*ctsize,&amp;dw,NULL);
	WriteFile(fp,bits,imgsize,&amp;dw,NULL);
	CloseHandle(fp);
	GlobalFree(info);
	GlobalFree(bits);

	ReleaseDC( hwndScreen,hdcScreen );
	return TRUE;
}
</code></pre>
<p>Frage: Kann man den Windwos-Inhalt nicht auch dann einlesen, wenn es im Hintergrund läuft?</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1148786</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1148786</guid><dc:creator><![CDATA[Percy2000]]></dc:creator><pubDate>Tue, 03 Oct 2006 17:11:23 GMT</pubDate></item></channel></rss>