桌面截图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
    }

苟命哥
0 声望0 粉丝