Search code examples
c++windowsmagnificationmagnification-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.

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.

I use the following code to get sub screenshot, just same with the webrtc code, but MagSetImageScalingCallback() not triggerd.

// 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);

The working environment is Windows 10 Professional 64bit, my application is also 64bit, my primary screen is plugged in discrete graphics card, sub screen is plugged in integrated graphics.


Solution

  • I test the code of webrtc screen_capturer_win_magnifier.cc, find that if you want use magnification API to capture sub screen, maybe 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

    For example:

    • Set the host_window_ position to {-1920, -250, 1920(width), 1080(height)}
    • Set the magnifier_window_ position to {1920, 250, 1920(width), 1080(height)}

    Have a try, good luck to you!