Login or Sign up Help | Site Map
Connecting Tech Pros Worldwide

Mouse location

Question posted by: EggHead (Guest) on January 22nd, 2007 02:35 PM
Hi all,

My development environment is VB 6.0, and my OS is winxp. I would like to know how to find the mouse location at a control when the mouse is point at that control. The problem is that the mouse "whatever" events will not fire since the mouse is hjhack by other control. Anyway, I have the following code and I can check is the mouse over the control or not, however, I cannot find out where the mouse location at that control.

Private Declare Function GetCursorPos Lib "user32" (lpPoint As POINTAPI) As Long
Private Declare Function WindowFromPoint Lib "user32" (ByVal xPoint As Long, ByVal yPoint As Long) As Long


private sub mouseChecker()
Dim pnt As POINTAPI
Dim ConvertX As Double
GetCursorPos pnt
If WindowFromPoint(pnt.x, pnt.y) = Me.control1.hWnd Then
'I cannot find any method in finding the mouse location in that Visual basic control.

End If
end sub



thanks
Egghead
Would you like to answer this question?
Sign up for a free account, or Login (if you're already a member).
EggHead's Avatar
EggHead
Guest
n/a Posts
January 22nd, 2007
03:15 PM
#2

Re: Mouse location


--
Thanks
Robert Lo
Application Developer
LogTech Canada Ltd
660, 10201 Southport Road S.W.
Calgary, Alberta
Canada T2W 4X9
Email: Join Bytes!
"EggHead" <robertlo_NO_SPAM@shaw.cawrote in message news:GH4th.773721$1T2.555065@pd7urf2no...
Hi all,

My development environment is VB 6.0, and my OS is winxp. I would like to know how to find the mouse location at a control when the mouse is point at that control. The problem is that the mouse "whatever" events will not fire since the mouse is hjhack by other control. Anyway, I have the following code and I can check is the mouse over the control or not, however, I cannot find out where the mouse location at that control.

Private Declare Function GetCursorPos Lib "user32" (lpPoint As POINTAPI) As Long
Private Declare Function WindowFromPoint Lib "user32" (ByVal xPoint As Long, ByVal yPoint As Long) As Long


private sub mouseChecker()
Dim pnt As POINTAPI
Dim ConvertX As Double
GetCursorPos pnt
If WindowFromPoint(pnt.x, pnt.y) = Me.control1.hWnd Then
'I cannot find any method in finding the mouse location in that Visual basic control.

End If
end sub



thanks
Egghead

J French's Avatar
J French
Guest
n/a Posts
January 23rd, 2007
07:05 AM
#3

Re: Mouse location
On Mon, 22 Jan 2007 15:25:26 GMT, "EggHead" <robertlo_NO_SPAM@shaw.ca>
wrote:
Quote:
Originally Posted by
>This is a multi-part message in MIME format.
>
>------=_NextPart_000_0010_01C73DFE.D4179010
>Content-Type: text/plain;
> charset="iso-8859-1"
>Content-Transfer-Encoding: quoted-printable
>
>Hi all,
>
>My development environment is VB 6.0, and my OS is winxp. I would like =
>to know how to find the mouse location at a control when the mouse is =
>point at that control. The problem is that the mouse "whatever" events =
>will not fire since the mouse is hjhack by other control. Anyway, I have =
>the following code and I can check is the mouse over the control or not, =
>however, I cannot find out where the mouse location at that control.
>
>Private Declare Function GetCursorPos Lib "user32" (lpPoint As POINTAPI) =
>As Long
>Private Declare Function WindowFromPoint Lib "user32" (ByVal xPoint As =
>Long, ByVal yPoint As Long) As Long
>
>
>private sub mouseChecker()
Dim pnt As POINTAPI
Dim ConvertX As Double
GetCursorPos pnt
If WindowFromPoint(pnt.x, pnt.y) =3D Me.control1.hWnd Then
'I cannot find any method in finding the mouse location in that =


Look at the ScreenToClient API

It converts a Point structure from screen coordinates to client
coordinates

Shell's Avatar
Shell
Guest
n/a Posts
January 23rd, 2007
08:15 AM
#4

Re: Mouse location
In response to the post:
On Mon, 22 Jan 2007 15:25:26 GMT, "EggHead"
<robertlo_NO_SPAM@shaw.castated...and I replied:
Quote:
Originally Posted by
>Hi all,
>
>My development environment is VB 6.0, and my OS is winxp. I would like to know how to find the mouse location at a control when the mouse is point at that control. The problem is that the mouse "whatever" events will not fire since the mouse is hjhack by other control. Anyway, I have the following code and I can check is the mouse over the control or not, however, I cannot find out where the mouse location at that control.
>
>Private Declare Function GetCursorPos Lib "user32" (lpPoint As POINTAPI) As Long
>Private Declare Function WindowFromPoint Lib "user32" (ByVal xPoint As Long, ByVal yPoint As Long) As Long
>
>
>private sub mouseChecker()
Dim pnt As POINTAPI
Dim ConvertX As Double
GetCursorPos pnt
If WindowFromPoint(pnt.x, pnt.y) = Me.control1.hWnd Then
'I cannot find any method in finding the mouse location in that Visual basic control.
>
End If
>end sub
>
>
>
>thanks
>Egghead



Try this (air code)

'begin code
Type POINTAPI
X As Long
Y As Long
End Type

Type RECT
Left As Long
Top As Long
Right As Long
Bottom As Long
End Type

Type WINDOWPLACEMENT
Length As Long
flags As Long
ShowCmd As Long
ptMinPosition As POINTAPI
ptMaxPosition As POINTAPI
rcNormalPosition As RECT
End Type

Declare Function GetCursorPos Lib "user32" ( _
lpPoint As POINTAPI) As Long

Declare Function GetWindowPlacement Lib "user32" ( _
ByVal hwnd As Long, _
lpwndpl As WINDOWPLACEMENT) As Long

Public Function PointsToMe() As Boolean
Dim WinPos As WINDOWPLACEMENT
Dim Point As POINTAPI, lResult As Long

lResult = GetCursorPos(Point)

lResult = GetWindowPlacement(Me.hwnd, WinPos)

If Point.X >= WinPos.rcNormalPosition.Left And _
Point.X <= WinPos.rcNormalPosition.Right And _
Point.Y >= WinPos.rcNormalPosition.Top And _
Point.Y <= WinPos.rcNormalPosition.Bottom Then _
PointsToMe = True
End Function
'end air code


Dean Earley's Avatar
Dean Earley
Guest
n/a Posts
January 23rd, 2007
08:25 AM
#5

Re: Mouse location
Shell wrote:
Quote:
Originally Posted by
In response to the post:
On Mon, 22 Jan 2007 15:25:26 GMT, "EggHead"
<robertlo_NO_SPAM@shaw.castated...and I replied:
>
Quote:
Originally Posted by
>Hi all,
>>
>My development environment is VB 6.0, and my OS is winxp. I would like to know how to find the mouse location at a control when the mouse is point at that control. The problem is that the mouse "whatever" events will not fire since the mouse is hjhack by other control. Anyway, I have the following code and I can check is the mouse over the control or not, however, I cannot find out where the mouse location at that control.
>>
>Private Declare Function GetCursorPos Lib "user32" (lpPoint As POINTAPI) As Long
>Private Declare Function WindowFromPoint Lib "user32" (ByVal xPoint As Long, ByVal yPoint As Long) As Long
>>
>>
>private sub mouseChecker()
> Dim pnt As POINTAPI
> Dim ConvertX As Double
> GetCursorPos pnt
> If WindowFromPoint(pnt.x, pnt.y) = Me.control1.hWnd Then
> 'I cannot find any method in finding the mouse location in that Visual basic control.
>>
> End If
>end sub
>>
>>
>>
>thanks
>Egghead

>
>
Try this (air code)
>
'begin code
Type POINTAPI
X As Long
Y As Long
End Type
>
Type RECT
Left As Long
Top As Long
Right As Long
Bottom As Long
End Type
>
Type WINDOWPLACEMENT
Length As Long
flags As Long
ShowCmd As Long
ptMinPosition As POINTAPI
ptMaxPosition As POINTAPI
rcNormalPosition As RECT
End Type
>
Declare Function GetCursorPos Lib "user32" ( _
lpPoint As POINTAPI) As Long
>
Declare Function GetWindowPlacement Lib "user32" ( _
ByVal hwnd As Long, _
lpwndpl As WINDOWPLACEMENT) As Long
>
Public Function PointsToMe() As Boolean
Dim WinPos As WINDOWPLACEMENT
Dim Point As POINTAPI, lResult As Long
>
lResult = GetCursorPos(Point)
>
lResult = GetWindowPlacement(Me.hwnd, WinPos)
>
If Point.X >= WinPos.rcNormalPosition.Left And _
Point.X <= WinPos.rcNormalPosition.Right And _
Point.Y >= WinPos.rcNormalPosition.Top And _
Point.Y <= WinPos.rcNormalPosition.Bottom Then _
PointsToMe = True
End Function
'end air code


Bare in mind that this will also return true if the OPs window is not on
top.

To Egghead (why can't people use sensible names?):
What is it that has captured the mouse as it is broken...

--
Dean Earley (dean.earley@icode.co.uk)
i-Catcher Development Team

iCode Systems

Egghead's Avatar
Egghead
Guest
n/a Posts
February 13th, 2007
05:35 PM
#6

Re: Mouse location
Hi all,

using this API "GetWindowRect", I found it is very easy.
The mouse event is not broken. It is because other control has the mouse
event

cheers,
Egghead
"Shell" <drshell@mindspring.comwrote in message
news:smjbr2157n6m2hqdokn2eslbd2fl27cl7g@4ax.com...
Quote:
Originally Posted by
In response to the post:
On Mon, 22 Jan 2007 15:25:26 GMT, "EggHead"
<robertlo_NO_SPAM@shaw.castated...and I replied:
>
Quote:
Originally Posted by
>>Hi all,
>>
>>My development environment is VB 6.0, and my OS is winxp. I would like to
>>know how to find the mouse location at a control when the mouse is point
>>at that control. The problem is that the mouse "whatever" events will not
>>fire since the mouse is hjhack by other control. Anyway, I have the
>>following code and I can check is the mouse over the control or not,
>>however, I cannot find out where the mouse location at that control.
>>
>>Private Declare Function GetCursorPos Lib "user32" (lpPoint As POINTAPI)
>>As Long
>>Private Declare Function WindowFromPoint Lib "user32" (ByVal xPoint As
>>Long, ByVal yPoint As Long) As Long
>>
>>
>>private sub mouseChecker()
> Dim pnt As POINTAPI
> Dim ConvertX As Double
> GetCursorPos pnt
> If WindowFromPoint(pnt.x, pnt.y) = Me.control1.hWnd Then
> 'I cannot find any method in finding the mouse location in that
>Visual basic control.
>>
> End If
>>end sub
>>
>>
>>
>>thanks
>>Egghead

>
>
Try this (air code)
>
'begin code
Type POINTAPI
X As Long
Y As Long
End Type
>
Type RECT
Left As Long
Top As Long
Right As Long
Bottom As Long
End Type
>
Type WINDOWPLACEMENT
Length As Long
flags As Long
ShowCmd As Long
ptMinPosition As POINTAPI
ptMaxPosition As POINTAPI
rcNormalPosition As RECT
End Type
>
Declare Function GetCursorPos Lib "user32" ( _
lpPoint As POINTAPI) As Long
>
Declare Function GetWindowPlacement Lib "user32" ( _
ByVal hwnd As Long, _
lpwndpl As WINDOWPLACEMENT) As Long
>
Public Function PointsToMe() As Boolean
Dim WinPos As WINDOWPLACEMENT
Dim Point As POINTAPI, lResult As Long
>
lResult = GetCursorPos(Point)
>
lResult = GetWindowPlacement(Me.hwnd, WinPos)
>
If Point.X >= WinPos.rcNormalPosition.Left And _
Point.X <= WinPos.rcNormalPosition.Right And _
Point.Y >= WinPos.rcNormalPosition.Top And _
Point.Y <= WinPos.rcNormalPosition.Bottom Then _
PointsToMe = True
End Function
'end air code
>




 
Not the answer you were looking for? Post your question . . .
183,970 Experts ready to help you find a solution.
Sign up for a free account, or Login (if you're already a member).

Latest Articles: Read & Comment
  • Didn't find the answer you were looking for?
    Post Your Question
  • Top Community Contributors