// ConsoleApplication10.cpp : This file contains the 'main' function. Program execution begins and ends there.
//
#include <windows.h>
#include <iostream>
#include <gdiplus.h>
#pragma comment(lib, "GdiPlus.lib")
using namespace Gdiplus;
static const GUID png =
{0x557cf406, 0x1a04, 0x11d3, {0x9a, 0x73, 0x00, 0x00, 0xf8, 0x1e, 0xf3, 0x2e}};
int main(void)
{
GdiplusStartupInput gdiplusStartupInput;
ULONG_PTR gdiplusToken;
GdiplusStartup(&gdiplusToken, &gdiplusStartupInput, NULL);
HDC window_dc, memdc;
HBITMAP membit;
// Получаем DC окна по его HWND
HWND window_handle = FindWindowA(0, "GTA SA:MP");
window_dc = GetDC(window_handle);
// Определяем разрешение экрана
int Height, Width;
Height = GetSystemMetrics(SM_CYSCREEN);
Width = GetSystemMetrics(SM_CXSCREEN);
// Создаем новый DC, идентичный десктоповскому и битмап размером с экран.
memdc = CreateCompatibleDC(window_dc);
membit = CreateCompatibleBitmap(window_dc, Width, Height);
SelectObject(memdc, membit);
// Улыбаемся... Снято!
BitBlt(memdc, 0, 0, Width, Height, window_dc, 0, 0, SRCCOPY);
HBITMAP hBitmap;
hBitmap = (HBITMAP)SelectObject(memdc, membit);
Gdiplus::Bitmap bitmap(hBitmap, NULL);
bitmap.Save(L"screen.png", &png);
DeleteObject(hBitmap);
return 0;
}