this have been bugging me ever since my Flash days, I havent heed it but now I need to ask, I hope you can help me guyz.
Any mouseover event in VB? how?
Printable View
this have been bugging me ever since my Flash days, I havent heed it but now I need to ask, I hope you can help me guyz.
Any mouseover event in VB? how?
Double click whatever control you want to add the code to (or the form). On the top of the code window, click the drop down arrow of the right combo box. Click MouseOver
Disiance
there is no mouveover.... Only mousemove, mousedown and mouseup.
MouseMove is similar to MouseOver.
is that all it? nothing special api-related functions or something like that??:) :) :)
You need to use TrackMouseEvent and subclass the window concerned to trap for WM_MOUSEHOVER
VB Code:
' ##ENUMERATION_DESCRIPTION Before WM_MOUSEHOVER and WM_MOUSELEAVE messages can be generated for ' ##ENUMERATION_DESCRIPTION a window, the message tracking must be enabled on that window. Public Enum TrackMouseEvents ' ##ENUMERATION_MEMBER_DESCRIPTION TME_HOVER Request WM_MOUSEHOVER message notification TME_HOVER = &H1 ' ##ENUMERATION_MEMBER_DESCRIPTION TME_LEAVE Request WM_MOUSELEAVE message notification TME_LEAVE = &H2 ' ##ENUMERATION_MEMBER_DESCRIPTION TME_NONCLIENT Request WM_NCMOUSEHOVER and WM_NCMOUSEHOVER messages TME_NONCLIENT = &H10 ' ##ENUMERATION_MEMBER_DESCRIPTION TME_QUERY Get the mouse track status for this window TME_QUERY = &H40000000 ' ##ENUMERATION_MEMBER_DESCRIPTION TME_CANCEL Cancel mouse tracking TME_CANCEL = &H80000000 End Enum Private Type TRACKMOUSESTRUCT cbSize As Long dwFlags As Long '\\ TrackMouseEvents hwndTrack As Long '\\ Target window dwHoverTime As Long '\\ Mouse hover timeout in milliseconds End Type Private Declare Function TrackMouseEvent Lib "user32" (lpTrackMouseStruct As TRACKMOUSESTRUCT) As Long
Well you can try something like this, I use it with a program I have and it works perfect. I use it for a startmenu in a game I made that works like windows start menus. When you mouseover them it sets to another color background. But with other pics. Heres the module I use for it:
Then with that I used it like this:Code:'Programmer Info: Originally developed by Jerrame Hertz
' Modified and updated by Adam VanDerMeid
'
'Question, Comments, Suggestions? Please E-Mail [email protected]
Option Explicit
'Function found in the API Viewer
Public Declare Function GetCursorPos Lib "user32" (lpPoint As POINTAPI) As Long
'Type found in the API Viewer and referenced by the GetCursorPos
Public Type POINTAPI
X As Long
Y As Long
End Type
Public Function CheckMouseOver(FormName As Form, ControlName As Control, DefaultValue As Variant, MouseOverValue As Variant) As Variant
'return the mouse position if the screen
Dim MousePos As POINTAPI
Dim RetValue As Boolean
Dim ctrlLeft, ctrlRight, ctrlTop, ctrlBottom
Dim frmX, frmY
'Get Cursor position relevant to screen
RetValue = GetCursorPos(MousePos)
'calculate cursor position relevant to form
frmX = MousePos.X - FormName.ScaleX(FormName.Left, vbTwips, vbPixels)
frmY = MousePos.Y - FormName.ScaleY(FormName.Top, vbTwips, vbPixels)
'calculate control dimensions relevant to form
ctrlLeft = 3 + FormName.ScaleX(ControlName.Left, vbTwips, vbPixels)
ctrlRight = ctrlLeft + FormName.ScaleX(ControlName.Width, vbTwips, vbPixels)
ctrlTop = 22 + FormName.ScaleY(ControlName.Top, vbTwips, vbPixels)
ctrlBottom = ctrlTop + FormName.ScaleY(ControlName.Height, vbTwips, vbPixels)
'check cursor position against object position and return appropriate value
If (frmX > ctrlLeft) And (frmX < ctrlRight) And (frmY > ctrlTop) And (frmY < ctrlBottom) Then
CheckMouseOver = MouseOverValue
Else
CheckMouseOver = DefaultValue
End If
End Function
Change the code around to best fit your needs. But it does work.Code:Private Sub Timer1_Timer()
If Picture1..Visible = True Then
Picture1.Visible = CheckMouseOver(Form1, Picture3, True, False)
End If
thanks.. ill try that code later coz im not home.. thanks alot!
Yea thanks deepak sakpal
As long as the control exposes a hwnd property you can use Hack's code in this post.
http://www.vbforums.com/showpost.php...57&postcount=9