不用MediaPlayer播放Midi
【打印文章】
你厌倦MediaPlayer吗?用了它你的EXE会大7K。
uses
Windows, Classes, Forms, MMSystem, WinProcs;
var
wDeviceID: Word;
PlayWindow: HWnd;
procedure OpenMCI(PWindow: HWnd; FileName, DeviceType: PChar);
var
OpenParms: Tmci_Open_Parms;
Style: LongInt;
begin
PlayWindow := PWindow;
OpenParms.lpstrDeviceType := DeviceType;
OpenParms.lpstrElementName := FileName;
Style := Mci_Open_Type or Mci_Open_Element;
mciSendCommand(0, MCI_OPEN, Style, LongInt(@OpenParms));
wDeviceID := OpenParms.wDeviceID;
end;
procedure PlayMCI;
var
Info: TMci_Play_Parms;
begin
Info.dwCallback := PlayWindow;
mciSendCommand(wDeviceID, MCI_PLAY, Mci_Notify, LongInt(@Info));
end;
procedure MidiPlay(MidiName: PChar);
const
DevType: PChar='Sequencer';
begin
if MidiName = 'StopMidi' then
CloseMCI
else
begin
OpenMci(Application.Handle, MidiName, DevType);
PlayMci;
end;
end;
procedure CloseMCI;
begin
mciSendCommand(wDeviceID, MCI_CLOSE, 0, 0);
wDeviceID := 0;
end;
end.
使用方法:
MidiPlay("Feeling.mid")); // 注意,这里必须是 PChar 或 char*
MidiPlay("StopMidi");
uses
Windows, Classes, Forms, MMSystem, WinProcs;
var
wDeviceID: Word;
PlayWindow: HWnd;
procedure OpenMCI(PWindow: HWnd; FileName, DeviceType: PChar);
var
OpenParms: Tmci_Open_Parms;
Style: LongInt;
begin
PlayWindow := PWindow;
OpenParms.lpstrDeviceType := DeviceType;
OpenParms.lpstrElementName := FileName;
Style := Mci_Open_Type or Mci_Open_Element;
mciSendCommand(0, MCI_OPEN, Style, LongInt(@OpenParms));
wDeviceID := OpenParms.wDeviceID;
end;
procedure PlayMCI;
var
Info: TMci_Play_Parms;
begin
Info.dwCallback := PlayWindow;
mciSendCommand(wDeviceID, MCI_PLAY, Mci_Notify, LongInt(@Info));
end;
procedure MidiPlay(MidiName: PChar);
const
DevType: PChar='Sequencer';
begin
if MidiName = 'StopMidi' then
CloseMCI
else
begin
OpenMci(Application.Handle, MidiName, DevType);
PlayMci;
end;
end;
procedure CloseMCI;
begin
mciSendCommand(wDeviceID, MCI_CLOSE, 0, 0);
wDeviceID := 0;
end;
end.
使用方法:
MidiPlay("Feeling.mid")); // 注意,这里必须是 PChar 或 char*
MidiPlay("StopMidi");
本栏文章均来自于互联网,版权归原作者和各发布网站所有,本站收集这些文章仅供学习参考之用。任何人都不能将这些文章用于商业或者其他目的。( Pfan.cn )
【编程爱好者论坛】