Compare commits
4 commits
cc5c051a33
...
94989c680a
Author | SHA1 | Date | |
---|---|---|---|
snow flurry | 94989c680a | ||
snow flurry | dc07b5e612 | ||
snow flurry | 7d1c91401f | ||
snow flurry | d64803c1a9 |
27
Bitmap.c
27
Bitmap.c
|
@ -36,6 +36,9 @@ void
|
|||
DeleteScreen(Screen *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->hdcBitmap) DeleteDC(scrn->hdcBitmap);
|
||||
if (scrn->hdcScreen) DeleteDC(scrn->hdcScreen);
|
||||
|
@ -57,9 +60,13 @@ PFULLBMPHDR
|
|||
GenerateBitmapInfo(Screen *scrn,
|
||||
BITMAP *bmp)
|
||||
{
|
||||
PFULLBMPHDR pBmpHdr = HeapAlloc(GetProcessHeap(),
|
||||
// GDI seems to modify the DWORD after the info header, even if we
|
||||
// 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,
|
||||
sizeof(struct _FULLBMPHDR));
|
||||
sizeof(struct _FULLBMPHDR) + sizeof(RGBQUAD));
|
||||
RECT rcScrn = {0};
|
||||
WORD cClrBits = (WORD)(bmp->bmPlanes * bmp->bmBitsPixel);
|
||||
DWORD hdrSize;
|
||||
|
@ -67,6 +74,7 @@ GenerateBitmapInfo(Screen *scrn,
|
|||
if (!pBmpHdr) return NULL;
|
||||
|
||||
if (!GetRgnBox(scrn->hScreenRgn, &rcScrn)) {
|
||||
HeapFree(hHeap, 0, pBmpHdr);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
|
@ -156,7 +164,8 @@ WriteRegionToFile(Screen *scrn,
|
|||
LPTSTR fname)
|
||||
{
|
||||
BITMAP bmp = {0}; // hBitmap's metadata
|
||||
HANDLE hOutFile = NULL; // Output .bmp
|
||||
HANDLE hOutFile = NULL, // Output .bmp
|
||||
hHeap = GetProcessHeap();
|
||||
LPBYTE lpBits = NULL; // Actual bitmap bits
|
||||
|
||||
HDC hdcRgn = NULL; // HDC for defined region
|
||||
|
@ -236,7 +245,7 @@ WriteRegionToFile(Screen *scrn,
|
|||
goto cleanup;
|
||||
}
|
||||
|
||||
lpBits = HeapAlloc(GetProcessHeap(),
|
||||
lpBits = HeapAlloc(hHeap,
|
||||
0,
|
||||
pHdr->info.biSizeImage);
|
||||
if (!lpBits) {
|
||||
|
@ -245,7 +254,7 @@ WriteRegionToFile(Screen *scrn,
|
|||
}
|
||||
|
||||
if (pHdr->info.biBitCount <= 8) {
|
||||
pbmi = HeapAlloc(GetProcessHeap(),
|
||||
pbmi = HeapAlloc(hHeap,
|
||||
HEAP_ZERO_MEMORY,
|
||||
sizeof(BITMAPINFOHEADER) +
|
||||
(pHdr->info.biClrUsed * sizeof(RGBQUAD)));
|
||||
|
@ -329,18 +338,16 @@ cleanup:
|
|||
}
|
||||
}
|
||||
|
||||
if (lpBits) HeapFree(GetProcessHeap(), 0, lpBits);
|
||||
if (lpBits) HeapFree(hHeap, 0, lpBits);
|
||||
|
||||
// In case our bits are <= 8, pbmi will be an actual heap-alloc'd
|
||||
// pointer. Let's make sure to handle that.
|
||||
if (pbmi && pbmi != (PBITMAPINFO) &pHdr->info) HeapFree(GetProcessHeap(), 0, pbmi);
|
||||
if (pbmi && pbmi != (PBITMAPINFO) &pHdr->info) HeapFree(hHeap, 0, pbmi);
|
||||
|
||||
if (pHdr) HeapFree(GetProcessHeap(), 0, pHdr);
|
||||
if (pHdr) HeapFree(hHeap, 0, pHdr);
|
||||
|
||||
if (scrn->hOldObj) SelectObject(scrn->hdcBitmap, scrn->hOldObj);
|
||||
if (hOldObj) SelectObject(hdcRgn, hOldObj);
|
||||
if (hRgnBitmap) DeleteObject(hRgnBitmap);
|
||||
if (scrn->hBitmap) DeleteObject(scrn->hBitmap);
|
||||
|
||||
if (hdcRgn) DeleteDC(hdcRgn);
|
||||
|
||||
|
|
28
Grabby.c
28
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");
|
||||
}
|
||||
|
||||
|
|
12
Overlay.c
12
Overlay.c
|
@ -187,7 +187,11 @@ OverlayWndProc(HWND hWnd,
|
|||
(ptCur.y != ptStart.y))
|
||||
{
|
||||
RECT rcPrevDmg = POINT2RECT(ptStart, ptPrev);
|
||||
// InvalidateRect(hWnd, &rcCurDmg, TRUE);
|
||||
// Expand out a little bit to contain the focus rect
|
||||
rcPrevDmg.left--;
|
||||
rcPrevDmg.right++;
|
||||
rcPrevDmg.top--;
|
||||
rcPrevDmg.bottom++;
|
||||
InvalidateRect(hWnd, &rcPrevDmg, TRUE);
|
||||
}
|
||||
|
||||
|
@ -211,8 +215,10 @@ OverlayWndProc(HWND hWnd,
|
|||
}
|
||||
break;
|
||||
case WM_KEYUP:
|
||||
// TODO: Escape
|
||||
break;
|
||||
if (wParam != VK_ESCAPE) {
|
||||
break;
|
||||
}
|
||||
/* PASSTHRU */
|
||||
case WM_RBUTTONUP:
|
||||
// We treat right click as Escape
|
||||
PostQuitMessage(1);
|
||||
|
|
Loading…
Reference in a new issue