我是一名在Windows上运行Lazarus的用户。我想让程序发出“嘟”的声音。看起来可以使用Pascal实现:
windows.beep(300,500);
但在Lazarus中不行!还有其他命令可以使用吗?
更新:
sysutils.beep()
这个方法是可行的,但我真的想要设置声音的频率和持续时间。
如果在Lazarus中未声明此函数,您可以像这样声明它:
function Beep(dwFreq, dwDuration: DWORD): BOOL; stdcall; external 'kernel32.dll';
beep(300,500);
- VitaliyG开始
Beep(300,300);
结束;
函数 Beep(dwFreq, dwDuration: DWORD): BOOL; stdcall; external 'kernel32.dll';
以上是代码。 - plukeunit Unit1;
{$mode objfpc}{$H+}
interface
uses
Classes, SysUtils, FileUtil, Forms, Controls, Graphics, Dialogs, StdCtrls,
windows; // added by manually
type
{ TForm1 }
TForm1 = class(TForm)
Button1: TButton;
procedure Button1Click(Sender: TObject);
private
{ private declarations }
public
{ public declarations }
end;
var
Form1: TForm1;
implementation
{$R *.lfm}
{ TForm1 }
procedure TForm1.Button1Click(Sender: TObject);
var
n,
freq,dur : integer;
begin
Randomize;
for n:=1 to 100 do
begin
windows.Beep(random(1000)+n,random(100)+100);
end;
end;
end.
use Windows;
解决了它。谢谢! - pluke