Click here to Skip to main content
15,886,199 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
I want to capture desktop image in win7 using Getfrontbufferdata, a interface function in DirectX9Ex. But I met the below two problems.

1. In Windowed Mode,I can capture desktop image correctly. Then I want to capture image in full-screen mode. So I changed the Windowed value into FALSE,But failed in CreateDeviceEx.

...
 d3dppEx.Windowed = FALSE;//changed this
d3dppEx.Flags = D3DPRESENTFLAG_LOCKABLE_BACKBUFFER;
d3dppEx.BackBufferFormat = ddmEx.Format;
d3dppEx.BackBufferHeight = ddmEx.Height;
d3dppEx.BackBufferWidth = ddmEx.Width;
d3dppEx.MultiSampleType = D3DMULTISAMPLE_NONE;
d3dppEx.SwapEffect = D3DSWAPEFFECT_DISCARD;
//d3dpp.hDeviceWindow = hWnd;
d3dppEx.PresentationInterval = D3DPRESENT_INTERVAL_DEFAULT;
d3dppEx.FullScreen_RefreshRateInHz = D3DPRESENT_RATE_DEFAULT;

hr = g_pD3DEx-> CreateDeviceEx(D3DADAPTER_DEFAULT, D3DDEVTYPE_HAL, NULL,D3DCREATE_SOFTWARE_VERTEXPROCESSING,&d3dppEx, NULL, &g_pd3dDeviceEx);//failed and error code is 0x8876086c 

How can I solve the problem and get the image in full-screen mode?

2. I found a strange phenomenon When test my code. When win7's Areo effects is turn on, the capture rate just be 10~20hz (MSDN said that Getfrontbufferdata is slow by design ). But when changed theme into Windows classic which will turn off the Areo. The capture rate became about 60hz. Then I turn on the Areo and recovered my original theme. The capture rate still keep about 60hz,an ideal high frequence!
I guss it is related to rdp, which windows uesd in remote desktop. But I don't know how to apply in my code.

What I have tried:

1. I changed Windowed value into FALSE but failed to create Device.

2. I tried to off the Areo. But it took about 1 minute that capture frequence be fast. Besides, I also want to keep Areo effect in my project.
hr = DwmEnableComposition(DWM_EC_DISABLECOMPOSITION);

Then I tried to turn on rdp session and added below code in my project, but nothing changed.
HRESULT hr2 = S_OK;
hr2 = CoInitialize(NULL);
IRDPSRAPISharingSession* p_ShareSession;
IRDPSRAPIInvitationManager* p_InvitationManager;
IRDPSRAPIInvitation* p_Invitation;
hr2 = CoCreateInstance(__uuidof(RDPSession), NULL, CLSCTX_ALL, __uuidof(IRDPSRAPISharingSession), reinterpret_cast<void**>(&p_ShareSession));
IConnectionPointContainer* pConnectionPointContainer = NULL;
IConnectionPoint* pConnectionPoint = NULL;
unsigned long cid;
hr2 = p_ShareSession->QueryInterface(IID_IConnectionPointContainer, reinterpret_cast<void**>(&pConnectionPointContainer));
hr2 = p_ShareSession->Open();
Posted
Updated 13-Sep-18 2:50am

1 solution

Read the article and code about Capturing an Image. The trick is to use the full screen as device context.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900