An alternative would be to use completely native methods...something like:
Main Topics
Browse All TopicsHi Experts,
I have an large old VB6 program that I need to convert to VB.NET (2005).
It has a window (via a picturebox) that show a zoom of the area around the mouse pointer with StretchBlt.
In other words I want to use StretchBlt to copy the area around the mouse and show it in my picturebox (alt. panel).
The code parts that works in VB6 that I'm not getting to work in VB.NET:
--------------------------
Private Sub DoZoom(ptMouse As POINTAPI)
hWndDesk = GetDesktopWindow()
hDCDesk = GetDC(hWndDesk)
picZoom.Cls
lRet = StretchBlt(picZoom.hDc, sizDest.Left, sizDest.Top, sizDest.width, sizDest.height,
hDCDesk, sizSrce.Left, sizSrce.Top, sizSrce.width, sizSrce.height, SRCCOPY)
lRet = ReleaseDC(hWndDesk, hDCDesk)
picZoom.Refresh
End Sub
--------------------------
It feels like I've tried everything, without getting it to work.
Thanks
Perry
This Question has been solved and asker verified All Experts Exchange premium technology solutions are available to subscription members.
Experts Exchange has been collecting answers to technology questions since 1996…3 million and counting! If you have a question, chances are we already have your answer.
If you can't find the exact answer you're looking for, ask our exclusive community of 50,000 experts. You’ll get a personalized answer from a trusted professional.
Thousands of free tech tips, tricks, how-to’s and tutorials are available in our peer reviewed articles section. See for yourself how smart our experts are, no login required.
Access the answers to your technology questions today.
30-day free trial. Register in 60 seconds.
Members of the expert community talk about why the experience at Experts Exchange is different than what you will find anywhere else.

Try it out and discover for yourself.
30-day free trial. Register in 60 seconds.
Join the community of experts here and help other tech pros by answering question in your area of expertise. You can earn FREE access to all Experts Exchange's premium features and resources.
Constants will be the same but you need to change the TYPE.
It would be:
Public Const SRCOPY As Integer = &HCC0020
The APIs might look like:
Public Declare Function GetDesktopWindow Lib "user32" () As IntPtr
Public Declare Function GetWindowDC Lib "user32" (ByVal handle As IntPtr) As IntPtr
Public Declare Function ReleaseDC Lib "user32" Alias "ReleaseDC" (ByVal handle As IntPtr, ByVal hDc As IntPtr) As Integer
For the desktop you would do:
Dim hWndDesk As IntPtr = GetDesktopWindow()
Dim hDCDesk As IntPtr = GetWindowDC(hWndDesk)
' ..use "dDCDesk"...
ReleaseDC(hWndDesk, hDCDesk)
Did you really try my second example? It just needs a Timer on the Form and a PictureBox called "picZoom".
With the StretchBlt function I get some aritmetic problem (System.OverflowException)
Dim hWndDesk As IntPtr = GetDesktopWindow()
Dim hDCDesk As IntPtr = GetWindowDC(hWndDesk)
Dim result As Integer
Dim G As Graphics = picZoom.CreateGraphics
Dim hDC As IntPtr = G.GetHdc
result = StretchBlt(hDC, 1, 1, picZoom.Width, picZoom.Height, hDCDesk, 1, 1, 10, 10, SRCOPY)
G.ReleaseHdc(hDC)
ReleaseDC(hWndDesk, hDCDesk)
Business Accounts
Answer for Membership
by: Idle_MindPosted on 2009-11-05 at 08:19:35ID: 25751030
First you need to convert all of your API Declarations for use in VB.Net by chaning all "Long" to "Integer" (or IntPtr for handles).
Make sure that your variables such as "hWndDesk" also get changed to Integer or IntPtr as well!
Then you can use code like this to get an hDC for picZoom:
Dim G As Graphics = picZoom.CreateGraphics
Dim hDC As IntPtr = G.GetHdc
' ...now use "hDC"...
G.ReleaseHdc(hDC)
You could also create a Bitmap and get an hDC for that instead:
Dim bmp As New Bitmap(SomeWidth, SomeHeight)
Dim G As Graphics = Graphics.FromImage(bmp)
Dim hDC As IntPtr = G.GetHdc
' ...now use "hDC"...
G.ReleaseHdc(hDC)
' ...now use "bmp"...
picZoom.Image = bmp