Prevent sub-window flashes in the MDI window

xiaoxiao2021-03-06  78

Keywords: MFC, MDI, Flicker Create a MDI project with Visual Studio, we will find that it often flicks on the Sub-window (CMDichildWnd), and when the embedded browser) is usually said. There are several cases: 1. Creating a new window when the current sub-window is in a maximizing state, and a process of flickering a rectangle will see. 2. The flashing phenomenon is not obvious when switching the window, but still exists in the edge edge (call MDINEXT and MDIPREV do not flash, and the calling MDIACTIVATE will cause blinking). 3. If there is a CControlbar on the mainframe, the SHOWCONTROLBAR is called when the SHOWCONTROLBAR is displayed / hidden panel, and the sub-window boundary will flash.

Solved method: 1 cs

CS.Style = WS_CHILD | WS_OVERLAPPED | WS_CAPTION | WS_SYSMENU | FWS_ADDTITE | WS_THICKFRAME | WS_MINIMIMIMIMIMIMIMIMIMIMIMIMIMIMIMIMIMIMIMIMIMIMIMIX | WS_MAXIMIZE; / / Set window style to maximize, but do not display, problem 1

Cs.cx = 1024; // Set the window size to the entire screen size, problem 2 cs.cy = 768;

IF (! cmdichildwndex :: precreatewindow (cs)) Return False;

cs.style | = ws_visible; // Create a completion of the window, the problem 1

Return True;}

2, the third problem method is to process the MDI Client area of ​​Mainframe, the MDI Client window handle of Mainframe (cmdiframeWnd) is saved in member variable m_hwndmdiclient, just need to lock the window update before calling ShowControlbar, calling ShowControlbar Recovering the update to eliminate flicker, the method can solve all the flicker caused by all sub-window changes, as follows: // Switch the panel of the display Void CMAINFRAME :: Togglerth (Ccontrolbar & PBar) {: SendMessage (m_hwndmdiclient, WM_SetredRAW, FALSE, 0L); showControlBar (! & pBar, pBar.IsVisible (), FALSE); :: SendMessage (m_hWndMDIClient, WM_SETREDRAW, TRUE, 0L); :: RedrawWindow (m_hWndMDIClient, NULL, NULL, RDW_UPDATENOW | RDW_ALLCHILDREN | RDW_INVALIDATE); // mandatory Heavy painting, including sub-window}

Calling the MDIACTIVATE Switch Switch Sub-window can also solve, but only need setRedraw, ... :: SendMDiClient, WM_SETREDRAW, FALSE, 0L); mdiactivate (ptmpchild) ;: SendMPCHILED, WM_SETREDRAW, TRUE, 0L);:: RedRawwindow (m_hwndmdinent, null, null, rdw_updatenow | rdw_allchildren | rdw_invalidate); // Forced redraw, including subsets ... As for the principle, I think it is package, for Ensure the update of the content of the window, when the redraw occurs, if the redraw is not fast enough and each window is redrawn, the flash is generated, so it is prohibited from re-painting when appropriate, and then recover when appropriate. You can solve the problem.

But always lock the update before the operation window, and then restore the update and trouble, it seems that you should be able to find two suitable locations to place these two sentences, and play the effect of life. For the third case, you can simply lock the update and recovery update during WM_WindowPosChanging and WM_WindowPSCHANGED, but in the first two cases, the window is involved in two windows. It is more troublesome.

转载请注明原文地址:https://www.9cbs.com/read-121481.html

New Post(0)