Urgent code help ScreenShot program
hi all,
i need some really urgent help and i hope someone is able to do it.
i have an exe that takes a screenshot of the screen and saves it as a
jpeg which works perfectly.
theres only 2 things i need and i hope its not too much...
heres a link to the complete project and compiled exe
http://www.mediafire.com/download.php?m2zyyzcngtn
heres the source if anyone doesnt want to dl it
/////////////START///////////////////
////////////////////////////////////
#include <windows.h>
#include <stdio.h>
#include <gdiplus.h>
using namespace Gdiplus;
int GetEncoderClsid(WCHAR *format, CLSID *pClsid)
{
unsigned int num = 0, size = 0;
GetImageEncodersSize(&num, &size);
if(size == 0) return -1;
ImageCodecInfo *pImageCodecInfo = (ImageCodecInfo *)(malloc(size));
if(pImageCodecInfo == NULL) return -1;
GetImageEncoders(num, size, pImageCodecInfo);
for(unsigned int j = 0; j < num; ++j){
if(wcscmp(pImageCodecInfo[j].MimeType, format) == 0){
*pClsid = pImageCodecInfo[j].Clsid;
free(pImageCodecInfo);
return j;
}
}
free(pImageCodecInfo);
return -1;
}
int GetScreeny(LPWSTR lpszFilename, ULONG uQuality)
{
ULONG_PTR gdiplusToken;
GdiplusStartupInput gdiplusStartupInput;
GdiplusStartup(&gdiplusToken, &gdiplusStartupInput, NULL);
HDC hdcScreen = CreateDC("DISPLAY", NULL, NULL, NULL);
HDC hdcCapture = CreateCompatibleDC(hdcScreen);
int nWidth = GetDeviceCaps(hdcScreen, HORZRES),
nHeight = GetDeviceCaps(hdcScreen, VERTRES),
nBPP = GetDeviceCaps(hdcScreen, BITSPIXEL);
LPBYTE lpCapture;
BITMAPINFO bmiCapture = { {
sizeof(BITMAPINFOHEADER), nWidth, -nHeight, 1, nBPP, BI_RGB, 0, 0,
0, 0, 0,
} };
HBITMAP hbmCapture = CreateDIBSection(hdcScreen, &bmiCapture,
DIB_PAL_COLORS, (LPVOID *)&lpCapture, NULL, 0);
if(!hbmCapture){
DeleteDC(hdcCapture);
DeleteDC(hdcScreen);
GdiplusShutdown(gdiplusToken);
return 1;
}
int nCapture = SaveDC(hdcCapture);
SelectObject(hdcCapture, hbmCapture);
BitBlt(hdcCapture, 0, 0, nWidth, nHeight, hdcScreen, 0, 0, SRCCOPY);
RestoreDC(hdcCapture, nCapture);
DeleteDC(hdcCapture);
DeleteDC(hdcScreen);
CLSID imageCLSID;
Bitmap *pScreenShot = new Bitmap(hbmCapture, (HPALETTE)NULL);
EncoderParameters encoderParams;
encoderParams.Count = 1;
encoderParams.Parameter[0].NumberOfValues = 1;
encoderParams.Parameter[0].Guid = EncoderQuality;
encoderParams.Parameter[0].Type = EncoderParameterValueTypeLong;
encoderParams.Parameter[0].Value = &uQuality;
GetEncoderClsid(L"image/jpeg", &imageCLSID);
int result = (pScreenShot->Save(lpszFilename, &imageCLSID,
&encoderParams) == Ok);
delete pScreenShot;
DeleteObject(hbmCapture);
GdiplusShutdown(gdiplusToken);
return result;
}
int APIENTRY WinMain(HINSTANCE hInst, HINSTANCE hPrev, LPSTR
lpCmdLine, int nShowCmd)
{
return GetScreeny(L"screeny5.jpg", 75);
}
/////////////////END///////////////////////////
///////////////////////////////////////////////
What i have done is this, linked this .exe to another code
so when a button is pressed, the exe will run and take a screenshot.
what i need to modify is this
1) Be able to take a maximum of 5 screenshots. There can only be 5 of
the latest shots as ill have to recall the images later on but ill
figure out that later. So when the exe is called the 6th time, it
needs to know to replace the oldest shot (in array 0?) and push every
other shot down (from array 1 to 2 ect).
OR if this is not possible or too tedious
1b) be able to take an infinite number of shots. (so when i do the
recall later on, ill call out the last 5 shots everytime)
and
2) Again only if this is easy to do and not tedious for anyone.
i would like the screenshot to save itself as the date and time of
capture (example X_24July1:43.JPEG)
X = Number of shot for my recall page later on
I will be forever in gratitude if someone can do this and compile it
to an .exe as i have problems compiling with GDI in my pc. I hope
someone can do at least the (1b) part for me =D
THANK YOU SO MUCH & sorry for the long post
for any clarifications plz feel free to add me on msn at
eloquent1@gmail.com