Hello Everyone..
Am new to this DirectX programming. Recently i have installed DirectX9 & setup with VS 2008. Am trying to take screenshot of Desktop ( client area i.e., not entire desktop, only specified region on desktop ). I've googled on this & found a peice of code.
#include <windows.h>
#include <d3d9.h>
#include <d3dx9.h>
IDirect3DDevice9* g_pd3dDevice;
int ScreenWidth = 100;
int ScreenHeight = 100;
void CaptureScreen()
{
IDirect3DSurface9* pSurface;
g_pd3dDevice->CreateOffscreenPlainSurface(ScreenWidth, ScreenHeight,
D3DFMT_A8R8G8B8, D3DPOOL_SCRATCH, &pSurface, NULL);
g_pd3dDevice->GetFrontBufferData(0, pSurface);
D3DXSaveSurfaceToFile("E:\\Desktop.bmp",D3DXIFF_BMP,pSurface,NULL,NULL);
pSurface->Release();
}
void CDirectXProject::Screenshot()
{
CaptureScreen();
}
And in Linker Properties -> Input I've refrenced d3d9.lib d3dx9.lib. In project folder, I've kept d3d9.dll, d3d9.lib & d3dx9.lib files.
But when i run the program, it crashes at CreateOffscreenPlainSurface function stating that Access violation. Am not getting what am doing wrong with this. And also i've specified the Image width & HEight. But how do i specify the client region i.e., x & y cordinate.
Please suggest me on this.
Thank you all..