I prefer to use this function written by me that works on all windows device (directx8,directx9,opengl,irrlicht software and apfelbaum software)(but this function just works on windows).
To compile it, get DIBAPI from
here
You can compile DIBAPI as a static library or as a dynamic library
NOTE: this function automatic add the ".bmp" extension at the file name. This function is stable,it doesn't crash and ,if the file exist, this function save the screen with the name file1.bmp. if file1.bmp exist, it saves the screen with the name file2.bmp, etc...
however, your library is excellent.
the code of my function is below.
example of use of my function :
Code: Select all
//this exsample capture the portion of the screen comprised between 0,0 //and 800,600
RECT rect;
rect.left = 0;
rect.top = 0;
rect.right = 800;
rect.bottom = 600;
CaptureTheCurrentScreen(device,"image",rect);
//save the current screen with the name image.bmp, or image1.bmp if image.bmp exist, or image2.bmp if image1.bmp exist, etc.....
do you want capure all the screen (and not a portion of it)? use CaptureTheCurrentScreen(device,"image");
This is the source of the function:
Code: Select all
#include <windows.h>
#include "dibapi.h"
#include <irrlicht.h>
using namespace irr;
#include <string>
#inlcude <sstream>
using namespace std;
RECT GetScreenResolution() {
RECT screenrect;
HDC hDC = CreateDC("DISPLAY", NULL, NULL, NULL);
screenrect.left = screenrect.top = 0;
screenrect.right = GetDeviceCaps(hDC, HORZRES);
screenrect.bottom = GetDeviceCaps(hDC, VERTRES);
/* Delete our DC */
DeleteDC(hDC);
return screenrect
}
template<class Num>string NumericString(Num num) {
ostringstream stringa;
stringa<<num;
return stringa.str();
}
void CaptureTheCurrentScreen(IrrlichtDevice* device,string name_of_file,RECT screenrect)
{
/*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/
/* get the bitmap */
HDIB dib = CopyScreenToDIB(&screenrect);
/* save the bitmap in a file */
int number = 0;
/*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/
for(;; number++)
{
string file = name_of_file + NumericString(number) ".bmp";
if(device->getFileSystem()->existFile(file.c_str()) == false)
{
/* if the file does not exist save it */
if(SaveDIB(dib, (char *) file.c_str()) != 0)
{
MessageBox(NULL, "errore!", "errore", MB_OK |MB _SYSTEMMODAL);
}
break;
}
}
/* destroy the DIB */
DestroyDIB(dib);
}
void CaptureTheCurrentScreen(IrrlichtDevice* device,string name_of_file) {
CaptureTheCurrentScreen(device,name_of_file,GetScreenResolution());
}
What do you think?
