Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

sound on button over

Posted on 2002-04-27
2
Medium Priority
?
181 Views
Last Modified: 2010-05-02
i have a sound installed in a resource file and would like  to know what is the best possible method of playing this sound whenever the mouse is moved over the button, without a lot of code?

the button is a component that i downloaded, its a KDC button, if that helps!
0
Comment
Question by:marksmall
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
2 Comments
 
LVL 16

Expert Comment

by:Richie_Simonetti
ID: 6973744
If component supports MouseMove event, it would not be so difficult.
0
 
LVL 16

Accepted Solution

by:
Richie_Simonetti earned 200 total points
ID: 6973748
Takea look at MSDN article:


Using LoadResData with Binary Data
Last reviewed: May 16, 1996
Article ID: Q141505  
The information in this article applies to:
Professional and Enterprise Editions of Microsoft Visual Basic, 16-bit and 32-bit, for Windows, version 4.0


SUMMARY
Visual Basic 4.0 introduces a new function called LoadResData, which can be used to retrieve binary data from a resource (.res) file. The sample in this document demonstrates how to create a resource file and use binary data from it in all versions of Visual Basic 4.0.



MORE INFORMATION
The following code is a resource script that can be compile by using the 16 and 32-bit versions of Rc.exe.


///////////////////////////////////////////////////////////////////////
//////
   // Myres.rc - 16 & 32 bit script. This must be compiled into two .res
   // files using the 16 & 32 bit versions of RC.

///////////////////////////////////////////////////////////////////////
//////
   // Wave Resources - You must copy these files from your \Windows
   // directory to the directory where your .rc script resides.

   CHIMES                  WAVE    DISCARDABLE     "Chimes.wav"
   DING                    WAVE    DISCARDABLE     "Ding.wav"


Steps to Create a Resource File

Save the above code in Notepad as Myres.rc in the directory where Rc.exe exists on your hard disk.

Copy Chimes.wav and Ding.wav from your Windows directory (or your \Windows\Media directory on Windows 95) to the same directory where you saved Myres.rc.

At the command line, type "RC -r Myres.rc" If you want a 16-bit and 32- bit version of your resource file, then you will have to save two copies of your resource file as Myres32.rc and Myres16.rc, and compile each separately with the appropriate resource compiler.

Steps to Run the Sample Application

Create a new project and add a command button to Form1.

Add the following code to Form1:

'*********************************************************************

      ' Form1.frm - Calls PlayWaveRes to play a wave resource file.

'*********************************************************************

      Sub Command1_Click()
         PlayWaveRes "Chimes"
         PlayWaveRes "Ding"
      End Sub



Add your resource file to the project.

Type the following code in a new code module:

'*********************************************************************

      ' Baswave.bas - Plays a wave file from a resource using LoadResData.

'*********************************************************************

      Option Explicit
      #If Win32 Then
        Private Declare Function sndPlaySound Lib "winmm" Alias

"sndPlaySoundA" _
                            (lpszSoundName As Any, ByVal uFlags As

Long) As Long
      #Else
        Private Declare Function sndPlaySound Lib "MMSYSTEM" ( _
                           lpszSoundName As Any, ByVal uFlags%) As Integer
      #End If

'*********************************************************************

      '  Flag values for wFlags parameter.

'*********************************************************************

      Public Const SND_SYNC = &H0        ' Play synchronously (default)
      'Public Const SND_ASYNC = &H1       ' Play asynchronously (see
                                          ' note below!)
      Public Const SND_NODEFAULT = &H2   ' Don't use default sound
      Public Const SND_MEMORY = &H4      ' lpszSoundName points to a
                                         ' memory file.
      Public Const SND_LOOP = &H8        ' Loop the sound until next
                                         ' sndPlaySound.
      Public Const SND_NOSTOP = &H10     ' Don't stop any currently
                                         ' playing sound.

'*********************************************************************

      ' Plays a wave file from a resource.

'*********************************************************************

      Public Sub PlayWaveRes(vntResourceID As Variant, Optional vntFlags)
      '-----------------------------------------------------------------
      ' WARNING:  If you want to play sound files asynchronously in
      '           Win32, then you MUST change bytSound() from a local
      '           variable to a module-level or static variable. Doing
      '           this prevents your array from being destroyed before
      '           sndPlaySound is complete. If you fail to do this, you
      '           will pass an invalid memory pointer, which will cause
      '           a GPF in the Multimedia Control Interface (MCI).
      '-----------------------------------------------------------------
      Dim bytSound() As Byte ' Always store binary data in byte arrays!

      bytSound = LoadResData(vntResourceID, "WAVE")

      If IsMissing(vntFlags) Then
         vntFlags = SND_NODEFAULT Or SND_SYNC Or SND_MEMORY
      End If

      If (vntFlags And SND_MEMORY) = 0 Then
         vntFlags = vntFlags Or SND_MEMORY
      End If

      sndPlaySound bytSound(0), vntFlags
      End Sub

 



 

0

Featured Post

New benefit for Premium Members - Upgrade now!

Ready to get started with anonymous questions today? It's easy! Learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

When trying to find the cause of a problem in VBA or VB6 it's often valuable to know what procedures were executed prior to the error. You can use the Call Stack for that but it is often inadequate because it may show procedures you aren't intereste…
Most everyone who has done any programming in VB6 knows that you can do something in code like Debug.Print MyVar and that when the program runs from the IDE, the value of MyVar will be displayed in the Immediate Window. Less well known is Debug.Asse…
Get people started with the process of using Access VBA to control Excel using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Excel. Using automation, an Access application can laun…
Show developers how to use a criteria form to limit the data that appears on an Access report. It is a common requirement that users can specify the criteria for a report at runtime. The easiest way to accomplish this is using a criteria form that a…
Suggested Courses

688 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question