Go Back   Forum Care Forums > Development Reference Area > Visual Basic

Reply
 
LinkBack Thread Tools Display Modes
Mouse location
Old
  (#1)
EggHead
Guest
 
Posts: n/a
Default Mouse location - 06-04-2007, 10:35 AM

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
   
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote

Re: Mouse location
Old
  (#2)
EggHead
Guest
 
Posts: n/a
Default Re: Mouse location - 06-04-2007, 10:35 AM



--
Thanks
Robert Lo
Application Developer
LogTech Canada Ltd
660, 10201 Southport Road S.W.
Calgary, Alberta
Canada T2W 4X9
Email: EMAIL REMOVED
"EggHead" <EMAIL REMOVED> wrote 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
   
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
Re: Mouse location
Old
  (#3)
J French
Guest
 
Posts: n/a
Default Re: Mouse location - 06-04-2007, 10:35 AM

On Mon, 22 Jan 2007 15:25:26 GMT, "EggHead" <EMAIL REMOVED>
wrote:

>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
   
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
Re: Mouse location
Old
  (#4)
Shell
Guest
 
Posts: n/a
Default Re: Mouse location - 06-04-2007, 10:35 AM

In response to the post:
On Mon, 22 Jan 2007 15:25:26 GMT, "EggHead"
<EMAIL REMOVED> stated...and I replied:

>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

   
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
Re: Mouse location
Old
  (#5)
Dean Earley
Guest
 
Posts: n/a
Default Re: Mouse location - 06-04-2007, 10:35 AM

Shell wrote:
> In response to the post:
> On Mon, 22 Jan 2007 15:25:26 GMT, "EggHead"
> <EMAIL REMOVED> stated...and I replied:
>
>> 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 (EMAIL REMOVED)
i-Catcher Development Team

iCode Systems
   
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
Re: Mouse location
Old
  (#6)
Egghead
Guest
 
Posts: n/a
Default Re: Mouse location - 06-04-2007, 10:35 AM

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" <EMAIL REMOVED> wrote in message
news:EMAIL REMOVED...
> In response to the post:
> On Mon, 22 Jan 2007 15:25:26 GMT, "EggHead"
> <EMAIL REMOVED> stated...and I replied:
>
>>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
>



   
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
Reply

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On





Contact Us - Forum Care Forums - Archive - Top