Recently, an ActiveX video control was developed, which requires a full screen function. Because several layers of windows are used, it takes a lot of twists and turns to be used in full screen mode. Finally, I have finally gotten it together and wrote it down to share it with you.
ApplyProgramThe idea of full screen display is simple:
1. First save the parent window of the window to be full screen
2. If the window to be full screen is not a subwindow, set its style to ws_child.
3. Set the parent window of the window to desktop (: getdesktopwindow ())
4. Move the window to full screen, and set the window to always at the top of hwnd_topmost
M_videomgr is the video window created in my control. Its parent window is the window of the control window (cameracontrol) control itself, which is not directly displayed and completely overwritten by the m_videomgr window. In full screen mode, if you directly change the parent window of cameracontrol, its subwindow m_videomgr cannot always be correctly set to full screen, which may be normal in the control test container, but it is not normal in IE. So I changed the parent window of the m_videomgr window to keep the control window, but changed the size of the parent window when changing the window size, perhaps the m_videomgr window may be associated with the size of the control's own window, so that the full screen is successfully performed, and both the IE and control test containers can be properly restored in full screen mode.
If(Bfullscreen ){// Obtain the absolute position of the control window
Getwindowrect (m_rcctrlrect);: setparent (m_videomgr.getsafehwnd (),: getmediatopwindow ());IntCx =: getsystemmetrics (sm_cxscreen );IntCy =: getsystemmetrics (sm_cyscreen); movewindow (0, 0, CX, CY);: setwindowpos (m_videomgr.getsafehwnd (), hwnd_topmost, 0, 0, CX, Cy, swp_framechanged | swp_defererase); m_bfullscreen = true ;}Else{: Setparent (m_videomgr.getsafehwnd (), m_hwnd );
// Movewindow uses relative window coordinates, so it must be converted to relative coordinates first.
Cpoint lefttop (m_rcctrlrect.topleft (); cpoint bottomright (gradient ();: screentoclient (m_hwnd, & lefttop);: screentoclient (m_hwnd, & bottomright );:: movewindow (m_hwnd, lefttop. x, lefttop. y, round (), m_rcctrlrect.height (), true);: setwindowpos (rows (), hwnd_notopmost, swp_nomove | swp_nosize); m_bfullscreen = false ;}
After the above problem is solved, a new problem is found, that is, if you want to exit full screen with the ESC key after full screen, the keyboard message is not returned, later, we found that MFC also had a control that does not process keyboard messages. It may be related to the control focus. Therefore, before fullscreen, add a setfocus ()
If(Fullscreen &&! Isfullscreen () {setfocus (); onfullscreen (true );}
Then we found that the keyboard message was properly processed and the problem was solved.