Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chriss Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

MouseMove Event Detection 1

Status
Not open for further replies.

DarkMercenary44

Technical User
May 19, 2000
55
US
I'm making a custom control, and when the mouse moves over it i want to highlihgt the background, well the problem I'm having is that how do I tell if the mouse is out of the mouse_move event, without putting a statement in form mouse_move.

I was thinking something like getting screen X Y coordinates of control, and then check to see if the mouse is in the control, or somehting to that effect.

but I would rather not use a timer, that will make the program run slower
DarkMercenary
darkmercenary44@earthlink.net

In the real world
As in dreams
Nothing is quite
What it seems
:Book of Counted Sorrows
 
try this out:

Private Sub Text1_MouseMove(Button As Integer, Shift As Integer, X As Single, Y As Single)
If (X > 50 And X < Text1.Width - 50 And Y > 50 And Y < Text1.Height - 50) Then
Debug.Print X, Y
Text1.BackColor = &amp;HFF&amp;
Else
Debug.Print X, Y
Text1.BackColor = &amp;HFFFFFF
End If
End Sub

the measurements are in twips so adjust accordingly,
i left 50 twips leeway on all sides
you can leave more or less whichever works best

Good luck!!
 
Holy crap, lol. Thats so simple. Why didn't I think of that , lol. Thank you so much. DarkMercenary
darkmercenary44@earthlink.net

In the real world
As in dreams
Nothing is quite
What it seems
:Book of Counted Sorrows
 
Your method worked fine untill the control got too small to use that code the proper way. So I came up with this after about 6 hours of thinking.

Use GetCursorPos and get the position constantly, of course I have to use a timer, I didnt' want to but thats the only safe way.
then get the rectangle boundrys of the control by using GetWindowRect
and then compare the values, it works no matter how small the control goes, so thanks for the input.
DarkMercenary
darkmercenary44@earthlink.net

In the real world
As in dreams
Nothing is quite
What it seems
:Book of Counted Sorrows
 
DarkMercenary,
I am having EXACTLY the same problem as you are having :)
The only thing that I cannot figure out is how to call the GetCursorPos constantly outside of the MouseMove event.

How did you accomplish this? Best Regards and many Thanks!
Michael G. Bronner X-)

&quot;Life is too Short to Drink Cheap Beer&quot;
 
I was wondering how the timer was used.... but I figured it out now. Best Regards and many Thanks!
Michael G. Bronner X-)

&quot;They who drink beer will think beer.&quot; Washington Irving
 
Hope that helps

Private Declare Function GetCursorPos Lib &quot;user32&quot; (lpPoint As POINTAPI) As Long
Private Declare Function GetWindowRect Lib &quot;user32&quot; (ByVal hwnd As Long, lpRect As RECT) As Long

Public FirstTime As Boolean
Private Type RECT
Left As Long
Top As Long
Right As Long
Bottom As Long
End Type
Private Type POINTAPI
x As Long
Y As Long
End Type

Private Sub Timer1_Timer()
Dim Point As POINTAPI
Dim Rec As RECT

Dim lngX As Long
Dim lngY As Long

Dim X_bounds As Boolean
Dim Y_bounds As Boolean

GetWindowRect Command1.hwnd, Rec
GetCursorPos Point

lngX = Point.x - Rec.Left
lngY = Point.Y - Rec.Top

X_bounds = (lngX > 0) And (lngX < Command1.Width / 15)
Y_bounds = (lngY > 0) And (lngY < Command1.Height / 15)

If X_bounds And Y_bounds Then
If FirstTime Then
Beep
FirstTime = False
End If
Else
FirstTime = True
End If

End Sub
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top