Compare commits

..

No commits in common. "94989c680a574691938e32150fcc41f1a1aa9fa4" and "cc5c051a33c407e6959ab4148c33c46c744c0f5c" have entirely different histories.

4 changed files with 15 additions and 54 deletions

View file

@ -36,9 +36,6 @@ 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);
@ -60,13 +57,9 @@ PFULLBMPHDR
GenerateBitmapInfo(Screen *scrn,
BITMAP *bmp)
{
// 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,
PFULLBMPHDR pBmpHdr = HeapAlloc(GetProcessHeap(),
HEAP_ZERO_MEMORY,
sizeof(struct _FULLBMPHDR) + sizeof(RGBQUAD));
sizeof(struct _FULLBMPHDR));
RECT rcScrn = {0};
WORD cClrBits = (WORD)(bmp->bmPlanes * bmp->bmBitsPixel);
DWORD hdrSize;
@ -74,7 +67,6 @@ GenerateBitmapInfo(Screen *scrn,
if (!pBmpHdr) return NULL;
if (!GetRgnBox(scrn->hScreenRgn, &rcScrn)) {
HeapFree(hHeap, 0, pBmpHdr);
return NULL;
}
@ -164,8 +156,7 @@ WriteRegionToFile(Screen *scrn,
LPTSTR fname)
{
BITMAP bmp = {0}; // hBitmap's metadata
HANDLE hOutFile = NULL, // Output .bmp
hHeap = GetProcessHeap();
HANDLE hOutFile = NULL; // Output .bmp
LPBYTE lpBits = NULL; // Actual bitmap bits
HDC hdcRgn = NULL; // HDC for defined region
@ -245,7 +236,7 @@ WriteRegionToFile(Screen *scrn,
goto cleanup;
}
lpBits = HeapAlloc(hHeap,
lpBits = HeapAlloc(GetProcessHeap(),
0,
pHdr->info.biSizeImage);
if (!lpBits) {
@ -254,7 +245,7 @@ WriteRegionToFile(Screen *scrn,
}
if (pHdr->info.biBitCount <= 8) {
pbmi = HeapAlloc(hHeap,
pbmi = HeapAlloc(GetProcessHeap(),
HEAP_ZERO_MEMORY,
sizeof(BITMAPINFOHEADER) +
(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
// 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 (hRgnBitmap) DeleteObject(hRgnBitmap);
if (scrn->hBitmap) DeleteObject(scrn->hBitmap);
if (hdcRgn) DeleteDC(hdcRgn);

View file

@ -59,14 +59,8 @@ 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");
@ -86,28 +80,8 @@ int APIENTRY _tWinMain(HINSTANCE hInstance,
GetChosenRect(&capRegion);
if (!GetTempPath(OUTPUT_DIR_LEN, szOutputDir)) {
Die("Couldn't get temporary directory");
}
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) {
if (WriteRegionToFile(scrn, &capRegion, _T("test.bmp")) == -1) {
Die("Couldn't grab region of the screen");
}

View file

@ -187,11 +187,7 @@ OverlayWndProc(HWND hWnd,
(ptCur.y != ptStart.y))
{
RECT rcPrevDmg = POINT2RECT(ptStart, ptPrev);
// Expand out a little bit to contain the focus rect
rcPrevDmg.left--;
rcPrevDmg.right++;
rcPrevDmg.top--;
rcPrevDmg.bottom++;
// InvalidateRect(hWnd, &rcCurDmg, TRUE);
InvalidateRect(hWnd, &rcPrevDmg, TRUE);
}
@ -215,10 +211,8 @@ OverlayWndProc(HWND hWnd,
}
break;
case WM_KEYUP:
if (wParam != VK_ESCAPE) {
// TODO: Escape
break;
}
/* PASSTHRU */
case WM_RBUTTONUP:
// We treat right click as Escape
PostQuitMessage(1);

View file

@ -16,4 +16,4 @@
#include <stdio.h>
#include <tchar.h>
#include <Strsafe.h>
// TODO: reference additional headers your program requires here