Click to See Complete Forum and Search --> : How to know the mouse moved out of the control?


Bon La Lay
July 31st, 2001, 02:38 AM
I had a text box on a dialog and need to change the border style of it when
the mouse moved in the text box and out of the text box. I can use Text1_MouseMove
event to deliver the mouse move in action but found I never know when the user
moved the mouse out of it! ( cannot write function in the Form_MouseMove because
it's not always working fine )

Any good ways?

//-----------------------------------------\\
Where there's a wire , there's a way
\\-----------------------------------------//

Cimperiali
July 31st, 2001, 03:07 AM
I used to take advantage of those events, but if you say form_mousemove is not
good enough, you may try with
Private Declare Function GetCursorPos Lib "user32" (lpPoint As POINTAPI) As Long

and with:
Private Type POINTAPI
X As Long
Y As Long
End Type
and have a timer on form , and

Private Sub Timer1_Timer()
Dim Point As POINTAPI
' Get the position of the cursor
GetCursorPos Point

then test for
Point.X
and Point.Y to see if mouse is over your control.
But it will not be easy: you will get coordinates of mouse all over the screen
and in screen coordinates


Special thanks to Lothar "the Great" Haensler, Tom Archer, Chris Eastwood,
Bruno Paris and all the other wonderful people who made and make Codeguru
a great place.
Come back soon, you Gurus.

The Rater

cksiow
July 31st, 2001, 03:50 AM
for control that got window handle, you can try SetCapture, whereby in the X,Y of mouse_move should become negative if you move out of a control (i haven't try it out myself). but, don't forget to call ReleaseCapture.

for control that doesn't have window handle, you will need to check the container mouse move event handle, if the X, Y is fall within the control. if u need example for this, check out http://vblib.virtualave.net, there should be a function call EnableOnMouseOver for vbLabel.



HTH

cksiow
http://vblib.virtualave.net - share our codes

Clearcode
July 31st, 2001, 04:20 AM
You can use the API calls CreateRectRgn and PointInRgn to get this kind of functionality - see the ImageMapVB source code at http://www.merrioncomputing.com/Download/index.htm

HTH,
Duncan

-------------------------------------------------
Ex. Datis: Duncan Jones
Merrion Computing Ltd
http://www.merrioncomputing.com
Check out the new downloads - ImageMap.ocx is the VB control that emulates an HTML image map, EventVB.OCX for adding new events to your VB form and adding System Tray support simply, MCL Hotkey for implemenmting system-wide hotkeys in your application...all with source code included.

John G Duffy
July 31st, 2001, 09:17 AM
Here is a working example. Start a new project. Add a command button. Paste this code into the general declarations section. Ru the program and move the mouse over and off the command button

option Explicit

private Declare Function SetCapture Lib "user32" (byval hwnd as Long) as Long
private Declare Function ReleaseCapture Lib "user32" () as Long


'Code:
'Put this code in MouseMove event. In this example, I put a
'CommandButton on a
'form with the name Command1

private Sub Command1_MouseMove(Button as Integer, Shift as Integer, X _
as Single, Y as Single)
static CtrMov as Boolean
static Counter as Long
Counter = Counter + 1
With Command1 'Change this 'Command1' to your control name
If (X < 0) Or (Y < 0) Or (X > .Width) Or (Y > .Height) then
ReleaseCapture
CtrMov = false
Command1.BackColor = &HFF&
Command1.Caption = " Not Over " & Counter
Command1.Refresh
'Put here your code to LostMouseFocus
'for example:
me.print "LostMouseFocus"

else
SetCapture .hwnd
If CtrMov = false then ' do this only once per "over"
CtrMov = true
Command1.BackColor = &HFFFFFF
Command1.Caption = " Over " & Counter
Command1.Refresh
'Put here your code to GetMouseFocus
'for example:
me.print "GetMouseFocus"

End If
End If
End With
End Sub




John G