473,395 Members | 1,763 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,395 software developers and data experts.

Magnify Area under Mouse Coordinates

Hi, I see examples of Magnifying an area under mouse coordinates to a
form or picturebox using VB6 and VC6, does anyone know how to do it
under VB.NET? Its nice to use the new GDI+ for it.

Thanks,
Henry
Nov 21 '05 #1
4 8805
* he***********@hotmail.com (Henry Wu) scripsit:
Hi, I see examples of Magnifying an area under mouse coordinates to a
form or picturebox using VB6 and VC6, does anyone know how to do it
under VB.NET? Its nice to use the new GDI+ for it.


You can use 'Cursor.Position' to determine the position of the mouse.
Then you can take a screenshot of the area of the desktop and draw it
onto the form in magnified size ('Graphics.DrawImage').

<URL:http://dotnet.mvps.org/dotnet/samples/windowsandforms/downloads/Screenshot.zip>

--
M S Herfried K. Wagner
M V P <URL:http://dotnet.mvps.org/>
V B <URL:http://dotnet.mvps.org/dotnet/faqs/>
Nov 21 '05 #2
Hi Herfried,
After continous tries to capture Transparent Forms, I discovered
several things.

In your sample CaptureScreen Project, if you add CAPTUREBLT to the
StretchBlt function having a defintion of Public Const CAPTUREBLT As
Integer = &H40000000
you will be able to Capture Transparent Forms without any problems.

I modified your code below and just added an OR CAPTUREBLT to capture
Transparent Forms.

' Zeichnen des Inhalts des Desktop-DCs in den DC der Bitmap.
StretchBlt( _
hdc, _
0, _
0, _
Width, _
Height, _
hdcWindow, _
rct.Left, _
rct.Top, _
Width, _
Height, _
SRCCOPY Or CAPTUREBLT _
)
Your sample CaptureScreen project stores the captured screen into a
BMP variable and you sets it into a PictureBox.

However, what I am trying to do is to draw directly to the form and
not into a BMP or Picturebox. So what I tried is to add the CAPTUREBLT
to my code, but apperntly it does not work! Why is that if it is saved
to a BMP variable and loaded to a PictureBox or saved into a Bitmap
File, you can see the Transparent Form w/o any problems, BUT if you
try to draw the capture screen w/ transparent forms directly to the
form itself, you CANNOT see the transparent form??

Below is my code I modified from my previous post:

Notes: stbVideoPatternControl is a StatusBar docked to the bottom, and
vsbVideoPatternControl is a VerticalScrollBar docked to the right.

-------------------------------------------------
Paint Event of the Form
-------------------------------------------------

Private Sub tbpPatternMovement_Paint(ByVal sender As Object, ByVal e
As System.Windows.Forms.PaintEventArgs) Handles
tbpPatternMovement.Paint
'Mouse Coordiantes To Statusbar
Me.stbVideoPatternControl.Text = "X = " &
Cursor.Current.Position.X & ", Y = " & Cursor.Current.Position.Y

'Get Handle Of Desktop
Dim hdc As IntPtr = GetDC(IntPtr.Zero)

'Get Screen Dimensions
Dim hr As Integer = Screen.PrimaryScreen.Bounds.Width
Dim vr As Integer = Screen.PrimaryScreen.Bounds.Height

Dim percent As Single = Me.vsbVideoPatternControl.Value / 100
Dim lengthX As Single = (Me.tbpPatternMovement.Width -
Me.vsbVideoPatternControl.Width) * percent
Dim lengthY As Single = (Me.tbpPatternMovement.Height -
Me.stbVideoPatternControl.Height) * percent

'Center image around the mouse
Dim offsetX As Single = lengthX \ 2
Dim offsetY As Single = lengthY \ 2

'Actual area to blit to
Dim blitAreaX As Integer = Me.tbpPatternMovement.Width -
Me.vsbVideoPatternControl.Width
Dim blitAreaY As Integer = Me.tbpPatternMovement.Height -
Me.stbVideoPatternControl.Height

e.Graphics.CompositingQuality =
Drawing2D.CompositingQuality.HighSpeed
e.Graphics.SmoothingMode = Drawing2D.SmoothingMode.HighSpeed

Dim ret As Integer = StretchBlt(e.Graphics.GetHdc.ToInt32, 0,
0, blitAreaX, blitAreaY, hdc.ToInt32, Cursor.Current.Position.X -
offsetX, Cursor.Current.Position.Y - offsetY, lengthX, lengthY,
SRCCOPY Or CAPTUREBLT)

'Free Memory
e.Graphics.ReleaseHdc(hdc)
e.Dispose()
ReleaseDC(GetDesktopWindow(), hdc.ToInt32)
End Sub

-------------------------------------------------
Timer Event of the Form
-------------------------------------------------

Private Sub tmrVideoPatternControl_Tick(ByVal sender As
System.Object, ByVal e As System.EventArgs) Handles
tmrVideoPatternControl.Tick
Me.tbpPatternMovement.Invalidate()
End Sub


The only codes I added from my previous post are:

For Flickering Issue:
=====================
e.Graphics.CompositingQuality = Drawing2D.CompositingQuality.HighSpeed
e.Graphics.SmoothingMode = Drawing2D.SmoothingMode.HighSpeed

For Transparent Form Issue:
===========================
CAPTUREBLT

I tried to make the flickering stop, but to no avail, it still
flickers. I really wonder how did Microsoft create the Magnifier
program that has no flickers and could see transparent forms.

Oh by da way, since I know that saving to a bitmap variable would make
transparent forms appear, I tried to do a e.Graphics.DrawImage from a
bitmap variable, and yes I could now see the transparent form drawn
directly to the form, however this method is Super Slow for a
magnifier program.
Any help to draw directly to the form which could see transparent
forms will be very much appreciated!
Thanks,
Henry



he***********@hotmail.com (Henry Wu) wrote in message news:<86*************************@posting.google.c om>...
Hi again, I stumble yet to another problem, I tried the VisualBasic
Sample ScreenShot program you gave, and both that and my program fails
to solve my new found problem.

Have you ever tried creating a form with the ff:
FormBorderStyle = None
BackColor = White
TransparencyKey = White

Then at the form's paint event, draw a simple Cirle like the ff:
e.Graphics.DrawEllipse(New Pen(Color.Black, 10), 0, 0, 100, 100)
e.Dispose()

It draws a thick black circle, with its underlying form "invisible"

Now trying to capture screen on both the sample program, and my code
didn't capture the "thick black circle".

HOWEVER, the strange thing is, when you hit the "PrtScn" or
PrintScreen key at your keyboard, and paste is at MS Paint for
example, you can see that it actually captures the "thick black
circle" correctly.

Why is this? I was wondering if the API or function or underlying code
of the PrintScreen key differs a lot from the sample Screenshot
program/s with APIs?

Thanks so much,
Henry

hi***************@gmx.at (Herfried K. Wagner [MVP]) wrote in message news:<uT**************@TK2MSFTNGP11.phx.gbl>...
* he***********@hotmail.com (Henry Wu) scripsit:
Hi, I see examples of Magnifying an area under mouse coordinates to a
form or picturebox using VB6 and VC6, does anyone know how to do it
under VB.NET? Its nice to use the new GDI+ for it.


You can use 'Cursor.Position' to determine the position of the mouse.
Then you can take a screenshot of the area of the desktop and draw it
onto the form in magnified size ('Graphics.DrawImage').

<URL:http://dotnet.mvps.org/dotnet/samples/windowsandforms/downloads/Screenshot.zip>

Nov 21 '05 #3
* he***********@hotmail.com (Henry Wu) scripsit:
In your sample CaptureScreen Project, if you add CAPTUREBLT to the
StretchBlt function having a defintion of Public Const CAPTUREBLT As
Integer = &H40000000
you will be able to Capture Transparent Forms without any problems.

I modified your code below and just added an OR CAPTUREBLT to capture
Transparent Forms.

' Zeichnen des Inhalts des Desktop-DCs in den DC der Bitmap.
StretchBlt( _
hdc, _
0, _
0, _
Width, _
Height, _
hdcWindow, _
rct.Left, _
rct.Top, _
Width, _
Height, _
SRCCOPY Or CAPTUREBLT _
)
Your sample CaptureScreen project stores the captured screen into a
BMP variable and you sets it into a PictureBox.

However, what I am trying to do is to draw directly to the form and
not into a BMP or Picturebox.


So, why not draw the image onto the form using 'DrawImage' in the form's
'Paint' event?

--
M S Herfried K. Wagner
M V P <URL:http://dotnet.mvps.org/>
V B <URL:http://dotnet.mvps.org/dotnet/faqs/>
Nov 21 '05 #4
oh by the way,.. the max value of the scrollbar is 100, the min value
of the scrollbar is 1, and lastly the default value or value of the
scrollbar is 50.

I just wrote this down if someone wants to try to duplicate the
scenario.

Thanks,
Henry

Contants/Declartions Used:

Public Const SRCCOPY As Integer = &HCC0020
Public Const CAPTUREBLT As Integer = &H40000000
Public Declare Function GetDesktopWindow Lib "user32" () As Integer
Public Declare Function GetDC Lib "user32.dll" (ByVal hWnd As IntPtr)
As IntPtr
Public Declare Function ReleaseDC Lib "user32" (ByVal hwnd As Integer,
ByVal hdc As Integer) As Integer
Nov 21 '05 #5

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
by: cte | last post by:
I have a swing program involving drag and drop - implemented with javax.swing.TransferHandler etc. My problem is that I want to determine the mouse coordinates of a drop onto one of my...
3
by: | last post by:
How can I get the mouse coordinates in Mozilla? I try x = event.pageX but it does not work... basically I try alert(event) and it does not work. Where is the problem? the full code...
4
by: Jonne | last post by:
Hi, I haven't found anything like this anywhere with Google, so I'm posting it here, hoping one of you people knows how to do something like this. I'm trying to get the mouse coordinates in a div,...
2
by: Robin Senior | last post by:
Hi, I'm trying to drag and drop onto a Panel on my form. The panel is inside a groupBox, which of course is inside my form. When dropping the item onto my Panel, I want it to appear at that...
0
by: Henry C. Wu | last post by:
Hi, I have a form that has a video "inserted" at the form's Handle. Like so: '//Create Capture Window capGetDriverDescriptionA(0, lpszName, 100, lpszVer, 100) '// Retrieves driver info lwndC =...
1
by: finerrecliner | last post by:
trying to get the mouse coordinates to show up in an alert box. but all i get is "undefined" the script should work like: click the button, then click anywhere on the page to show your current x...
4
by: Luongo | last post by:
Hi, I'm working on a project in which I'd like to have the user's mouse click coordinates included in a php URL which would load onClick, for example http://...imagecreate.php?x=200&y=100. I've...
4
by: atn2002 | last post by:
How can I track the mouse coordinates outside the active window? No one can tell me its not possible because Google Spreadsheets and EditGrid both do it. When you drag down to select cells these...
4
by: mbatestblrock | last post by:
I hope this makes some sense. My ultimate goal here is to execute a block of code if the mouse has not moved in a minute or so within the broswer. The machine I am running this on is for internal...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.