window笔记 桌面截图api
文章目录
桌面截图api
void SystemPlugin::Screenshot()
{
RECT rect;
HWND hwnd = GetDesktopWindow();
GetWindowRect(hwnd, &rect);
HDC winDC = ::GetDC(hwnd);
int nBPP = GetDeviceCaps(winDC,BITSPIXEL) * GetDeviceCaps(winDC,PLANES);
if (nBPP < 24) nBPP = 24;
CImage image;
BOOL bStat = image.Create((rect.right - rect.left), (rect.bottom - rect.top) , nBPP);
CImageDC imageDC(image);
::BitBlt(image.GetDC(), rect.left, rect.top, (rect.right - rect.left) , (rect.bottom - rect.top),
winDC, rect.left, rect.top, SRCCOPY);
HRESULT hr = image.Save(L"D:\\out.jpg");
image.ReleaseDC();
}高斯模糊:并非所有电脑有效
HMODULE hMod = LoadLibrary(L"user32.dll");
if (hMod != NULL) {
pfnGWA getWindowAttribute = (pfnGWA)GetProcAddress(hMod, "SetWindowCompositionAttribute");
if (getWindowAttribute != NULL) {
AccentPolicy policy = { };
policy.accentState = ACCENT_ENABLE_BLURBEHIND;
WINCOMPATTRDATA windata = { };
windata.attribute = WCA_ACCENT_POLICY;
windata.pData = &policy;
windata.dataSize = sizeof(policy);
BOOL res = getWindowAttribute(hwnd, &windata);
if (!res) {
//TODO log
}
}
else {
//TODO log
}
FreeLibrary(hMod);
}
else {
//TODO log
}
评论
登录后参与技术讨论,分享你的经验与见解。
登录 / 注册暂无评论