Welcome to MSDN Blogs Sign in | Join | Help

Create a magnifier by painting the Desktop into your form

Had a question about how to create an application magnifier and was amazed at how easy it was to get a prototype working! Depending on what you consider lines of code it is about 3 lines!

Dim g As Graphics = Me.CreateGraphics()

'Get the Graphics context to blt into

Dim Desktop_Hwnd As IntPtr

Dim Desktop_HDC As IntPtr

Desktop_Hwnd = GetDesktopWindow()

Desktop_HDC = GetWindowDC(Desktop_Hwnd)

Debug.Print(StretchBlt(g.GetHdc, 0, 0, Me.Width, Me.Height, Desktop_HDC, 0, 0, Me.Height / 2, Me.Width / 2, SRCCOPY))

'Slam the super sized desktop into graphics context of your form.

 

 

The declares for this are:

Declare Function GetWindowDC Lib "user32" (ByVal hwnd As IntPtr) As IntPtr

Private Declare Function StretchBlt Lib "gdi32" (ByVal hdc As IntPtr, ByVal x As Integer, ByVal y As Integer, ByVal nWidth As Integer, ByVal nHeight As Integer, ByVal hSrcDC As IntPtr, ByVal xSrc As Integer, ByVal ySrc As Integer, ByVal nSrcWidth As Integer, ByVal nSrcHeight As Integer, ByVal dwRop As System.Int32) As Boolean

Declare Function GetDesktopWindow Lib "user32" () As IntPtr

Private Const SRCCOPY As Integer = &HCC0020

 

Published Wednesday, November 22, 2006 9:23 PM by Charles_Sterling

Comments

Thursday, November 23, 2006 5:12 PM by @ Head

# Managing un-managed Resources

Yesterday Chuck posted a cool example of using GDI from .NET . One thing that was missing was the call

New Comments to this post are disabled
 
Page view tracker