|
|
@ -21,6 +21,7 @@ void doScreenshot(); |
|
|
|
void InitNotifyIconData(); |
|
|
|
int CaptureImage(HWND hWnd, const wchar_t* filename); |
|
|
|
void getRaspiStorage(LPWSTR out); |
|
|
|
void SavePng(HBITMAP hBmp, LPCWSTR lpszFilename); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@ -254,6 +255,7 @@ void doScreenshot() |
|
|
|
{ |
|
|
|
WCHAR path[12]; |
|
|
|
getRaspiStorage(path); |
|
|
|
MessageBox(Hwnd, path, L"Storage path", MB_OK); |
|
|
|
CaptureImage(Hwnd, L"file.bmp"); |
|
|
|
} |
|
|
|
|
|
|
@ -299,7 +301,7 @@ void getRaspiStorage(LPWSTR out) { |
|
|
|
if (GetVolumeInformationW(drive, volumeName, ARRAYSIZE(volumeName), &serialNumber, &maxComponentLen, &fileSystemFlags, fileSystemName, ARRAYSIZE(fileSystemName))) |
|
|
|
{ |
|
|
|
if (wcscmp(volumeName, L"SCREENSHOTS")) { |
|
|
|
wcsncpy(drive, out, sizeof(out)); |
|
|
|
wcsncpy(out, drive, sizeof(out)); |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
@ -405,6 +407,9 @@ int CaptureImage(HWND hWnd, const wchar_t* filename) { |
|
|
|
return -1; |
|
|
|
} |
|
|
|
|
|
|
|
SavePng(hBmp, filename); |
|
|
|
|
|
|
|
/*
|
|
|
|
// Get the BITMAP from the HBITMAP
|
|
|
|
GetObject(hBmp,sizeof(BITMAP),&bmpScreen); |
|
|
|
|
|
|
@ -469,7 +474,7 @@ int CaptureImage(HWND hWnd, const wchar_t* filename) { |
|
|
|
|
|
|
|
//Close the handle for the file that was created
|
|
|
|
CloseHandle(hFile); |
|
|
|
|
|
|
|
*/ |
|
|
|
// clean up
|
|
|
|
DeleteObject(hbmScreen); |
|
|
|
DeleteObject(hBmp); |
|
|
@ -518,22 +523,38 @@ int GetEncoderClsid(const WCHAR* format, CLSID* pClsid) |
|
|
|
* https://stackoverflow.com/questions/997175/how-can-i-take-a-screenshot-and-save-it-as-jpeg-on-windows
|
|
|
|
* https://docs.microsoft.com/en-us/windows/desktop/gdiplus/-gdiplus-converting-a-bmp-image-to-a-png-image-use
|
|
|
|
*/ |
|
|
|
void SaveJpeg(HBITMAP hBmp, LPCWSTR lpszFilename, ULONG uQuality) |
|
|
|
void SavePng(HBITMAP hBmp, LPCWSTR lpszFilename) |
|
|
|
{ |
|
|
|
//using namespace Gdiplus;
|
|
|
|
using namespace Gdiplus; |
|
|
|
|
|
|
|
// Initialize GDI+.
|
|
|
|
GdiplusStartupInput gdiplusStartupInput; |
|
|
|
ULONG_PTR gdiplusToken; |
|
|
|
GdiplusStartup(&gdiplusToken, &gdiplusStartupInput, NULL); |
|
|
|
|
|
|
|
Gdiplus::GpBitmap* pBitmap; |
|
|
|
Gdiplus::DllExports::GdipCreateBitmapFromHBITMAP(hBmp, NULL, &pBitmap); |
|
|
|
|
|
|
|
CLSID imageCLSID; |
|
|
|
GetEncoderClsid(L"image/jpeg", &imageCLSID); |
|
|
|
INT result; |
|
|
|
result = GetEncoderClsid(L"image/png", &imageCLSID); |
|
|
|
|
|
|
|
Gdiplus::EncoderParameters encoderParams; |
|
|
|
if (result < 0) { |
|
|
|
MessageBox(Hwnd, L"The PNG encoder is not installed",L"Failed", MB_OK); |
|
|
|
return; |
|
|
|
} |
|
|
|
|
|
|
|
/* Gdiplus::EncoderParameters encoderParams;
|
|
|
|
encoderParams.Count = 1; |
|
|
|
encoderParams.Parameter[0].NumberOfValues = 1; |
|
|
|
encoderParams.Parameter[0].Guid = Gdiplus::EncoderQuality; |
|
|
|
encoderParams.Parameter[0].Type = Gdiplus::EncoderParameterValueTypeLong; |
|
|
|
encoderParams.Parameter[0].Value = &uQuality; |
|
|
|
encoderParams.Parameter[0].Value = &uQuality;*/ |
|
|
|
|
|
|
|
Gdiplus::DllExports::GdipSaveImageToFile(pBitmap, lpszFilename, &imageCLSID, NULL); |
|
|
|
|
|
|
|
DeleteObject(pBitmap); |
|
|
|
|
|
|
|
Gdiplus::DllExports::GdipSaveImageToFile(pBitmap, lpszFilename, &imageCLSID, &encoderParams); |
|
|
|
GdiplusShutdown(gdiplusToken); |
|
|
|
} |
|
|
|
|
|
|
|