Compare commits
No commits in common. "94989c680a574691938e32150fcc41f1a1aa9fa4" and "cc5c051a33c407e6959ab4148c33c46c744c0f5c" have entirely different histories.
94989c680a
...
cc5c051a33
27
Bitmap.c
27
Bitmap.c
|
@ -36,9 +36,6 @@ void
|
||||||
DeleteScreen(Screen *scrn)
|
DeleteScreen(Screen *scrn)
|
||||||
{
|
{
|
||||||
if (scrn) {
|
if (scrn) {
|
||||||
if (scrn->hOldObj) SelectObject(scrn->hdcBitmap, scrn->hOldObj);
|
|
||||||
if (scrn->hBitmap) DeleteObject(scrn->hBitmap);
|
|
||||||
|
|
||||||
if (scrn->hScreenRgn) DeleteObject((HGDIOBJ) scrn->hScreenRgn);
|
if (scrn->hScreenRgn) DeleteObject((HGDIOBJ) scrn->hScreenRgn);
|
||||||
if (scrn->hdcBitmap) DeleteDC(scrn->hdcBitmap);
|
if (scrn->hdcBitmap) DeleteDC(scrn->hdcBitmap);
|
||||||
if (scrn->hdcScreen) DeleteDC(scrn->hdcScreen);
|
if (scrn->hdcScreen) DeleteDC(scrn->hdcScreen);
|
||||||
|
@ -60,13 +57,9 @@ PFULLBMPHDR
|
||||||
GenerateBitmapInfo(Screen *scrn,
|
GenerateBitmapInfo(Screen *scrn,
|
||||||
BITMAP *bmp)
|
BITMAP *bmp)
|
||||||
{
|
{
|
||||||
// GDI seems to modify the DWORD after the info header, even if we
|
PFULLBMPHDR pBmpHdr = HeapAlloc(GetProcessHeap(),
|
||||||
// don't need a palette (>8 bit BMPs). Thus, an extra RGBQUAD just
|
|
||||||
// to be safe.
|
|
||||||
HANDLE hHeap = GetProcessHeap();
|
|
||||||
PFULLBMPHDR pBmpHdr = HeapAlloc(hHeap,
|
|
||||||
HEAP_ZERO_MEMORY,
|
HEAP_ZERO_MEMORY,
|
||||||
sizeof(struct _FULLBMPHDR) + sizeof(RGBQUAD));
|
sizeof(struct _FULLBMPHDR));
|
||||||
RECT rcScrn = {0};
|
RECT rcScrn = {0};
|
||||||
WORD cClrBits = (WORD)(bmp->bmPlanes * bmp->bmBitsPixel);
|
WORD cClrBits = (WORD)(bmp->bmPlanes * bmp->bmBitsPixel);
|
||||||
DWORD hdrSize;
|
DWORD hdrSize;
|
||||||
|
@ -74,7 +67,6 @@ GenerateBitmapInfo(Screen *scrn,
|
||||||
if (!pBmpHdr) return NULL;
|
if (!pBmpHdr) return NULL;
|
||||||
|
|
||||||
if (!GetRgnBox(scrn->hScreenRgn, &rcScrn)) {
|
if (!GetRgnBox(scrn->hScreenRgn, &rcScrn)) {
|
||||||
HeapFree(hHeap, 0, pBmpHdr);
|
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -164,8 +156,7 @@ WriteRegionToFile(Screen *scrn,
|
||||||
LPTSTR fname)
|
LPTSTR fname)
|
||||||
{
|
{
|
||||||
BITMAP bmp = {0}; // hBitmap's metadata
|
BITMAP bmp = {0}; // hBitmap's metadata
|
||||||
HANDLE hOutFile = NULL, // Output .bmp
|
HANDLE hOutFile = NULL; // Output .bmp
|
||||||
hHeap = GetProcessHeap();
|
|
||||||
LPBYTE lpBits = NULL; // Actual bitmap bits
|
LPBYTE lpBits = NULL; // Actual bitmap bits
|
||||||
|
|
||||||
HDC hdcRgn = NULL; // HDC for defined region
|
HDC hdcRgn = NULL; // HDC for defined region
|
||||||
|
@ -245,7 +236,7 @@ WriteRegionToFile(Screen *scrn,
|
||||||
goto cleanup;
|
goto cleanup;
|
||||||
}
|
}
|
||||||
|
|
||||||
lpBits = HeapAlloc(hHeap,
|
lpBits = HeapAlloc(GetProcessHeap(),
|
||||||
0,
|
0,
|
||||||
pHdr->info.biSizeImage);
|
pHdr->info.biSizeImage);
|
||||||
if (!lpBits) {
|
if (!lpBits) {
|
||||||
|
@ -254,7 +245,7 @@ WriteRegionToFile(Screen *scrn,
|
||||||
}
|
}
|
||||||
|
|
||||||
if (pHdr->info.biBitCount <= 8) {
|
if (pHdr->info.biBitCount <= 8) {
|
||||||
pbmi = HeapAlloc(hHeap,
|
pbmi = HeapAlloc(GetProcessHeap(),
|
||||||
HEAP_ZERO_MEMORY,
|
HEAP_ZERO_MEMORY,
|
||||||
sizeof(BITMAPINFOHEADER) +
|
sizeof(BITMAPINFOHEADER) +
|
||||||
(pHdr->info.biClrUsed * sizeof(RGBQUAD)));
|
(pHdr->info.biClrUsed * sizeof(RGBQUAD)));
|
||||||
|
@ -338,16 +329,18 @@ cleanup:
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (lpBits) HeapFree(hHeap, 0, lpBits);
|
if (lpBits) HeapFree(GetProcessHeap(), 0, lpBits);
|
||||||
|
|
||||||
// In case our bits are <= 8, pbmi will be an actual heap-alloc'd
|
// In case our bits are <= 8, pbmi will be an actual heap-alloc'd
|
||||||
// pointer. Let's make sure to handle that.
|
// pointer. Let's make sure to handle that.
|
||||||
if (pbmi && pbmi != (PBITMAPINFO) &pHdr->info) HeapFree(hHeap, 0, pbmi);
|
if (pbmi && pbmi != (PBITMAPINFO) &pHdr->info) HeapFree(GetProcessHeap(), 0, pbmi);
|
||||||
|
|
||||||
if (pHdr) HeapFree(hHeap, 0, pHdr);
|
if (pHdr) HeapFree(GetProcessHeap(), 0, pHdr);
|
||||||
|
|
||||||
|
if (scrn->hOldObj) SelectObject(scrn->hdcBitmap, scrn->hOldObj);
|
||||||
if (hOldObj) SelectObject(hdcRgn, hOldObj);
|
if (hOldObj) SelectObject(hdcRgn, hOldObj);
|
||||||
if (hRgnBitmap) DeleteObject(hRgnBitmap);
|
if (hRgnBitmap) DeleteObject(hRgnBitmap);
|
||||||
|
if (scrn->hBitmap) DeleteObject(scrn->hBitmap);
|
||||||
|
|
||||||
if (hdcRgn) DeleteDC(hdcRgn);
|
if (hdcRgn) DeleteDC(hdcRgn);
|
||||||
|
|
||||||
|
|
28
Grabby.c
28
Grabby.c
|
@ -59,14 +59,8 @@ int APIENTRY _tWinMain(HINSTANCE hInstance,
|
||||||
LPTSTR lpCmdLine,
|
LPTSTR lpCmdLine,
|
||||||
int nCmdShow)
|
int nCmdShow)
|
||||||
{
|
{
|
||||||
SYSTEMTIME stNow = {0};
|
|
||||||
RECT capRegion = {0};
|
RECT capRegion = {0};
|
||||||
Screen *scrn = CreateScreen();
|
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) {
|
if (!scrn) {
|
||||||
Die("Couldn't get screen information");
|
Die("Couldn't get screen information");
|
||||||
|
@ -86,28 +80,8 @@ int APIENTRY _tWinMain(HINSTANCE hInstance,
|
||||||
|
|
||||||
GetChosenRect(&capRegion);
|
GetChosenRect(&capRegion);
|
||||||
|
|
||||||
if (!GetTempPath(OUTPUT_DIR_LEN, szOutputDir)) {
|
|
||||||
Die("Couldn't get temporary directory");
|
|
||||||
}
|
|
||||||
|
|
||||||
GetLocalTime(&stNow);
|
if (WriteRegionToFile(scrn, &capRegion, _T("test.bmp")) == -1) {
|
||||||
|
|
||||||
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");
|
Die("Couldn't grab region of the screen");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
12
Overlay.c
12
Overlay.c
|
@ -187,11 +187,7 @@ OverlayWndProc(HWND hWnd,
|
||||||
(ptCur.y != ptStart.y))
|
(ptCur.y != ptStart.y))
|
||||||
{
|
{
|
||||||
RECT rcPrevDmg = POINT2RECT(ptStart, ptPrev);
|
RECT rcPrevDmg = POINT2RECT(ptStart, ptPrev);
|
||||||
// Expand out a little bit to contain the focus rect
|
// InvalidateRect(hWnd, &rcCurDmg, TRUE);
|
||||||
rcPrevDmg.left--;
|
|
||||||
rcPrevDmg.right++;
|
|
||||||
rcPrevDmg.top--;
|
|
||||||
rcPrevDmg.bottom++;
|
|
||||||
InvalidateRect(hWnd, &rcPrevDmg, TRUE);
|
InvalidateRect(hWnd, &rcPrevDmg, TRUE);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -215,10 +211,8 @@ OverlayWndProc(HWND hWnd,
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
case WM_KEYUP:
|
case WM_KEYUP:
|
||||||
if (wParam != VK_ESCAPE) {
|
// TODO: Escape
|
||||||
break;
|
break;
|
||||||
}
|
|
||||||
/* PASSTHRU */
|
|
||||||
case WM_RBUTTONUP:
|
case WM_RBUTTONUP:
|
||||||
// We treat right click as Escape
|
// We treat right click as Escape
|
||||||
PostQuitMessage(1);
|
PostQuitMessage(1);
|
||||||
|
|
Loading…
Reference in a new issue