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


 


Comments (1)

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

Skip to main content