PlanetSquires Forums

Support Forums => Other Software and Code => Topic started by: Petrus Vorster on September 19, 2013, 03:34:25 PM

Title: Mouse in / out on controls
Post by: Petrus Vorster on September 19, 2013, 03:34:25 PM
Hi

I remember certain controls in VB had this mouse_in and mouse_out function.
Pretty handy.
Is there some examples here on how we do that in FF?
Title: Re: Mouse in / out on controls
Post by: Paul Squires on September 19, 2013, 05:43:52 PM
The easiest way to do this across all versions of 32-bit Windows is to use a Timer to check if the mouse is over the area you desire. This technique is used in the FireFly custom controls that ship with FireFly. Check out the FireLink custom control code - that one should be easy to understand.
Title: Re: Mouse in / out on controls
Post by: Elias Montoya on September 19, 2013, 07:07:41 PM
I was trying to make an example without a timer (more efficient because it is event driven), but WindowFromPoint doesnt seem to be working correctly.

Firefly codetips state that it takes xCoord, and yCoord, but when i add them, the compiler says a string is expected.... anyway here's the code that I believe should work:

Sub MouseInNotification(hWndControl As Dword)

   Call FF_Control_SetText(hWndControl, "Mouse in!!!")

End Sub


Sub MouseOutNotification(hWndControl As Dword)

   Call FF_Control_SetText(hWndControl, "Mouse Out!!!")

End Sub



'--------------------------------------------------------------------------------
Function MOUSEINOUT_LABEL1_CUSTOM ( _
                             ControlIndex  As Long,  _  ' index in Control Array
                             hWndForm      As Dword, _  ' handle of Form
                             hWndControl   As Dword, _  ' handle of Control
                             wMsg          As Long,  _  ' type of message
                             wParam        As Dword, _  ' first message parameter
                             lParam        As Long   _  ' second message parameter
                             ) As Long
                             
                             
Select Case wMsg
   Case %WM_MOUSEMOVE
      If GetCapture() <> hWndControl Then
            SetCapture(hWndControl)
            Call MouseInNotification(hWndControl)
      Else         
         If WindowFromPoint(LoWrd(lparam), HiWrd(lparam)) <> hWndControl Then
            ReleaseCapture()
            Call MouseOutNotification(hWndControl)
         End If
      End If
     
End Select     
     

End Function
Title: Re: Mouse in / out on controls
Post by: José Roca on September 19, 2013, 07:32:09 PM
WindowFromPoint, as its name says, expects a POINT structure. If you want to use separate coordinates, call WindowFromXY.
Title: Re: Mouse in / out on controls
Post by: Elias Montoya on September 19, 2013, 07:35:56 PM
 AFAIK it used to work with a POINT Structure. Then the API declarations changed and a X and Y coordinates were required. Well them that makes 3 diferent versions:


:)
Title: Re: Mouse in / out on controls
Post by: José Roca on September 19, 2013, 07:38:13 PM
When in doubt, trust me :)
Title: Re: Mouse in / out on controls
Post by: Elias Montoya on September 19, 2013, 07:41:03 PM
 I have no doubt, it should be a POINT. :)

Paul, Perhaps this should be added to the firefly notification messages. This is working correctly:


Sub MouseInNotification(hWndControl As Dword)

   Call FF_Control_SetText(hWndControl, "Mouse in!!!" & Str$(timer))

End Sub


Sub MouseOutNotification(hWndControl As Dword)

   Call FF_Control_SetText(hWndControl, "Mouse Out!!!" & Str$(timer))

End Sub



'--------------------------------------------------------------------------------
Function MOUSEINOUT_LABEL1_CUSTOM ( _
                             ControlIndex  As Long,  _  ' index in Control Array
                             hWndForm      As Dword, _  ' handle of Form
                             hWndControl   As Dword, _  ' handle of Control
                             wMsg          As Long,  _  ' type of message
                             wParam        As Dword, _  ' first message parameter
                             lParam        As Long   _  ' second message parameter
                             ) As Long
                             
                             
Select Case wMsg
   Case %WM_MOUSEMOVE
      If GetCapture() <> hWndControl Then
            SetCapture(hWndControl)
            Call MouseInNotification(hWndControl)
      Else
         Local PT As POINT
         GetCursorPos(PT)         
         If WindowFromPoint(PT) <> hWndControl Then
            ReleaseCapture()
            Call MouseOutNotification(hWndControl)
         End If
      End If
     
End Select     
     

End Function


Title: Re: Mouse in / out on controls
Post by: Petrus Vorster on September 30, 2013, 02:00:19 PM
Guys, please keep in mind I am centuries behind any of you. Seriously dumb hobby programmer here...

The code of Elias looks very simple, now just help me here on firing the mouse_in event on say a PICTUREBOX.

The rest i should manage.


Title: Re: Mouse in / out on controls
Post by: Elias Montoya on September 30, 2013, 03:17:24 PM
In that case, just replace MOUSEINOUT_LABEL1_CUSTOM with the Custom function name for the PICTURE BOX and add the apropriate action in the mouse in and mouse out event handler functions.

Here is an example with an array of controls, it is very straightforward.



Title: Re: Mouse in / out on controls
Post by: Petrus Vorster on October 30, 2013, 04:24:10 PM
Thanks for all the advice.
Was away for a while. Sorry for the late response!
Title: Re: Mouse in / out on controls
Post by: Petrus Vorster on October 30, 2013, 04:27:44 PM
Pretty Brilliant Elias!
Works like a charm!!!

Imagine any FF control with that build in....  ;)