#include <windows.h>
#include <gdiplus.h>
#include <iostream>
#pragma comment(lib, "gdiplus.lib")
void SaveScreenshotAsJPG(const std::wstring& filename) {
// Captura la pantalla
HDC hScreenDC = GetDC(NULL);
HDC hMemoryDC = CreateCompatibleDC(hScreenDC);
int width = GetSystemMetrics(SM_CXSCREEN);
int height = GetSystemMetrics(SM_CYSCREEN);
HBITMAP hBitmap = CreateCompatibleBitmap(hScreenDC, width, height);
SelectObject(hMemoryDC, hBitmap);
BitBlt(hMemoryDC, 0, 0, width, height, hScreenDC, 0, 0, SRCCOPY);
// Guarda la imagen como JPG
Gdiplus::GdiplusStartupInput gdiplusStartupInput;
ULONG_PTR gdiplusToken;
Gdiplus::GdiplusStartup(&gdiplusToken, &gdiplusStartupInput, NULL);
Gdiplus::Bitmap bitmap(hBitmap, NULL);
CLSID clsid;
CLSIDFromString(L"{557CF400-1A04-11D3-9A26-00C04F79DBC0}", &clsid); // CLSID para JPG
bitmap.Save(filename.c_str(), &clsid, NULL);
// Limpieza
DeleteObject(hBitmap);
DeleteDC(hMemoryDC);
ReleaseDC(NULL, hScreenDC);
Gdiplus::GdiplusShutdown(gdiplusToken);
}
int main() {
// Abre Internet Explorer
ShellExecute(NULL, L"open", L"iexplore.exe", L"https://www.ejemplo.com", NULL, SW_SHOWNORMAL);
// Espera un tiempo para que la página cargue (ajusta según sea necesario)
Sleep(5000);
// Guarda la captura de pantalla como JPG
SaveScreenshotAsJPG(L"screenshot.jpg");
return 0;
}