gpt4 book ai didi

C++ Direct3D 多屏幕捕获

转载 作者:塔克拉玛干 更新时间:2023-11-03 00:48:02 25 4
gpt4 key购买 nike

您好 Direct3D 专家,

我目前正在使用 Direct3D 开发应用程序以捕获我的两个显示器桌面(当然用作扩展桌面)。以下代码运行良好,但我只能捕获主显示器而不是扩展桌面(只捕获一个屏幕两次)

如何调整此解决方案以进行双屏幕捕获?

首先,我初始化 Direct3D:

D3DDISPLAYMODE          d3dDisplayMode;
D3DPRESENT_PARAMETERS d3dPresentationParameters; //Presentation parameters (backbufferwidth, height...)

if( (pSinfo->g_pD3D=Direct3DCreate9(D3D_SDK_VERSION)) == NULL )
return FALSE;

if( pSinfo->g_pD3D->GetAdapterDisplayMode(D3DADAPTER_DEFAULT, &d3dDisplayMode) == D3DERR_INVALIDCALL )
return FALSE;

ZeroMemory(&d3dPresentationParameters,sizeof(D3DPRESENT_PARAMETERS));
d3dPresentationParameters.Windowed = TRUE;
d3dPresentationParameters.Flags = D3DPRESENTFLAG_LOCKABLE_BACKBUFFER;
d3dPresentationParameters.BackBufferFormat = d3dDisplayMode.Format;
d3dPresentationParameters.BackBufferHeight = gScreenRect.bottom = d3dDisplayMode.Height;
d3dPresentationParameters.BackBufferWidth = gScreenRect.right = d3dDisplayMode.Width;
d3dPresentationParameters.MultiSampleType = D3DMULTISAMPLE_NONE;
d3dPresentationParameters.SwapEffect= D3DSWAPEFFECT_DISCARD;
d3dPresentationParameters.hDeviceWindow = hWnd;
d3dPresentationParameters.PresentationInterval = D3DPRESENT_INTERVAL_DEFAULT;
d3dPresentationParameters.FullScreen_RefreshRateInHz = D3DPRESENT_RATE_DEFAULT;

pSinfo->uiWidth = d3dDisplayMode.Width;
pSinfo->uiHeight = d3dDisplayMode.Height;

if( pSinfo->g_pD3D->CreateDevice(D3DADAPTER_DEFAULT,D3DDEVTYPE_REF,hWnd,D3DCREATE_SOFTWARE_VERTEXPROCESSING ,&d3dPresentationParameters,&pSinfo->g_pd3dDevice) != D3D_OK )
return FALSE;

然后,执行连续截图并将图像数据保存在pData中的循环:

while(1)
{
pSinfo->g_pd3dDevice->GetRenderTarget(0, &pSinfo->pRenderSurface);
pSinfo->g_pd3dDevice->CreateOffscreenPlainSurface(pSinfo->uiWidth, pSinfo->uiHeight, pSinfo->d3dFormat, D3DPOOL_SYSTEMMEM, &pSinfo->pRenderSurface, NULL);
pSinfo->g_pd3dDevice->GetFrontBufferData(0, pSinfo->pRenderSurface);

//D3DXSaveSurfaceToFile("Desktop.bmp", D3DXIFF_BMP, pSinfo->pRenderSurface,NULL, NULL); //Test

ZeroMemory(&pSinfo->lockedRect, sizeof(D3DLOCKED_RECT));
pSinfo->pRenderSurface->LockRect(&pSinfo->lockedRect,NULL, D3DLOCK_READONLY);

memcpy((BYTE*)pSinfo->pData, (BYTE*)pSinfo->lockedRect.pBits, (pSinfo->uiWidth) * pSinfo->uiHeight * pSinfo->uiBitsPerPixels/8);

pSinfo->pRenderSurface->UnlockRect();
//InvalidateRect(((CMainFrame*)(pApp->m_pMainWnd))->m_hWnd,NULL,false);
pSinfo->pRenderSurface->Release();
}

为了更清楚地了解我遇到的问题和解决方案:

我有两台显示器和我的扩展 Windows 桌面。捕获屏幕时,我有两张主屏幕屏幕截图,我想要的是一张主屏幕屏幕截图和一张扩展屏幕屏幕截图。

我想我必须在某处设置一个参数,指示扩展桌面从 Point.x = 1920(对于 1080p 屏幕)开始,但我不知道如何设置。

非常感谢您的帮助!

迪伦

Screen Scheme

最佳答案

好的,我现在已经找到问题了。

需要注意的重要一点是设备创建:

pSinfo->g_pD3D->CreateDevice(D3DADAPTER_DEFAULT,D3DDEVTYPE_REF,hWnd,D3DCREATE_SOFTWARE_VERTEXPROCESSING ,&d3dPresentationParameters,&pSinfo->g_pd3dDevice) != D3D_OK )

我在这里创建了一个带有 D3DADAPTER_DEFAULT 的设备,它不处理其他显示器。因此,我根据可用屏幕的数量调整了这段代码:

for (i = 0; i < NUMBER_OF_DISPLAYS; i++)
{
pSinfo->g_pD3D->CreateDevice(i,D3DDEVTYPE_REF,hWnd,D3DCREATE_SOFTWARE_VERTEXPROCESSING ,&d3dPresentationParameters,&pSinfo->g_pd3dDevice) != D3D_OK )
}

关于C++ Direct3D 多屏幕捕获,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25681915/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com