简体   繁体   中英

how can i get byte-array from HBITMAP

my environment:
win32
visual c++
directx

i need to map another application's face to my application's texture.
for example, my Internet Explorer screen is appears on my DirectX Cube's Texture, and it is updated realtime.

my Method is Next:

//in DirectX Rendering Loop...

HWND hSrc = FindWindow(NULL, _T("application's classname"));
HDC hdc = GetDC(hSrc);

RECT targetRect;
GetClientRect(hSrc, &targetRect);
HBITMAP hBitmap = CreateCompatibleBitmap(hdc,targetRect.right,targetRect.bottom);
//now, target application's window is 'hBitmap'

LPDIRECT3DTEXTURE9 ptxt = NULL;    //my destination texture
if( SUCCEEDED(D3DXCreateTexture(gpDevice,targetRect.right, targetRect.bottom, 
        0, 0, D3DFMT_A8B8G8R8, D3DPOOL_MANAGED,&ptxt)))
        {
            D3DLOCKED_RECT lr;
            HRESULT hr = ptxt->LockRect(0,&lr,NULL,D3DLOCK_DISCARD);

             //TODO : memcpy(lr.pBits , 'Start pointer of Bit-Array' , targetRect.right*targetRect.bottom*4); //mydesktop's color is 32bit truecolor (= *4)

            ptxt->UnlockRect(0);
        }

Question:
how can i get byte array from HBITMAP format???
there is any method in win32api like this?

GetByteArray(HBITMAP, void**)

or can do this with other method's composition?

CreateCompatibleBitmap creates a DDB where you don't have access to the bits. Try using CreateDIBSection instead.

Also note that as written you haven't actually painted anything into the bitmap yet.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM