 |
Cheat Engine The Official Site of Cheat Engine
|
| View previous topic :: View next topic |
| Author |
Message |
killersamurai Expert Cheater
Reputation: 0
Joined: 10 Sep 2007 Posts: 197 Location: Colorado
|
Posted: Wed Oct 10, 2007 9:42 pm Post subject: [tut]Screen Capture |
|
|
I got really bored and decided to do something in c++. Since not many people know this, I’ve decided to make a little tutorial on how to get a screen shot of your desktop and save it as a .bmp . If you don’t know what some of these structures or functions do, I’ll provide you with a link where you can find out what it does. I will not explain some of them because you would get very lost if I did.
What we first need to do is get the handle to the desktop and other information. We would do this by
| Code: |
HWND hDeskHandle = GetDesktopWindow();
HDC hdcSrc = GetWindowDC(hDeskHandle);
HDC hdcDes = CreateCompatibleDC(hdcSrc);
|
GetDesktopWindow() - Gets the handle to the desktop
GetWindowDc() http://msdn2.microsoft.com/en-us/library/ms534830.aspx
CreateCompatibleDC() http://msdn2.microsoft.com/en-us/library/ms533239.aspx
After this is done, we need to get the dimension of the window
| Code: |
RECT rRec;
GetWindowRect(hDeskHandle, &rRec);
int iWidth = rRec.right - rRec.left;
int iHeight = rRec.bottom - rRec.top;
|
RECT – A structure that holds the coordinates the upper-left and lower-right corners of the rectangle
GetWindowRect() – Fills out a RECT;
Before we continue, I must tell you how a bitmap is created. It is done like so
|Bitmap file header |
|Bitmap info header |
|RGBQUAD array |
|Color index array |
You can get more information from google if you are really interested. We will now start with the file header
| Code: |
BITMAPFILEHEADER bFileHeader = {
0x4d42,
0,
0,
0,
sizeof(BITMAPFILEHEADER) + sizeof(BITMAPINFOHEADER)};
|
BITMAPFILEHEADER http://msdn2.microsoft.com/en-us/library/ms532321.aspx
4d42 is MB which is BM and that is the type it must be. We are now going to get the info header
| Code: |
BITMAPINFOHEADER bInfoHeader = {
sizeof(bInfoHeader),
iWidth, iHeight,
1,
24,
BI_RGB,
0,
0,
0,
0,
0};
|
BITMAPINFOHEADER http://msdn2.microsoft.com/en-us/library/ms532290.aspx
We now get to write this to a file.
| Code: |
DWORD d; // used to hold number of bytes written
HANDLE hFile = CreateFile("screenshot.bmp", GENERIC_WRITE,
0, NULL, CREATE_ALWAYS, FILE_ATTRIBUTE_NORMAL, NULL);
WriteFile(hFile, (char*)&bFileHeader, sizeof(bFileHeader), &d, NULL);
WriteFile(hFile, (char*)&bInfoHeader, sizeof(bInfoHeader), &d, NULL);
|
CreateFile(filename, desired access, share mode, security, creation disposition, flags and attributes, template file)
WriteFile(handle, buffer, number of bytes to write, return number of bytes written, overlapped)
We now can get to putting the picture together
| Code: |
BITMAPINFO bInfo;
bInfo.bmiHeader = bInfoHeader;
BYTE* bBuff = 0;
HBITMAP hBitmap = CreateDIBSection(hdcSrc, &bInfo, DIB_RGB_COLORS, (void**)&bBuff, 0, 0);
SelectObject(hdcDes, hBitmap);
BitBlt(hdcDes, 0, 0, iWidth, iHeight, hdcSrc, 0, 0, SRCCOPY);
DeleteDC(hdcDes);
ReleaseDC(hDeskHandle, hdcSrc);
// number of bytes to write
int bytes = (((24*iWidth + 31) & (~31)) / 8) * iHeight;
WriteFile(hFile, bBuff,(DWORD)bytes, &d, NULL);
CloseHandle(hFile);
DeleteObject(hBitmap);
|
BITMAPINFO http://msdn2.microsoft.com/en-us/library/aa921550.aspx
CreateDIBSection http://msdn2.microsoft.com/en-us/library/ms532292.aspx
SelectObject http://msdn2.microsoft.com/en-us/library/aa932923.aspx
BitBlt http://msdn2.microsoft.com/en-us/library/ms532278.aspx
DeleteDC - deletes the given device context
ReleaseDC – frees the device context so it can be used by other applications.
CloseHandle – closes open handle
DeleteObject – deletes the object (i.e. bitmap, pen, brush, font, etc.)
You can now take screen shots of your desktop. Once you understand it a little bit more, experiment with the code. Source code is also attached.
|
|
| Back to top |
|
 |
appalsap Moderator
Reputation: 0
Joined: 27 Apr 2006 Posts: 6753 Location: Pakistan
|
Posted: Wed Oct 10, 2007 9:47 pm Post subject: |
|
|
| Beautiful.
|
|
| Back to top |
|
 |
Trow Grandmaster Cheater
Reputation: 2
Joined: 17 Aug 2006 Posts: 957
|
Posted: Thu Oct 11, 2007 8:12 am Post subject: |
|
|
id hit that (still reading)
edit: everyone's good (seen before) besides the bitmap headers and stuff. supposedly its right
_________________
Get kidnapped often.
Last edited by Trow on Thu Oct 11, 2007 8:18 am; edited 1 time in total |
|
| Back to top |
|
 |
oib111 I post too much
Reputation: 0
Joined: 02 Apr 2007 Posts: 2947 Location: you wanna know why?
|
Posted: Thu Oct 11, 2007 8:17 am Post subject: |
|
|
This is awesome. And you got praise from appalsap, so you know its good.
_________________
| 8D wrote: |
cigs dont make people high, which weed does, which causes them to do bad stuff. like killing |
|
|
| Back to top |
|
 |
|
|
You cannot post new topics in this forum You cannot reply to topics in this forum You cannot edit your posts in this forum You cannot delete your posts in this forum You cannot vote in polls in this forum You cannot attach files in this forum You can download files in this forum
|
|