1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98
|
Program sound ;
{$APPTYPE GUI}
Uses Windows;
Var WinClass: WndClass;
Inst: HINST;
hWindow: HWND;
TheMessage: Msg;
// cette partie est une récupération des constantes de playsound,
// j'ai laissé les commentaires originaux qui peuvent etre utiles
const
SND_SYNC = $0000; // play synchronously (default)
SND_ASYNC = $0001; // play asynchronously
SND_NODEFAULT = $0002; // don't use default sound
SND_MEMORY = $0004; // lpszSoundName points to a memory file
SND_LOOP = $0008; // loop the sound until next sndPlaySound
SND_NOSTOP = $0010; // don't stop any currently playing sound
SND_NOWAIT = $00002000; // don't wait if the driver is busy
SND_ALIAS = $00010000; // name is a registry alias
SND_ALIAS_ID = $00110000; // alias is a predefined ID
SND_FILENAME = $00020000; // name is file name
SND_RESOURCE = $00040004; // name is resource name or atom
SND_PURGE = $0040; // purge non-static events for task
SND_APPLICATION = $0080; // look for application specific association
// declaration de la fonction playsound contenue dans la dll winmm.dll
function PlaySound(pszSound: PChar; hmod: HMODULE; fdwSound: DWORD): BOOL;
stdcall; external 'winmm.dll' name {$ifdef unicode}'PlaySoundW' {$else}
'PlaySoundA' {$endif};
//procedure simplifiée d'appel de playsound
procedure PlayMediaFile(_file : Pchar);
begin
PlaySound(_file, 0, SND_ASYNC or SND_FILENAME);
end;
{ function qui gere les evenements de votre fenetre }
function WindowProc(hWin: HWnd; Message,wParam,lParam: Integer): Integer; stdcall;
begin
Result := 0;
{ Gestion des messages }
case Message of
WM_CREATE :
// ici c'est le chemin du fichier wav à jouer
PlayMediaFile('C:\fpc1\ex\snd\1.wav');
WM_DESTROY:
begin
postquitmessage(0);
end;
else
Result := DefWindowProc(hWin, Message, wParam, lParam);
end;
end;
begin
{ enregistrement WndClass }
Inst := hInstance;
with WinClass do
begin
style := cs_hRedraw Or cs_vRedraw;
lpfnWndProc := @WindowProc;
hInstance := Inst;
hbrBackground := color_btnface + 1; //GetStockObject (GRAY_BRUSH);
lpszClassname := 'MyWindowClass';
hIcon := LoadIcon(0, IDI_APPLICATION);
hCursor := LoadCursor(0, IDC_ARROW);
end; { du with }
RegisterClass(WinClass);
{ Creation de la fenetre }
hWindow := CreateWindowEx(WS_EX_WINDOWEDGE,
'MyWindowClass','Titre de la fenetre',
WS_OVERLAPPEDWINDOW or WS_VISIBLE,
190, 128, 546, 426, 0, 0, Inst, nil);
UpdateWindow(hWindow);
{La boucle principale}
while GetMessage(TheMessage,0,0,0) do begin
if not IsDialogMessage(hWindow,TheMessage) then begin
TranslateMessage(TheMessage);
DispatchMessage(TheMessage);
end;
end;
end. |
Partager