This topic is now archived and is closed to further replies.


Win32 hwnd -> Direct3DTexture8

Recommended Posts

I'm attempting to copy data from a normal windows hwnd, into a D3D8 texture, but I'm not certain of the procedure to follow. I figure the steps are something like: 1) Obtain a lock on texture memory 2) Obtain a lock on window handle DC 3) Copy data from DC to texture memory 4) Unlock both 5) Update ...but I'm not certain what functions are available. Step #3 is what puzzles me. Ideas? Thanks! MatrixCubed
Edited by - MatrixCubed on November 17, 2001 9:39:07 PM

Share this post

Link to post
Share on other sites
Small update...

I''ve come up with a sort of scheme, which is not working at this point. Perhaps someone could offer guidance.

1. GetDC of the window to capture (source DC)
2. CreateCompatibleBitmap of DC from #1
3. LockRect on the D3D texture in question
4. Fill out a BITMAPINFO structure and pass to GetDIBits (this should theoretically fill the texture with pixels from the source window).
5. UnlockRect on the D3D texture.
6. Set the texture for use with the renderer, and we''re done

The problem lies with #4, the data is not copied, and no error is returned.



Share this post

Link to post
Share on other sites
Guest Anonymous Poster
Here''s some code for capturing the desktop to HBITMAP - sorry it''s in C - I have no idea about how to transfer the HBITMAP to a DX surface - you''ll have to figure that part out for yourself.
// ----------------------------------------------------------------------------

// Function captures current desktop storing the image in the bitmap parameter


BOOL __stdcall CaptureDesktop(HBITMAP *hBmpScr)

*hBmpScr = NULL;

HWND hwndDeskTop = GetDesktopWindow();


Sleep(500); // give the desktop time to repaint itself

HDC hdc = GetWindowDC(hwndDeskTop);

int iWidth = GetDeviceCaps(hdc, HORZRES);
int iHeight = GetDeviceCaps(hdc, VERTRES);

HDC memdc = CreateCompatibleDC(hdc);

*hBmpScr = CreateCompatibleBitmap(hdc, iWidth, iHeight);

HBITMAP hBmpPre = (HBITMAP)SelectObject(memdc, *hBmpScr);

BitBlt(memdc, 0, 0, iWidth, iHeight, hdc, 0, 0, SRCCOPY);

*hBmpScr = (HBITMAP)SelectObject(memdc, hBmpPre); // ??



ReleaseDC(hwndDeskTop, hdc);

return ( *hBmpScr != NULL );


Share this post

Link to post
Share on other sites