How to use the magnification API to capture sub screen image data?

勇强 韩 136 Reputation points
2020-12-27T11:26:15.107+00:00

When I use the magnification API to capture the image of the main screen, the callback set by MagImageScalingCallback can trigger and return data.
But when I put the host window on the secondary screen to capture the secondary screen, the contents of the secondary screen can be displayed on the host, but the callback set by MagImageScalingCallback will not be triggered.
The code is as follows:

    hostWindowRect.top = -1080;
    hostWindowRect.bottom = -180;  // top quarter of screen
    hostWindowRect.left = 0;
    hostWindowRect.right = 1920;
 int width = hostWindowRect.right - hostWindowRect.left;
 int height = hostWindowRect.bottom - hostWindowRect.top;

// Create the host window.
RegisterHostWindowClass(hinst);
hwndHost = CreateWindowEx(WS_EX_LAYERED,
    WindowClassName, WindowTitle,
    RESTOREDWINDOWSTYLES,
    hostWindowRect.left, hostWindowRect.top, width, height, NULL, NULL, hInst, NULL);
if (!hwndHost) {
    return FALSE;
}

    // Create a magnifier control that fills the client area.
 magWindowRect.top = -1080;
 magWindowRect.bottom = 0;
 magWindowRect.left = 0;
 magWindowRect.right = 1920;
 width = magWindowRect.right - magWindowRect.left;
 height = magWindowRect.bottom - magWindowRect.top;
 hwndMag = CreateWindow(WC_MAGNIFIER, TEXT("MagnifierWindow"),
 WS_CHILD | MS_SHOWMAGNIFIEDCURSOR | WS_VISIBLE,
 magWindowRect.left, magWindowRect.top, width, height, hwndHost, NULL, hInst, NULL);
 if (!hwndMag) {
 return FALSE;
 }
     BOOL result = MagSetImageScalingCallback(
 hwndMag,
 &OnMagImageScalingCallback);
 if (result) {
 }

    //... ...
    sourceRect.top = -1080;
 sourceRect.bottom = 0;
 sourceRect.left = 0;
 sourceRect.right = 1920;
 // Set the source rectangle for the magnifier control.
 MagSetWindowSource(hwndMag, sourceRect);

What is the reason that the callback is not triggered?
Or is there any way to get the image data displayed in the magnifying glass window in RGB format?
I try to use BitBlt and printwindow API, the function returns success, but the RGB is black image.

Windows API - Win32
Windows API - Win32
A core set of Windows application programming interfaces (APIs) for desktop and server applications. Previously known as Win32 API.
2,386 questions
{count} votes

2 answers

Sort by: Most helpful
  1. Krishandevan k 1 Reputation point
    2021-06-22T09:09:22.02+00:00

    @勇强 韩

    Hello,

    Recently I worked with a project involving Magnification API. And whatever you said regarding capturing the second monitor is true. When the second monitor resolution is greater than primary, the MagImageScalingCallback will not be called and it crashes.

    I spent like 1 week, and landed on your post here :)

    Did you get any work around on this ?

    Thanks


  2. Grey 5 Reputation points
    2023-01-18T07:26:34.2366667+00:00

    Hey,

    I don't know whether you still interested in this problem, but i could provide some guidelines for you.

    My test code similar with webrtc screen_capturer_win_magnifier.cc, if you want use magnification API to capture sub screen, you should satisfy following conditions:

    • make sure that the sum of left of host_window_ and magnifier_window_ is zero
    • make sure that the sum of top of host_window_ and magnifier_window_ is zero
    • make sure that the native_rect of MagSetWindowSource() equals to sub screen's position

    Have a look at your code sample, the sourceRect looks right, you can try set left and top of hwndHost and hwndMag to 0, maybe this code will works. Such as set hosWindowRect.left = 0, hostWindowRect.top = 0, magWindowRect.left = 0, magWindowRect.top = 0.

    0 comments No comments