From 94989c680a574691938e32150fcc41f1a1aa9fa4 Mon Sep 17 00:00:00 2001 From: snow flurry Date: Thu, 15 Feb 2024 07:32:20 +0000 Subject: [PATCH] Grabby: Write the screenshot to %TEMP% Means I don't have to ignore *.bmp in the repo. I'll probably make this user-configurable, once we have a configuration system in place. git-svn-id: svn://vcs.sdm.2ki.xyz/Grabby/trunk@14 27729192-006e-004d-b9b5-06fbd0ef7001 --- Grabby.c | 28 +++++++++++++++++++++++++++- stdafx.h | 2 +- 2 files changed, 28 insertions(+), 2 deletions(-) diff --git a/Grabby.c b/Grabby.c index 003e13e..d44d8b9 100644 --- a/Grabby.c +++ b/Grabby.c @@ -59,8 +59,14 @@ int APIENTRY _tWinMain(HINSTANCE hInstance, LPTSTR lpCmdLine, int nCmdShow) { + SYSTEMTIME stNow = {0}; RECT capRegion = {0}; Screen *scrn = CreateScreen(); +#define OUTPUT_DIR_LEN 96 + TCHAR szOutputDir[OUTPUT_DIR_LEN + 1]; +#define FULL_OUT_PATH_LEN OUTPUT_DIR_LEN + 24 + TCHAR szFullOutPath[FULL_OUT_PATH_LEN + 1]; + HRESULT hRes; if (!scrn) { Die("Couldn't get screen information"); @@ -80,8 +86,28 @@ int APIENTRY _tWinMain(HINSTANCE hInstance, GetChosenRect(&capRegion); + if (!GetTempPath(OUTPUT_DIR_LEN, szOutputDir)) { + Die("Couldn't get temporary directory"); + } - if (WriteRegionToFile(scrn, &capRegion, _T("test.bmp")) == -1) { + GetLocalTime(&stNow); + + hRes = StringCchPrintf(szFullOutPath, + FULL_OUT_PATH_LEN, + "%s\\scrn_%04d%02d%02d_%02d%02d%02d.bmp", + szOutputDir, + stNow.wYear, + stNow.wMonth, + stNow.wDay, + stNow.wHour, + stNow.wMinute, + stNow.wSecond); + + if (FAILED(hRes)) { + Die("Couldn't create screenshot file path"); + } + + if (WriteRegionToFile(scrn, &capRegion, szFullOutPath) == -1) { Die("Couldn't grab region of the screen"); } diff --git a/stdafx.h b/stdafx.h index 8ee51eb..6319016 100644 --- a/stdafx.h +++ b/stdafx.h @@ -16,4 +16,4 @@ #include #include -// TODO: reference additional headers your program requires here +#include