-
Aug 27th, 2013, 01:51 PM
#1
Thread Starter
Fanatic Member
[RESOLVED] Fullscreen magnifier glass
Hello everyone, been a while since posting here...
I'm trying to write a full-screen magnification program in Visual basic .NET, which will likely utilize the Windows API (Pinvoke) to do it's magic.
The problem I am running into is that, when capturing the screen, you inevitably capture the window you display it on as well.
You get the 'infiniwindow' effect, where the captured image is captured and displayed again. It also results in strange glitches when you have a dynamic moving image.
I have tried several ways to capture the screen and displaying it WITHOUT ending up capturing my own drawn window. To do so, I need to draw 'above' the zero-DC buffer.
This is the method I used to draw to the screen (no topmost window as that gets inevitably captured too):
PHP Code:
Public Class Magnifier Dim screen As Screen Dim bounds As Rectangle Dim g As Graphics Dim zoom As Double
Public Sub New(ByVal screen As Screen) Me.screen = screen Me.bounds = Me.screen.Bounds Me.g = Graphics.FromHwnd(IntPtr.Zero) End Sub
Public Sub Dispose() g.Dispose() End Sub
Public Sub SetZoom(ByVal zoom As Double) Me.zoom = zoom End Sub
Public Sub Draw() g.CopyFromScreen(Cursor.Position, New Point(0, 0), New Size(400, 400)) End Sub End Class
As you can see, getting the Graphics for handle IntPtr.ZERO results in the same graphics used to capture the screen. So, I end up capturing myself.
Draw is fired elsewhere using a timer.
Is there some way to capture the screen while EXCLUDING everything I rendered 'on top' of it? Can it be done with a fullscreen topmost window?
Alternatively, is it possible to be 'the man in the middle' transforming the graphics right before it is drawn to screen?
Last edited by bergerkiller; Aug 27th, 2013 at 01:56 PM.
-
Aug 27th, 2013, 02:04 PM
#2
Re: Fullscreen magnifier glass
Personally, I'd set up a property for Zoom:
Code:
Private _zoom As Double
Public Property Zoom() As Double
Get
Return _zoom
End Get
Set(ByVal value As Double)
_zoom = value
End Set
End Property
But, the situation could be different I suppose.
I guess my question is, how often are you calling draw? Because what I think is happening is if you're calling draw to soon and the graphics.copyfromscreen gets placed in the cue and it creates a lag after being called to many times. A sort of 'hack' would be to call DoEvents, but this can leads to some other problems. Try adding the DoEvents and let us know if it's good 'nough
-
Aug 27th, 2013, 02:09 PM
#3
Re: Fullscreen magnifier glass
Wouldn't Process.Start("magnify.exe") be a lot easier all round?
As the 6-dimensional mathematics professor said to the brain surgeon, "It ain't Rocket Science!"
Reviews: "dunfiddlin likes his DataTables" - jmcilhinney
Please be aware that whilst I will read private messages (one day!) I am unlikely to reply to anything that does not contain offers of cash, fame or marriage!
-
Aug 27th, 2013, 02:27 PM
#4
Thread Starter
Fanatic Member
Re: Fullscreen magnifier glass
@dunfiddlin
I have a multiscreen issue. So far, all magnification programs stretch out their image over all monitors, and provide no way to show the same zoomed image on all monitors. So, I am forced to write my own alternative.
Magnification stretched out over two monitors results in very strange zooming on both screens. As in, you can't properly look at the borders of a screen since it centered it there.
@dday9
Changing the interval had little to no effect. Since it is reading (BitBlt or something in the API itself) the same thing it is writing to, during the first capture it already messed up some parts. Doevents isn't going to help here either, since it is doesn't have to do with events in this case.
So yeah, I am capturing the same thing I am displaying on, I need some form of split. I am now attempting iterating all active windows and rendering each one individually to screen, instead of capturing. Sadly, not all applications appear to support the Windows hDC API and end up rendering nothing/black.
EDIT
Iterating each window is not going to work here. Besides it being really glitchy, it also takes very long to render, likely even longer when adding a Bitmap buffer as well.
Last edited by bergerkiller; Aug 27th, 2013 at 04:01 PM.
-
Aug 28th, 2013, 06:21 AM
#5
Thread Starter
Fanatic Member
Re: Fullscreen magnifier glass
After a long, long browse through all corners of the Internet I finally found that there is someone out there that wrote a .NET interaction library with the Windows Magnifier. It allowed me to create a new Magnifier control and move it around. After converting the code to VB .NET and altering some of the Magnifier logic (of which, what the source area is) I am now able to magnify properly. Best of all, it supports Aero, so no weird glitches.
Link is here: http://delphi32.blogspot.nl/2010/09/...n-api-net.html
In addition I used my Window API container class to make the form click-throughable. In case people wish to know: set the layered and transparent Window Exstyles:
Code:
Dim window As Window = window.FromControl(Me)
window.ExStyle = window.ExStyle Or Window.ExStyles.Layered Or Window.ExStyles.Transparent
Marking it solved, as my tests proved it to work very well, also fullscreen.
Last edited by bergerkiller; Aug 28th, 2013 at 07:00 AM.
Tags for this Thread
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|