Mouse in / out on controls

Started by Petrus Vorster, September 19, 2013, 03:34:25 PM

Previous topic - Next topic

Petrus Vorster

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?
-Regards
Peter

Paul Squires

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.
Paul Squires
PlanetSquires Software

Elias Montoya

#2
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
Win7, iMac x64 Retina display 5K, i7-5820K 4.4 ghz, 32GB RAM, All updates applied. - Firefly 3.70.

José Roca

WindowFromPoint, as its name says, expects a POINT structure. If you want to use separate coordinates, call WindowFromXY.

Elias Montoya

 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:


  • Firefly says x and y coordinates are required.
  • Compiler says a STRING is expected.
  • Me and you say a POINT should be required.

:)
Win7, iMac x64 Retina display 5K, i7-5820K 4.4 ghz, 32GB RAM, All updates applied. - Firefly 3.70.

José Roca


Elias Montoya

 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


Win7, iMac x64 Retina display 5K, i7-5820K 4.4 ghz, 32GB RAM, All updates applied. - Firefly 3.70.

Petrus Vorster

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.


-Regards
Peter

Elias Montoya

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.



Win7, iMac x64 Retina display 5K, i7-5820K 4.4 ghz, 32GB RAM, All updates applied. - Firefly 3.70.

Petrus Vorster

Thanks for all the advice.
Was away for a while. Sorry for the late response!
-Regards
Peter

Petrus Vorster

Pretty Brilliant Elias!
Works like a charm!!!

Imagine any FF control with that build in....  ;)
-Regards
Peter