0

I have been using a magnifier code from this github link : Magnify
I am trying to set MagImageScaling callback and i was able to get the bitmap through this callback.

Once the MagImageScaling Callback is set and if i try to move the window the the right side of the desktop. The Program throws an exception like this:

Exception thrown at 0x00007FFDA8724452 (msvcrt.dll) in Magnify10.exe: 0xC0000005: Access violation reading location 0x000001749E708FA4.


I'm not posting the complete code because it's too large.

The Callback Definition

BOOL MagImageScaling(HWND hwnd, void* srcdata, MAGIMAGEHEADER srcheader, void* destdata, MAGIMAGEHEADER destheader, RECT unclipped, RECT clipped, HRGN dirty)
{
    //Here i was able to receive the bitmap through srcdata
    return TRUE;
}

This is how i set the callback:

if (!MagSetImageScalingCallback(magActive->GetHandle(), (MagImageScalingCallback)MagImageScaling))
{
   return FALSE;
}

Sample

The above diagram shows the actual problem:

The yellow frame is the host window.
The Green frame is the magnifier window which is a child of host window.
The RED frame is the desktop rect.
The blue line is a random boundary.

When the window crosses the blue boundary it causes exception.

I think when the Window is moved, the magnifier window resizes itself and try to cross the Blue Boundary and Desktop boundary which causes this issue.

so i think if we were able to identify when the MagnifyWindow touching the desktop boundary and stop the movement of Mangnifier window then we might be able to stop it.

So is there any way to achieve this?

Here is the complete code of the project to reproduce this issue:
Magnify Bug Project

trickymind
  • 557
  • 5
  • 21
  • You UpdateMagnifier method receives bad values in panOffset and windowSize and this goes into MagSetWindowSource. The source rect is so bad that it crashes the mag api. You need to fix that method's input. – Simon Mourier Oct 12 '20 at 21:41
  • "**Note** The [`MagSetImageScalingCallback`](https://learn.microsoft.com/en-us/windows/win32/api/magnification/nf-magnification-magsetimagescalingcallback) function is deprecated in Windows 7 and later, and should not be used in new applications." And "`MagSetImageScalingCallback` function requires Windows Display Driver Model (WDDM)-capable video cards and works only when Desktop Window Manager (DWM) is off." – Rita Han Oct 13 '20 at 02:42
  • @ Rita Han, thankyou i have read it in microsoft docs, but there is no alternative method to get the visual behind the window other than the CompositionEffectSourceParameter("Backdrop"), from uwp,since i am working on c++ win32 / c# wpf. it causes lag when dragging the window. did you know any method to get the the visual behind the window like DwmEnableBlurBehindWindow() does? – trickymind Oct 13 '20 at 03:22
  • @Simon Mourier,Thank you very much for replying, i have changed the _sourceRect value in the UpdateMagnifier() method to a fixed value. then also if i move the window,it causes the same issue. The Fixed value i given was (left:10,top:10,right:10,bottom:10) – trickymind Oct 13 '20 at 03:32
  • Remove the `(MagImageScalingCallback)` cast. If the code fails to compile fix the callback signature (including the calling convention). – IInspectable Oct 13 '20 at 07:36
  • @ IInspectable , i removed the cast and still it produces the same exception – trickymind Oct 13 '20 at 07:50
  • Any Progress?, I'm Still Stuck on this issue.The MagImageScalingCallback is only giving the bitmap of the size of magnifier window.so if we can scale up the window and fix it position. will we might be able to solve this? Or if we can move the magnifier window to left side from when the HwndHost touches the right side, the magnifier window will not go outside desktop and will stop producing the exception. I think so, so is there any way to calculate when the hwnd host moving outside the desktop boundary and use that as the right margin for magnifier window. – trickymind Oct 14 '20 at 05:45
  • Maybe you can [capture the bitmap](https://learn.microsoft.com/en-us/windows/win32/gdi/capturing-an-image) instead of using that callback. Refer to this official sample: [Magnification](https://github.com/microsoft/Windows-classic-samples/tree/master/Samples/Magnification) to see if it helps. – Rita Han Oct 14 '20 at 05:52
  • but BitBlt is very slow right. – trickymind Oct 14 '20 at 06:02
  • @ Simon Mourier is there any way to capture a window using its hwnd using directx.if that is possible i can get the bitmap through directx and render it bact to the Host window using direct x. – trickymind Oct 14 '20 at 06:12
  • [There](https://stackoverflow.com/questions/30021274/capture-screen-using-directx) is an example using D3D9 you can refer to. – Rita Han Oct 15 '20 at 05:26
  • @ Rita Han,This will capture the entire application surface right. but i only need to capture the magnification window which is a chid of HwndHost.. i'am currently trying to recreate the windows Acrylic effect for win32 apps. so what i need is to capture each frame from magnifier and apply blureffect,saturation,exclusion blend and render it back to the same window. to increase the performance i need to use directx. what i need is a method to capture the buffer from magnifier window and rerender it to my window after applying the effects. I have codes to apply effects and all i need is this. – trickymind Oct 15 '20 at 09:44
  • @trickymind I'll consult the related engineer to see if there is a suggested alternative. – Rita Han Oct 16 '20 at 07:00
  • @ Rita Han - MSFT thank you verymuch – trickymind Oct 16 '20 at 15:56
  • @trickymind Can you confirm the following information for helping to find an alternative? #1, do you mean MagImageScalingCallback is faster than BitBlt for capturing each frame? #2 Since you mentioned that *BitBlt is very slow*, can you show a reproducible code? #3 What's your performance requirements? – Rita Han Oct 19 '20 at 08:18
  • I have read some where bitblit is slow. That's why I mentioned it. All I am looking is a code that could capture the visual which is behind my window and after applying some saturation and gaussian renders it back to the window using directx. If u have any idea please send me. – trickymind Oct 19 '20 at 08:36
  • All I care about performance is it shall not flicker on resize and shall not consume much memory. – trickymind Oct 19 '20 at 08:38
  • @trickymind Can you try BitBlt to find if it meets your performance requirements or not? – Rita Han Oct 20 '20 at 01:39
  • ok i will try out,currently my laptop have some issues – trickymind Oct 20 '20 at 06:42
  • @ Rita Han - MSFT i am unable to capture the magnifier window using the bitblt, it just shows only a white window with some borders only like this : https://firebasestorage.googleapis.com/v0/b/quizbox-f1bb1.appspot.com/o/Untitled.jpg?alt=media&token=5e24f6ca-4390-46de-a25f-0c9f096a45af – trickymind Oct 21 '20 at 14:08
  • @trickymind Since the magnifier window is a transparent, empty window, getting a white bitmap seems expected. In order to get the content in its scope, you can capture the screen bitmap in this scope, this will get what you see in the magnifier window. BTW, what use case for "*apply blureffect,saturation,exclusion blend and render it back to the same window*"? – Rita Han Oct 22 '20 at 07:43
  • i'm trying to recreate the windows acrylic blur effect for win32 and wpf apps so i need to get the visual behind the window and i need to app these effects to achieve it. – trickymind Oct 22 '20 at 10:04
  • i think magnifier window is not a right choice, so i am trying to use another method (dxgi desktop duplication along with setAffinity()). can you plz help me to answer this question : https://stackoverflow.com/questions/64468119/dxgi-desktop-duplication-capture-only-a-particular-rect?noredirect=1#comment114015479_64468119 – trickymind Oct 22 '20 at 10:08

0 Answers0