> Hi,
> I am a beginner to VB. I am trying to do the following:
[quoted text clipped - 10 lines]
>
> Srikanth
Why don't you store the X,Y points from MouseMove in module level variables
mX, mY. You could refer to them from the KeyDown event.
Dave
> Hi,
> I am a beginner to VB. I am trying to do the following:
[quoted text clipped - 11 lines]
>
> Srikanth
Srikanth -
Your best bet is to use a couple of API functions: GetCursorPos() to get the
cursor position, ScreenToClient() to convert screen coordinates to the
containing window coordinates, and then you would need to negatively offset
by the position of the graphic in the window. You can get all the
definitions from Win.tlb or by using the declarations in the code below:
(note that I am using an Image control to hold the graphic).
-------------------------------------------------
Option Explicit
Private Type POINT
X As Long
Y As Long
End Type
Private Declare Function ScreenToClient Lib "User32.dll" ( _
ByVal hWnd As Long, _
ByRef udtPoint As POINT _
) As Long
Private Declare Function GetCursorPos Lib "User32.dll" ( _
ByRef udtPoint As POINT _
) As Long
Private Function GetPixelInPicture(ByRef frm As Form, ByVal sngPicOffsetX As
Single, ByVal sngPicOffsetY As Single, ByRef lPixelX As Long, ByRef lPixelY
As Long)
Dim lPicOffsetX As Long
Dim lPicOffsetY As Long
Dim udtPoint As POINT
lPicOffsetX = frm.ScaleX(sngPicOffsetX, frm.ScaleMode, vbPixels)
lPicOffsetY = frm.ScaleY(sngPicOffsetY, frm.ScaleMode, vbPixels)
GetCursorPos udtPoint
ScreenToClient frm.hWnd, udtPoint
lPixelX = udtPoint.X - lPicOffsetX
lPixelY = udtPoint.Y - lPicOffsetY
End Function
Private Sub Image1_MouseDown(Button As Integer, Shift As Integer, X As
Single, Y As Single)
Dim lPixelX As Long
Dim lPixelY As Long
GetPixelInPicture Me, Image1.Left, Image1.Top, lPixelX, lPixelY
MsgBox CStr(lPixelX) & " - " & CStr(lPixelY)
End Sub
-------------------------------------------------
--
Mark Bertenshaw
LEAX Controls Ltd.
UK
Srikanth Ganesan - 22 Nov 2004 18:07 GMT