简体   繁体   English

在 Windows10 上使用放大 API 捕获子屏幕失败

[英]Use Magnification API to capture sub screen failed on Windows10

Magnification API can work well when used to capture primary screen, but when i use it to capture sub screen,after MagSetWindowSource() called, MagSetImageScalingCallback() not triggerd. Magnification API 用于抓取主屏幕时可以正常工作,但是当我使用它抓取子屏幕时,调用 MagSetWindowSource( MagSetWindowSource()后, MagSetImageScalingCallback()没有被触发。

I checked the window position is set correctly, in my computer is {-1080, -250, 0, 1670}, and i showed the window, it placed on the right position.我检查了window position是否设置正确,在我的电脑上是{-1080, -250, 0, 1670},我显示了window,它放在右边的position。

I use the following code to get sub screenshot, just same with the webrtc code, but MagSetImageScalingCallback() not triggerd.我使用以下代码获取子屏幕截图,与 webrtc 代码相同,但未MagSetImageScalingCallback()

// Create the host window.
host_window_ = CreateWindowExW(WS_EX_LAYERED, kMagnifierHostClass, 
                                 kHostWindowName, 0, 0,
                                 0, 0, 0, nullptr, nullptr, hInstance, nullptr);

// Create the magnifier control.
magnifier_window_ = CreateWindowW(kMagnifierWindowClass, 
                                  kMagnifierWindowName,
                                  WS_CHILD | WS_VISIBLE, 0, 0, 0, 0,
                                  host_window_, nullptr, hInstance, nullptr);

BOOL result = SetWindowPos(magnifier_window_, NULL, rect.left(), rect.top(),
                             rect.width(), rect.height(), 0);

// value is -1080, -250, 0, 1670
RECT native_rect = {rect.left(), rect.top(), rect.right(), rect.bottom()};

result = set_window_source_func_(magnifier_window_, native_rect);

In the documentation of the MagSetImageScalingCallback, which can be found here , it specifies a few things to take into account:在 MagSetImageScalingCallback 的文档中,可以在此处找到,它指定了一些需要考虑的事项:

  • " This function requires Windows Display Driver Model (WDDM)-capable video cards. " You might want to check if the other screen is running via a different videocard, maybe the driver isn't WDDM capable. 此 function 需要 Windows 显示驱动程序 Model (WDDM)-capable 视频卡。 ”您可能想检查另一个屏幕是否通过不同的视频卡运行,也许驱动程序不支持 WDDM。
  • " This function works only when Desktop Window Manager (DWM) is off. " I'm not sure how much of this statement is true, but as of Windows 8 DWM can no longer be programmatically disabled. 这个 function 仅在桌面 Window 管理器 (DWM) 关闭时才有效。 ”我不确定这个说法有多少是正确的,但截至 Windows 8 DWM 无法再以编程方式禁用。 You might come into some border cases, I do not think the documentation of this API is kept up to date with all the quicks it might have.您可能会遇到一些边界情况,我认为这个 API 的文档没有及时更新。

One very important note, you might want to look for a different solution, as this is specified in the documentation: " The MagSetImageScalingCallback function is deprecated in Windows 7 and later, and should not be used in new applications. There is no alternate functionality. "一个非常重要的注意事项,您可能想要寻找不同的解决方案,因为这在文档中有说明:“ MagSetImageScalingCallback function 在 Windows 7 及更高版本中已弃用,不应在新应用程序中使用。没有替代功能。

Is there any specific reason why you want to use this Windows API, maybe an alternative is a better choice?您是否有任何特定原因要使用此 Windows API,也许替代方案是更好的选择? I am quite familiar with making screenshots, but I'm more of a C# guy, but some c++ examples that look usable can be found here .我对制作屏幕截图非常熟悉,但我更像是一个 C# 的家伙,但是可以在这里找到一些看起来可用的 c++ 示例。 The GDI way pretty much describes what I use in Greenshot , and this works without any big issues. GDI 方式几乎描述了我在Greenshot中使用的内容,这没有任何大问题。

PS If my information doesn't help, you might want to extend your question with more information on your setup, like Windows version, is it 32/64 bit, is your application 32/64 bit, graphics card, screens etc. PS 如果我的信息没有帮助,你可能想用更多关于你的设置的信息来扩展你的问题,比如 Windows 版本,它是 32/64 位,你的应用程序是 32/64 位,显卡,屏幕等。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM