C#用 directshow做一个媒体播放器如何实现全屏播放与窗口播放的切换?

2025-05-14 10:24:35
推荐回答(1个)
回答(1):

private int ToggleFullScreen()
{
int hr = 0;
OABool lMode;

// Don't bother with full-screen for audio-only files
if ((this.isAudioOnly) || (this.videoWindow == null))
return 0;

// Read current state
hr = this.videoWindow.get_FullScreenMode(out lMode);
DsError.ThrowExceptionForHR(hr);

if (lMode == OABool.False)
{
this.videoWindow.put_WindowStyle(WindowStyle.Child | WindowStyle.ClipSiblings | WindowStyle.ClipChildren);
// Save current message drain
hr = this.videoWindow.get_MessageDrain(out hDrain);
DsError.ThrowExceptionForHR(hr);

// Set message drain to application main window
hr = this.videoWindow.put_MessageDrain(this.Videopanel.Handle);
DsError.ThrowExceptionForHR(hr);

// Switch to full-screen mode
lMode = OABool.True;
hr = this.videoWindow.put_FullScreenMode(lMode);
videoWindow.put_AutoShow(OABool.False);
DsError.ThrowExceptionForHR(hr);
}
else
{
// Switch back to windowed mode
lMode = OABool.False;
hr = this.videoWindow.put_FullScreenMode(lMode);
DsError.ThrowExceptionForHR(hr);

// Undo change of message drain
hr = this.videoWindow.put_MessageDrain(hDrain);
DsError.ThrowExceptionForHR(hr);

// Reset video window
hr = this.videoWindow.SetWindowForeground(OABool.True);
DsError.ThrowExceptionForHR(hr);

// Reclaim keyboard focus for player application
//this.Focus();
}

return hr;
}