472,789 Members | 1,350 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 472,789 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 8739
* 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: Rina0 | last post by:
Cybersecurity engineering is a specialized field that focuses on the design, development, and implementation of systems, processes, and technologies that protect against cyber threats and...
3
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 2 August 2023 starting at 18:00 UK time (6PM UTC+1) and finishing at about 19:15 (7.15PM) The start time is equivalent to 19:00 (7PM) in Central...
0
by: erikbower65 | last post by:
Using CodiumAI's pr-agent is simple and powerful. Follow these steps: 1. Install CodiumAI CLI: Ensure Node.js is installed, then run 'npm install -g codiumai' in the terminal. 2. Connect to...
0
linyimin
by: linyimin | last post by:
Spring Startup Analyzer generates an interactive Spring application startup report that lets you understand what contributes to the application startup time and helps to optimize it. Support for...
14
DJRhino1175
by: DJRhino1175 | last post by:
When I run this code I get an error, its Run-time error# 424 Object required...This is my first attempt at doing something like this. I test the entire code and it worked until I added this - If...
5
by: DJRhino | last post by:
Private Sub CboDrawingID_BeforeUpdate(Cancel As Integer) If = 310029923 Or 310030138 Or 310030152 Or 310030346 Or 310030348 Or _ 310030356 Or 310030359 Or 310030362 Or...
0
by: lllomh | last post by:
How does React native implement an English player?
0
by: Mushico | last post by:
How to calculate date of retirement from date of birth
2
by: DJRhino | last post by:
Was curious if anyone else was having this same issue or not.... I was just Up/Down graded to windows 11 and now my access combo boxes are not acting right. With win 10 I could start typing...

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.