When we implement RTSP or RTMP playback on Windows, there is one feature that we can’t get around, and that is full screen playback. This article will take the Windows player of Daniu Live SDK (official) as an example, and talk about the approximate implementation:

There aren’t many points to consider when playing full screen:

First: the meaning of full screen after video playback;

Second: after the full screen, whether equal proportion display, our design principle is, before equal proportion display, continue to equal proportion display, before full, continue to full;

Third: ESC exits full screen.

In this paper, the C++ demo as an example, the specific implementation is as follows:

void nt_wrapper_render_wnd::FullScreenSwitch(a)
{
	if(! : :IsWindow(m_hWnd) )
		return;

	if(player_handle_ ! =nullptr)
	{
		player_api_.SetRenderARGBLogo(player_handle_, nullptr.0.0.0.0.0.0.0);
	}

	if(!IsFullScreen()) {if(!IsCanFullScreen())return;

		auto old_wnd = GetParent(a);if ( old_wnd == NULL )
			return;

		old_parent_wnd_ = old_wnd->m_hWnd;
		ASSERT(: :IsWindow(old_parent_wnd_));

		GetWindowRect(&old_rect_);
		old_wnd->ScreenToClient(old_rect_);
	
		HMONITOR hMonitor = ::MonitorFromWindow(m_hWnd, MONITOR_DEFAULTTONEAREST);
		if (hMonitor == NULL)
			return;

		MONITORINFOEX mi;
		mi.cbSize = sizeof(mi);

		if(!GetMonitorInfo(hMonitor, &mi) )
			return; : :SetParent(m_hWnd, NULL);

		auto wnd_styles = GetWindowLongPtr(m_hWnd, GWL_STYLE); wnd_styles = wnd_styles & (~WS_CHILD); wnd_styles |= WS_POPUP; : :SetWindowLongPtr(m_hWnd, GWL_STYLE, wnd_styles);

		// Hide the old window: :ShowWindow(old_parent_wnd_, SW_HIDE);

		is_full_screen_ = true; : :SetWindowPos(m_hWnd, HWND_TOP, mi.rcMonitor.left, mi.rcMonitor.top, mi.rcMonitor.right - mi.rcMonitor.left, mi.rcMonitor.bottom - mi.rcMonitor.top, SWP_FRAMECHANGED); : :SetForegroundWindow(m_hWnd); : :RedrawWindow(m_hWnd, NULL.NULL, RDW_INVALIDATE | RDW_UPDATENOW | RDW_ERASE); : :RedrawWindow(NULL.NULL.NULL, RDW_INVALIDATE | RDW_UPDATENOW
			| RDW_ERASE);
	}
	else
	{
		::ShowWindow(old_parent_wnd_, SW_SHOW);

		auto wnd_styles = GetWindowLongPtr(m_hWnd, GWL_STYLE);
		wnd_styles = wnd_styles & (~WS_POPUP);
		wnd_styles |= WS_CHILD;
		auto ret = SetWindowLongPtr(m_hWnd, GWL_STYLE, wnd_styles); : :SetParent(m_hWnd, old_parent_wnd_);

		is_full_screen_ = false;

		MoveWindow(old_rect_, TRUE); }}Copy the code

ESC treatment:

void nt_wrapper_render_wnd::OnChar(UINT nChar, UINT nRepCnt, UINT nFlags)
{
	// TODO: Add your message handler code here and/or call default
	
	// Press ESC to exit full screen
	if ( nChar == VK_ESCAPE )
	{
		if ( IsFullScreen()) {FullScreenSwitch(a); } } CWnd::OnChar(nChar, nRepCnt, nFlags);
}
Copy the code

C# implementation is also very simple, interested in their own research.