你厌倦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");
|