共用方式為


設定播放視窗

[與此頁面相關聯的功能 MCI是舊版功能。 MediaPlayer已取代它。 MediaPlayer 已針對 Windows 10 和 Windows 11 優化。 Microsoft強烈建議新程式代碼盡可能使用 MediaPlayer,而不是 MCI。 Microsoft建議使用舊版 API 的現有程式代碼,盡可能改寫成使用新的 API。]

以下範例會找出播放 AVI 檔案所需的大小,建立一個對應此大小的視窗,並使用 MCIAVI 驅動程式在視窗中播放該檔案。 它會使用 mciSendCommand 函式

HWND hwnd; 
MCI_DGV_RECT_PARMS mciRect; 
 
// Get the movie dimensions with MCI_WHERE. 
 
mciSendCommand(wDeviceID, MCI_WHERE, MCI_DGV_WHERE_SOURCE, 
    (DWORD)(LPSTR)&mciRect); 
 
// Create the playback window. Make it bigger for the border. 
// Note that the right and bottom members of RECT structures in MCI 
// are unusual; rc.right is set to the rectangle's width, and 
// rc.bottom is set to the rectangle's height.

hwndMovie = CreateWindow("mywindow", "Playback", 
    WS_CHILD|WS_BORDER, 0,0, 
    mciRect.rc.right+(2*GetSystemMetric(SM_CXBORDER)),
    mciRect.rc.bottom+(2*GetSystemMetric(SM_CYBORDER)), 
    hwndParent, hInstApp, NULL); 
 
if (hwndMovie){ 
    // Window created OK; make it the playback window. 
 
    MCI_DGV_WINDOW_PARMS mciWindow; 
 
    mciWindow.hWnd = hwndMovie; 
    mciSendCommand(wDeviceID, MCI_WINDOW, MCI_DGV_WINDOW_HWND, 
        (DWORD)(LPSTR)&mciWindow); 
 
}