日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 运维知识 > windows >内容正文

windows

windows抓屏排除指定窗口

發布時間:2024/3/12 windows 31 豆豆
生活随笔 收集整理的這篇文章主要介紹了 windows抓屏排除指定窗口 小編覺得挺不錯的,現在分享給大家,幫大家做個參考.

方式一:

BOOL SetWindowDisplayAffinity(HWND hWnd,DWORD dwAffinity );

hWnd:窗口句柄

dwAffinity:

#define WDA_NONE 0x00000000 #define WDA_MONITOR 0x00000001 #define WDA_EXCLUDEFROMCAPTURE 0x00000011

在beta版本下,才有WDA_EXCLUDEFROMCAPTURE

包含在:C:\Program Files (x86)\Windows Kits\10\Include\10.0.19041.0\um\WinUser.h

然鵝,經過測試,并沒有用,被排除的窗口,只是顯示成了黑框。失敗!

?

方式二(從webrtc M81摳的):

Windows放大鏡Magnification API

MagSetWindowFilterList Sets the list of windows to be magnified or the list of windows to be excluded from magnification.BOOL MagSetWindowFilterList(HWND hwnd,DWORD dwFilterMode,int count,HWND *pHWND );

接口MagSetWindowFilterList具有排除指定窗口的功能。

?

測試可行,只是稍顯復雜:

//excludewindow.h #pragma once#include <magnification.h> #include <wincodec.h> #include <windows.h>// kMagnifierWindowClass has to be "Magnifier" according to the Magnification // API. The other strings can be anything. static wchar_t kMagnifierHostClass[] = L"ScreenCapturerWinMagnifierHost"; static wchar_t kHostWindowName[] = L"MagnifierHost"; static wchar_t kMagnifierWindowClass[] = L"Magnifier"; static wchar_t kMagnifierWindowName[] = L"MagnifierWindow";class CExcludeWindow { public:CExcludeWindow();virtual ~CExcludeWindow();int SetExcludeWnd(HWND hWnd);bool Init();bool CaptureFrame(); private:typedef BOOL(WINAPI* MagImageScalingCallback)(HWND hwnd,void* srcdata,MAGIMAGEHEADER srcheader,void* destdata,MAGIMAGEHEADER destheader,RECT unclipped,RECT clipped,HRGN dirty);typedef BOOL(WINAPI* MagInitializeFunc)(void);typedef BOOL(WINAPI* MagUninitializeFunc)(void);typedef BOOL(WINAPI* MagSetWindowSourceFunc)(HWND hwnd, RECT rect);typedef BOOL(WINAPI* MagSetWindowFilterListFunc)(HWND hwnd,DWORD dwFilterMode,int count,HWND* pHWND);typedef BOOL(WINAPI* MagSetImageScalingCallbackFunc)(HWND hwnd,MagImageScalingCallback callback);static BOOL WINAPI OnMagImageScalingCallback(HWND hwnd,void* srcdata,MAGIMAGEHEADER srcheader,void* destdata,MAGIMAGEHEADER destheader,RECT unclipped,RECT clipped,HRGN dirty);void OnCaptured(void* data, const MAGIMAGEHEADER& header);HMODULE mag_lib_handle_ = NULL;MagInitializeFunc mag_initialize_func_ = nullptr;MagUninitializeFunc mag_uninitialize_func_ = nullptr;MagSetWindowSourceFunc set_window_source_func_ = nullptr;MagSetWindowFilterListFunc set_window_filter_list_func_ = nullptr;MagSetImageScalingCallbackFunc set_image_scaling_callback_func_ = nullptr;// The hidden window hosting the magnifier control.HWND host_window_ = NULL;// The magnifier control that captures the screen.HWND magnifier_window_ = NULL;// True if the magnifier control has been successfully initialized.bool magnifier_initialized_ = false;// True if the last OnMagImageScalingCallback was called and handled// successfully. Reset at the beginning of each CaptureImage call.bool magnifier_capture_succeeded_ = true; };

?

//excludewindow.cpp #include "excludewindow.h" #include <iostream>DWORD GetTlsIndex() {static const DWORD tls_index = TlsAlloc();return tls_index; }CExcludeWindow::CExcludeWindow() { }bool CExcludeWindow::Init() {mag_lib_handle_ = LoadLibraryW(L"Magnification.dll");if (!mag_lib_handle_)return false;// Initialize Magnification API function pointers.mag_initialize_func_ = reinterpret_cast<MagInitializeFunc>(GetProcAddress(mag_lib_handle_, "MagInitialize"));mag_uninitialize_func_ = reinterpret_cast<MagUninitializeFunc>(GetProcAddress(mag_lib_handle_, "MagUninitialize"));set_window_source_func_ = reinterpret_cast<MagSetWindowSourceFunc>(GetProcAddress(mag_lib_handle_, "MagSetWindowSource"));set_window_filter_list_func_ = reinterpret_cast<MagSetWindowFilterListFunc>(GetProcAddress(mag_lib_handle_, "MagSetWindowFilterList"));set_image_scaling_callback_func_ =reinterpret_cast<MagSetImageScalingCallbackFunc>(GetProcAddress(mag_lib_handle_, "MagSetImageScalingCallback"));if (!mag_initialize_func_ || !mag_uninitialize_func_ ||!set_window_source_func_ || !set_window_filter_list_func_ ||!set_image_scaling_callback_func_) {std::cout << "Failed to initialize ScreenCapturerWinMagnifier: "<< "library functions missing.";return false;}BOOL result = mag_initialize_func_();if (!result) {std::cout << "Failed to initialize ScreenCapturerWinMagnifier: "<< "error from MagInitialize " << GetLastError();return false;}HMODULE hInstance = nullptr;result =GetModuleHandleExA(GET_MODULE_HANDLE_EX_FLAG_FROM_ADDRESS |GET_MODULE_HANDLE_EX_FLAG_UNCHANGED_REFCOUNT,reinterpret_cast<char*>(&DefWindowProc), &hInstance);if (!result) {mag_uninitialize_func_();std::cout << "Failed to initialize ScreenCapturerWinMagnifier: "<< "error from GetModulehandleExA " << GetLastError();return false;}// Register the host window class. See the MSDN documentation of the// Magnification API for more infomation.WNDCLASSEXW wcex = {};wcex.cbSize = sizeof(WNDCLASSEX);wcex.lpfnWndProc = &DefWindowProc;wcex.hInstance = hInstance;wcex.hCursor = LoadCursor(nullptr, IDC_ARROW);wcex.lpszClassName = kMagnifierHostClass;// Ignore the error which may happen when the class is already registered.RegisterClassExW(&wcex);// Create the host window.host_window_ =CreateWindowExW(WS_EX_LAYERED, kMagnifierHostClass, kHostWindowName, 0, 0,0, 0, 0, nullptr, nullptr, hInstance, nullptr);if (!host_window_) {mag_uninitialize_func_();std::cout << "Failed to initialize ScreenCapturerWinMagnifier: "<< "error from creating host window "<< GetLastError();return false;}// Create the magnifier control.magnifier_window_ = CreateWindowW(kMagnifierWindowClass, kMagnifierWindowName,WS_CHILD | WS_VISIBLE, 0, 0, 0, 0,host_window_, nullptr, hInstance, nullptr);if (!magnifier_window_) {mag_uninitialize_func_();std::cout << "Failed to initialize ScreenCapturerWinMagnifier: "<< "error from creating magnifier window "<< GetLastError();return false;}// Hide the host window.ShowWindow(host_window_, SW_HIDE);// Set the scaling callback to receive captured image.result = set_image_scaling_callback_func_(magnifier_window_,&CExcludeWindow::OnMagImageScalingCallback);if (!result) {mag_uninitialize_func_();std::cout << "Failed to initialize ScreenCapturerWinMagnifier: "<< "error from MagSetImageScalingCallback "<< GetLastError();return false;}return true; }CExcludeWindow::~CExcludeWindow() {}BOOL CExcludeWindow::OnMagImageScalingCallback(HWND hwnd,void* srcdata,MAGIMAGEHEADER srcheader,void* destdata,MAGIMAGEHEADER destheader,RECT unclipped,RECT clipped,HRGN dirty) {CExcludeWindow* owner =reinterpret_cast<CExcludeWindow*>(TlsGetValue(GetTlsIndex()));TlsSetValue(GetTlsIndex(), nullptr);owner->OnCaptured(srcdata, srcheader);return TRUE; }void CExcludeWindow::OnCaptured(void* data, const MAGIMAGEHEADER& header) {// Verify the format.// TODO(jiayl): support capturing sources with pixel formats other than RGBA.int captured_bytes_per_pixel = header.cbSize / header.width / header.height;if (header.format != GUID_WICPixelFormat32bppRGBA ) {std::cout<< "Output format does not match the captured format: "<< "width = " << header.width << ", "<< "height = " << header.height << ", "<< "stride = " << header.stride << ", "<< "bpp = " << captured_bytes_per_pixel << ", "<< "pixel format RGBA ? "<< (header.format == GUID_WICPixelFormat32bppRGBA) << ".";return;}static FILE* fp = fopen(".\\rgba.rgba","wb");if (fp){//fwrite(data, header.width * header.height * 4, 1, fp);fwrite(data, header.cbSize, 1, fp);fflush(fp);fclose(fp);fp = NULL;}// Copy the data into the frame./* current_frame->CopyPixelsFrom(reinterpret_cast<uint8_t*>(data), header.stride,DesktopRect::MakeXYWH(0, 0, header.width, header.height));*/magnifier_capture_succeeded_ = true; }int CExcludeWindow::SetExcludeWnd(HWND hWnd) {if (hWnd) {BOOL result = set_window_filter_list_func_(magnifier_window_, MW_FILTERMODE_EXCLUDE, 1, &hWnd);if (!result) {mag_uninitialize_func_();std::cout<< "Failed to initialize ScreenCapturerWinMagnifier: "<< "error from MagSetWindowFilterList " << GetLastError();return -1;}}return 0; }bool CExcludeWindow::CaptureFrame() {int nX = GetSystemMetrics(SM_XVIRTUALSCREEN);int nY = GetSystemMetrics(SM_YVIRTUALSCREEN);int nScreenW = GetSystemMetrics(SM_CXVIRTUALSCREEN);int nScreenH = GetSystemMetrics(SM_CYVIRTUALSCREEN);BOOL result = SetWindowPos(magnifier_window_, NULL, nX, nY,nScreenW, nScreenH, 0);if (!result) {std::cout << "Failed to call SetWindowPos: " << GetLastError()<< ". Rect = {" << nX<< ", " << nY << ", " << nX + nScreenW << ", "<< nY + nScreenH << "}";return false;}magnifier_capture_succeeded_ = false;RECT native_rect = { nX, nY, nX+nScreenW, nY+ nScreenH };TlsSetValue(GetTlsIndex(), this);// OnCaptured will be called via OnMagImageScalingCallback and fill in the// frame before set_window_source_func_ returns.result = set_window_source_func_(magnifier_window_, native_rect);if (!result) {std::cout << "Failed to call MagSetWindowSource: "<< GetLastError() << ". Rect = {" << nX<< ", " << nY << ", " << nX + nScreenW << ", "<< nY + nScreenH << "}";return false;}return magnifier_capture_succeeded_; }

測試:

CExcludeWindow ex; ex.Init(); ex.SetExcludeWnd(hWnd); ex.CaptureFrame();//回調函數會寫下一個rgba的文件

?

總結

以上是生活随笔為你收集整理的windows抓屏排除指定窗口的全部內容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。

主站蜘蛛池模板: 91玖玖| 麻豆一区在线 | 一个人看的www片免费高清中文 | 日韩中文字幕在线视频 | 精品国偷自产国产一区 | 国产剧情在线观看 | 欧美福利影院 | 玉女心经是什么意思 | 六月婷婷激情 | 一本一道久久a久久综合蜜桃 | 91av在线视频观看 | 你懂的欧美 | 国产女人水真多18毛片18精品 | 亚洲精品久久久久中文字幕二区 | 精品一区不卡 | 久久综合久久鬼 | 国产伦理一区 | 美女被日网站 | 日韩成人av网站 | 午夜影视体验区 | 国产精品污www一区二区三区 | 亚洲精品综合在线观看 | 国产精品亚洲二区 | 真人bbbbbbbbb毛片 | 亚洲精品字幕在线观看 | 日韩黄色一级大片 | www.youjizz.com日本 | 欧美国产在线看 | www.激情网 | 视频在线国产 | 欧美成在线观看 | 精品爆乳一区二区三区无码av | 奇米色播| 阿拉伯性视频xxxx | 蜜桃精品在线 | 天天综合网天天综合色 | sese欧美| 色婷婷欧美 | 久久成人精品一区二区 | 熟妇高潮精品一区二区三区 | 一本色综合| 四季av一区二区凹凸精品 | 99蜜桃臀久久久欧美精品网站 | 天天摸天天做天天爽 | 女人18毛片毛片毛片毛片区二 | 夜色视频在线观看 | 久久久久久久影院 | 少妇精品亚洲一区二区成人 | 国产精品免费av一区二区三区 | 综合免费视频 | 9191av| 国产三级国产精品国产国在线观看 | 亚洲乱码一区二区三区 | 国产视频分类 | 欧美第一页草草影院 | 男人的天堂va | 亚洲欧洲一区二区在线观看 | 六月婷婷激情 | 欧美少妇诱惑 | 美女插插| 第一宅男av导航入口 | 四虎一级片| 自拍偷拍福利视频 | 黄页嫩草| 国产一区二区在线精品 | 精品日本一区二区三区 | 国产综合精品一区二区三区 | 国产思思99re99在线观看 | 久久综合成人 | 超碰在线中文字幕 | 中文字幕在线观看国产 | 91丨porny丨九色 | 国产高清小视频 | 五月激情综合网 | 国产一区二区三区成人 | 亚洲熟妇av日韩熟妇在线 | 国产精品--色哟哟 | 欧美私人情侣网站 | 国产精品久久久久久婷婷天堂 | 欧美日韩三级 | 中文字幕素人 | 色婷婷综合久久 | 日韩av资源在线观看 | 午夜视频福利在线观看 | 韩国无码一区二区三区精品 | 亚洲成人av一区 | 一区一区三区产品乱码 | 欧美在线网址 | 国产不卡视频在线播放 | 女大学生的家政保姆初体验 | 伊人影院综合 | 色噜噜日韩精品欧美一区二区 | 国产999精品久久久久久 | 欧美裸体精品 | 探花视频在线免费观看 | av尤物| 国产精品11 | 91丨国产 | 一卡二卡在线 |