Скриншот экрана + мб кодировка
Скриншот экрана + мб кодировка
This commit is contained in:
parent
e5eb712517
commit
a5e6d46015
@ -50,7 +50,7 @@
|
||||
<UseDebugLibraries>false</UseDebugLibraries>
|
||||
<PlatformToolset>v143</PlatformToolset>
|
||||
<WholeProgramOptimization>true</WholeProgramOptimization>
|
||||
<CharacterSet>Unicode</CharacterSet>
|
||||
<CharacterSet>MultiByte</CharacterSet>
|
||||
</PropertyGroup>
|
||||
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.props" />
|
||||
<ImportGroup Label="ExtensionSettings">
|
||||
|
@ -1,15 +1,83 @@
|
||||
#include <Windows.h>
|
||||
#include <chrono>
|
||||
#include <Dwmapi.h>
|
||||
#include <iostream>
|
||||
#include <fstream>
|
||||
#pragma comment(lib, "dwmapi.lib")
|
||||
#pragma warning(disable : 4996)
|
||||
|
||||
const MARGINS margins = { -1 ,-1, -1, -1 };
|
||||
const wchar_t g_szClassName[] = L"overlay";
|
||||
const char g_szClassName[] = "overlay";
|
||||
bool isVisible = true;
|
||||
|
||||
void addWatermark(HDC hdc, HDC hdcDIB, BITMAPINFO bmi)
|
||||
{
|
||||
HFONT hFont;
|
||||
LOGFONT lf = { 0 };
|
||||
lf.lfHeight = -MulDiv(20, GetDeviceCaps(hdc, LOGPIXELSY), 72); // ðàçìåð øðèôòà
|
||||
lf.lfWeight = FW_NORMAL; // æèðíîñòü øðèôòà
|
||||
lf.lfCharSet = DEFAULT_CHARSET;
|
||||
lf.lfOutPrecision = OUT_TT_PRECIS;
|
||||
lf.lfClipPrecision = CLIP_DEFAULT_PRECIS;
|
||||
lf.lfQuality = DEFAULT_QUALITY;
|
||||
lf.lfPitchAndFamily = DEFAULT_PITCH | FF_DONTCARE;
|
||||
strcpy_s(lf.lfFaceName, "Arial");
|
||||
|
||||
hFont = CreateFontIndirect(&lf);
|
||||
SelectObject(hdcDIB, hFont);
|
||||
|
||||
std::string watermark = "vos.team";
|
||||
|
||||
SetTextColor(hdcDIB, RGB(255, 0, 255, 128));
|
||||
SetBkMode(hdcDIB, TRANSPARENT);
|
||||
TextOut(hdcDIB, 10, 10, watermark.c_str(), watermark.length());
|
||||
DeleteObject(hFont);
|
||||
}
|
||||
|
||||
void captureScreen(std::string file_Name)
|
||||
{
|
||||
HDC hdcScreen;
|
||||
HDC hdcDIB;
|
||||
HBITMAP hbmDIB;
|
||||
BITMAPINFO bmi;
|
||||
LPVOID lpvBits;
|
||||
HANDLE hFile;
|
||||
DWORD dwBytesWritten;
|
||||
|
||||
|
||||
hdcScreen = GetDC(NULL);
|
||||
hdcDIB = CreateCompatibleDC(hdcScreen);
|
||||
ZeroMemory(&bmi, sizeof(BITMAPINFO));
|
||||
bmi.bmiHeader.biSize = sizeof(BITMAPINFOHEADER);
|
||||
bmi.bmiHeader.biWidth = GetSystemMetrics(SM_CXSCREEN);
|
||||
bmi.bmiHeader.biHeight = GetSystemMetrics(SM_CYSCREEN);
|
||||
bmi.bmiHeader.biPlanes = 1;
|
||||
bmi.bmiHeader.biBitCount = 24;
|
||||
bmi.bmiHeader.biCompression = BI_RGB;
|
||||
hbmDIB = CreateDIBSection(hdcScreen, &bmi, DIB_RGB_COLORS, &lpvBits, NULL, 0);
|
||||
SelectObject(hdcDIB, hbmDIB);
|
||||
BitBlt(hdcDIB, 0, 0, bmi.bmiHeader.biWidth, bmi.bmiHeader.biHeight, hdcScreen, 0, 0, SRCCOPY);
|
||||
|
||||
// Äîáàâëåíèå âàòåðìàðêè íà êîíòåêñò
|
||||
addWatermark(hdcScreen, hdcDIB, bmi);
|
||||
|
||||
hFile = CreateFile(("C:\\Users\\" + (std::string)std::getenv("USERNAME") + "\\Documents\\vos.team\\" + file_Name).c_str(), GENERIC_WRITE, 0, NULL, CREATE_ALWAYS, FILE_ATTRIBUTE_NORMAL, NULL);
|
||||
BITMAPFILEHEADER hdr = { };
|
||||
hdr.bfType = 0x4d42; // Áóêâû 'B' è 'M'
|
||||
hdr.bfOffBits = sizeof(hdr) + sizeof(BITMAPINFOHEADER);
|
||||
hdr.bfSize = hdr.bfOffBits + bmi.bmiHeader.biWidth * bmi.bmiHeader.biHeight * 3;
|
||||
WriteFile(hFile, &hdr, sizeof(hdr), &dwBytesWritten, NULL);
|
||||
WriteFile(hFile, &bmi.bmiHeader, sizeof(BITMAPINFOHEADER), &dwBytesWritten, NULL);
|
||||
WriteFile(hFile, lpvBits, bmi.bmiHeader.biWidth * bmi.bmiHeader.biHeight * 3, &dwBytesWritten, NULL);
|
||||
CloseHandle(hFile);
|
||||
DeleteObject(hbmDIB);
|
||||
DeleteDC(hdcDIB);
|
||||
ReleaseDC(NULL, hdcScreen);
|
||||
}
|
||||
|
||||
LRESULT CALLBACK WndProc(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam)
|
||||
{
|
||||
std::string file_Name = "screenshot_" + std::to_string(time(NULL)) + ".bmp";
|
||||
switch (msg)
|
||||
{
|
||||
case WM_HOTKEY:
|
||||
@ -22,6 +90,10 @@ LRESULT CALLBACK WndProc(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam)
|
||||
{
|
||||
DestroyWindow(hwnd);
|
||||
}
|
||||
else if (wParam == 3)
|
||||
{
|
||||
captureScreen(file_Name);
|
||||
}
|
||||
break;
|
||||
case WM_PAINT:
|
||||
{
|
||||
@ -35,10 +107,10 @@ LRESULT CALLBACK WndProc(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam)
|
||||
auto currentTime = std::chrono::system_clock::now();
|
||||
auto currentTime_t = std::chrono::system_clock::to_time_t(currentTime);
|
||||
|
||||
wchar_t timeStr[100];
|
||||
wcsftime(timeStr, 100, L"Time: %H:%M:%S", std::localtime(¤tTime_t));
|
||||
char timeStr[100];
|
||||
strftime(timeStr, 100, "Time: %H:%M:%S", std::localtime(¤tTime_t));
|
||||
|
||||
TextOut(hdc, x, y, timeStr, wcslen(timeStr));
|
||||
TextOut(hdc, x, y, timeStr, strlen(timeStr));
|
||||
EndPaint(hwnd, &ps);
|
||||
}
|
||||
break;
|
||||
@ -85,6 +157,7 @@ int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine
|
||||
|
||||
RegisterHotKey(hwnd, 1, MOD_ALT, 0x5A);
|
||||
RegisterHotKey(hwnd, 2, MOD_ALT, 0x58);
|
||||
RegisterHotKey(hwnd, 3, MOD_ALT, 0x50);
|
||||
|
||||
while (GetMessage(&Msg, NULL, 0, 0) > 0)
|
||||
{
|
||||
@ -101,6 +174,7 @@ int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine
|
||||
|
||||
UnregisterHotKey(hwnd, 1);
|
||||
UnregisterHotKey(hwnd, 2);
|
||||
UnregisterHotKey(hwnd, 3);
|
||||
|
||||
exit(0);
|
||||
return Msg.wParam;
|
||||
|
Loading…
Reference in New Issue
Block a user