傳送命令
[與此頁面相關聯的功能 MCI是舊版功能。 MediaPlayer已取代它。 MediaPlayer 已針對 Windows 10 和 Windows 11 優化。 Microsoft強烈建議新程式代碼盡可能使用 MediaPlayer,而不是 MCI。 Microsoft建議使用舊版 API 的現有程式代碼,盡可能改寫成使用新的 API。]
下列範例函式會使用 mciSendString 函式,使用 “from” 和 “to” 旗標傳送 播放 命令。
BOOL PlayFromTo(LPTSTR lpstrAlias, DWORD dwFrom, DWORD dwTo)
{
TCHAR achCommandBuff[128];
int result;
MCIERROR err;
// Form the command string.
result = _stprintf_s(
achCommandBuff,
TEXT("play %s from %u to %u"),
lpstrAlias, dwFrom, dwTo);
if (result == -1)
{
return FALSE;
}
// Send the command string.
err = mciSendString(achCommandBuff, NULL, 0, NULL);
if (err != 0)
{
return FALSE;
}
return TRUE;
}