全國最多中醫師線上諮詢網站-台灣中醫網
發文 回覆 瀏覽次數:981
推到 Plurk!
推到 Facebook!

System Sounds - Windows Messages

 
axsoft
版主


發表:681
回覆:1056
積分:969
註冊:2002-03-13

發送簡訊給我
#1 引用回覆 回覆 發表時間:2003-03-31 13:45:29 IP:61.218.xxx.xxx 未訂閱

System Sounds - Windows Messages

-------------------------------------------------------------------------------- http://www.hobbypages.net/snip12.html Something that is rather dificult to setup are custom sound events. You can however cheat alittle. The installation routine for your application can add the events to the registry, and unless the user neglects to save the current scheme, it will play your sound when the event is triggered. See, the trouble would be getting the current configurations if the machine is setup with user profiles. You could easily add the .INF or .REG file to the HKEY_USERS\AppEvents\Schemes\Apps key, and even the HKEY_CURRENT_USER\AppEvents\Schemes\Apps\.Default key, but beyond that, who knows where to write it? In this example, it would be easier to merge the examples .reg file, and hope that if the user plays with his sound events, he'll see the EventLabel for you application, and select sounds for it. The key to this method as apposed to embedding a specific wave file name, is that you can allow the user to change the sound, through the control panel. -------------------------------------------------------------------------------- This RegEdit4 file will register the event label, and the default sound for your program event (shown later).: REGEDIT4 [HKEY_CURRENT_USER\AppEvents\EventLabels\MyNewSound] @="My New Sound" [HKEY_CURRENT_USER\AppEvents\Schemes\Apps\.Default\MyNewSound\.Default] @="mysound.wav" [HKEY_USER\AppEvents\EventLabels\MyNewSound] @="My New Sound" [HKEY_USER\AppEvents\Schemes\Apps\.Default\MyNewSound\.Default] @="mysound.wav" In the line ...\EventLabels\MyNewSound "MyNewSound" is what your program will call on, The other line @="My New Sound" is what the user will see in the control panel, sound events dialog. You can put whatever you like. (Sorry, I didn't write out an .INF file to duplicate the method) Your installation routine makes the changes, now your application has a system event. (Under Default) To call on the sound, I used a button here, but you can use whatever, OnEnter, OnClose, OnWhatever to call this sound:

void __fastcall TForm1::Button1Click(TObject *Sender)
{
if (PlaySound("MyNewSound", NULL , SND_ALIAS) == true)
        Label1->Caption = "Playing Sound";
        else
        Label1->Caption = "Not Working";
}     
I used an if statement to show what happens when you rename the sound event to something like "MyNewSound2". First, no sound is played, second the "Not Working" label pops up. You could write a routine to call on the system default beep instead. The uses for system sounds are innumerable. Most programmers overlook them, or hardcode them. I think if the user wants sound events, we should allow him to decide, when, and what sounds to play. The user is the final authority on what makes good software... 聯盟----Visita網站http://www.vista.org.tw ---[ 發問前請先找找舊文章 ]---
系統時間:2024-11-23 11:53:39
聯絡我們 | Delphi K.Top討論版
本站聲明
1. 本論壇為無營利行為之開放平台,所有文章都是由網友自行張貼,如牽涉到法律糾紛一切與本站無關。
2. 假如網友發表之內容涉及侵權,而損及您的利益,請立即通知版主刪除。
3. 請勿批評中華民國元首及政府或批評各政黨,是藍是綠本站無權干涉,但這裡不是政治性論壇!