如果你想做一個CD播放器的話,那本技巧一定少不了。這是一個控制CD-ROM驅動器門彈出和關閉的方法,首先需要在uses部分加入mmsystem,接著增加兩個TButton按鈕,在按鈕事件裡寫入下列語句,記住在調用完畢後一定要顯示或判斷returnstring,要不程序將出錯:
procedure TForm1.Button1Click(Sender: TObject);
var returnstring:pchar;
begin
//彈出
returnstring:=驅動器打開錯誤;
mciSendString(set CDAudio door open, returnstring, 127, 0);
label1.Caption :=returnstring;
end; procedure TForm1.Button2Click(Sender: TObject);
var returnstring:pchar;
begin
//關閉
returnstring:=驅動器關閉錯誤;
mciSendString(set CDAudio door closed, returnstring, 127, 0);
label1.Caption :=returnstring;
end;