Articles   Members Online:
-Article/Tip Search
-News Group Search over 21 Million news group articles.
-Delphi/Pascal
-CBuilder/C++
-C#Builder/C#
-JBuilder/Java
-Kylix
Member Area
-Home
-Account Center
-Top 10 NEW!!
-Submit Article/Tip
-Forums Upgraded!!
-My Articles
-Edit Information
-Login/Logout
-Become a Member
-Why sign up!
-Newsletter
-Chat Online!
-Indexes NEW!!
Employment
-Build your resume
-Find a job
-Post a job
-Resume Search
Contacts
-Contacts
-Feedbacks
-Link to us
-Privacy/Disclaimer
Embarcadero
Visit Embarcadero
Embarcadero Community
JEDI
Links
How to play sound from a resource file Turn on/off line numbers in source code. Switch to Orginial background IDE or DSP color Comment or reply to this aritlce/tip for discussion. Bookmark this article to my favorite article(s). Print this article
30-Aug-02
Category
Multimedia
Language
Delphi 2.x
Views
99
User Rating
No Votes
# Votes
0
Replies
0
Publisher:
DSP, Administrator
Reference URL:
DKB
			Author: Tomas Rutkauskas

I am attempting to have a wave file played when a button is clicked. Rather than 
install the wave file and use the PlaySound() API call, I'd like to put it into a 
resource file so that it plays with only the EXE present.

Answer:

1   { ... }
2   var
3     FindHandle, ResHandle: THandle;
4     ResPtr: Pointer;
5   begin
6     FindHandle := FindResource(HInstance, 'Name of your resource', 'WAVE');
7     if FindHandle <> 0 then
8     begin
9       ResHandle := LoadResource(HInstance, FindHandle);
10      if ResHandle <> 0 then
11      begin
12        ResPtr := LockResource(ResHandle);
13        if ResPtr <> nil then
14          SndPlaySound(PChar(ResPtr), snd_ASync or snd_Memory);
15        UnlockResource(ResHandle);
16      end;
17      FreeResource(FindHandle);
18    end;
19  end;


			
Vote: How useful do you find this Article/Tip?
Bad Excellent
1 2 3 4 5 6 7 8 9 10

 

Advertisement
Share this page
Advertisement
Download from Google

Copyright © Mendozi Enterprises LLC