INTERACT FORUM

Windows => Plug-in Development => Topic started by: KingSparta on February 07, 2006, 12:46:02 pm

Title: MouseOver VB6 Code Sample
Post by: KingSparta on February 07, 2006, 12:46:02 pm
I learned Something Today Since I Have Been Playing With Voice (TextAloud) Program And Make Small Mp3 Files For Command buttons "Back", "Next" etc...

Trying To Figure Out How To Detect When The Mouse Was Over The Command button. Where The MouseMove Would Normally Only Detect Once You Move The Mouse Away From The Button. This Sample Works Perfectly

Declare
Quote
Option Explicit
Private Declare Function SetCapture Lib "user32" (ByVal hwnd As Long) As Long
Private Declare Function ReleaseCapture Lib "user32" () As Long
Private Declare Function GetCapture Lib "user32" () As Long

To Detect That A Mouse Is Over A Command Button In This Case "Back(0)"

Quote
Private Sub Back_MouseMove(Index As Integer, Button As Integer, Shift As Integer, X As Single, Y As Single)
    If (X < 0) Or (Y < 0) Or (X > Back(0).Width) Or (Y > Back(0).Height) Then
        ReleaseCapture             ' the mouse is no longer over the button
    ElseIf GetCapture() <> Back(0).hwnd Then
        SetCapture Back(0).hwnd   ' the mouse is over the button
        PlayMediaFile Back(0).Caption
    End If
End Sub

Play A Sound Using The Media Player

Quote
Private Sub PlayMediaFile(MP3FileName As String)
    On Error Resume Next
    WindowsMediaPlayer1.URL = App.Path & "\Mp3\" & MP3FileName & ".mp3"
End Sub
Title: Re: MouseOver VB6 Code Sample
Post by: Mr ChriZ on February 07, 2006, 04:22:17 pm
Always good to know these things :)