procedure TForm1.Button1Click(Sender: Tobject);
var returnstring
char;
begin
//弹出
returnstring:='驱动器打开错误';
mciSendString('set CDAudiodo
or open', returnstring, 127, 0);
label1.Caption :=returnstring;
end;
procedure TForm1.Button2Click(Sender: Tobject);
var returnstring
char;
begin
//关闭
returnstring:='驱动器关闭错误';
mciSendString('set CDAudiodo
or closed', returnstring, 127, 0);
label1.Caption :=returnstring;
end;
播放背景音乐
如果要做一些比较艺术化的程序时,你会想到插入背景音乐,这时你是否使用了TMediaPlayer控件来播放音乐呢?其实我们大可放弃该方法,直接使用WINDOWS为我们提供的API函数来播放音乐,方法如下:首先需要在uses部分加入mmsystem,接着写入下列语句,其中e:/1.mid为播放的文件,NN为自定义名称标志
procedure TForm1.Button1Click(Sender: Tobject);
begin
//播放音乐
MCISendString('OPEN e:/1.MID TYPE SEQUENCER ALIAS NN', '', 0, 0);
MCISendString('PLAY NN FROM 0', '', 0, 0);
MCISendString('CLOSE ANIMATION', '', 0, 0);
end;
procedure TForm1.Button2Click(Sender: Tobject);
begin
//停止播放
MCISendString('OPEN e:/1.MID TYPE SEQUENCER ALIAS NN', '', 0, 0);
MCISendString('STOP NN', '', 0, 0);
MCISendString('CLOSE ANIMATION', '', 0, 0);
end;