[與此頁面相關聯的功能 MCI是舊版功能。 MediaPlayer已取代它。 MediaPlayer 已針對 Windows 10 和 Windows 11 優化。 Microsoft強烈建議新程式代碼盡可能使用 MediaPlayer,而不是 MCI。 Microsoft建議使用舊版 API 的現有程式代碼,盡可能改寫成使用新的 API。]
當您使用 mciSendString 函式時,使用 命令傳遞的所有值和所有傳回值都是文字字串,因此您的應用程式需要轉換例程,才能從變數轉譯為字元串或重新轉換。 下列範例會擷取來源矩形,並將傳回的字串轉換成矩形座標。
BOOL GetSourceRect(LPTSTR lpstrAlias, LPRECT lprc)
{
TCHAR achRetBuff[128];
TCHAR achCommandBuff[128];
int result;
MCIERROR err;
// Build the command string.
result = _stprintf_s(
achCommandBuff,
TEXT("where %s source"),
lpstrAlias);
if (result == -1)
{
return FALSE;
}
// Clear the RECT.
SetRectEmpty(lprc);
// Send the MCI command.
err = mciSendString(
achCommandBuff,
achRetBuff,
sizeof(achRetBuff),
NULL);
if (err != 0)
{
return FALSE;
}
// The rectangle is returned as "x y dx dy".
// Translate the string into the RECT structure.
// Warning: This example omits error checking
// for the _tcstok_s and _tstoi functions.
TCHAR *p;
TCHAR *context;
// Left.
p = _tcstok_s(achRetBuff, TEXT(" "), &context);
lprc->left = _tstoi(p);
// Top.
p = _tcstok_s(NULL, TEXT(" "), &context);
lprc->top = _tstoi(p);
// Right.
p = _tcstok_s(NULL, TEXT(" "), &context);
lprc->right = _tstoi(p);
// Bottom.
p = _tcstok_s(NULL, TEXT(" "), &context);
lprc->bottom = _tstoi(p);
return TRUE;
}
注意
RECT 結構在 MCI 中處理的方式與 Windows 的其他部分不同;在MCI中,右 成員包含矩形的寬度,而 底部 成員包含其高度。 在字串介面中,矩形會指定為 X1、Y1、X2和 Y2。 坐標 X1 和 Y1 指定矩形左上角,座標 X2 和 Y2 指定寬度和高度。