Home > Software engineering >  MFC interface flicker problem
MFC interface flicker problem

Time:09-22

I use MFC to create dialog box procedure, set up a "composite" items in the properties dialog box to True, which USES double buffer from the bottom up coloring,
Application USES custom BMP image as a background, by modifying the OnPaint () function implementation, by modifying the OnCtlColor () function makes the static text box for transparent background, static text box refresh rate of 100 ms refresh time,

Minimization and maximize the program, all display controls start according to the refresh rate of flashing, as long as the program does not minimize will not flicker, a great god is what causes excuse me? How to change?

 void CRTSDlg: : OnPaint () 
{
CPaintDC dc (this);//device context for painting
If (IsIconic ())
{
The SendMessage (WM_ICONERASEBKGND, reinterpret_cast & lt; WPARAM> (dc) GetSafeHdc ()), 0);

//Center icon in the client rectangle
Int cxIcon=GetSystemMetrics (SM_CXICON);
Int cyIcon=GetSystemMetrics (SM_CYICON);
CRect rect;
GetClientRect (& amp; The rect);
Int x=(the rect. Width () - cxIcon + 1)/2;
Int y=(the rect. Height () - cyIcon + 1)/2;

//Draw the icon
Dc. DrawIcon (x, y, m_hIcon);
}
The else
{
The CDC dcMem.
BITMAP bm.
CRect rect;

M_Background. GetBitmap (& amp; Bm);
GetClientRect (& amp; The rect);
DcMem. CreateCompatibleDC (& amp; Dc);
CBitmap * oldbitmap=dcMem. SelectObject (& amp; M_Background);
Dc. BitBlt (0, 0, bm. BmWidth, bm. BmHeight, & amp; DcMem, 0, 0, SRCCOPY);
DcMem. SelectObject (oldbitmap);
CDialogEx: : OnPaint ();
}
}


 HBRUSH CRTSDlg: : OnCtlColor (CDC * pDC, CWnd * pWnd, UINT nCtlColor) 
{
HBRUSH gets=CDialogEx: : OnCtlColor (pDC, pWnd, nCtlColor);
If (CTLCOLOR_STATIC==nCtlColor)
{
The switch (pWnd - & gt; GetDlgCtrlID ())
{
Default:
PDC - & gt; SetTextColor (RGB (0, 0, 0));
PDC - & gt; SetBkMode (TRANSPARENT);
Gets=(HBRUSH) GetStockObject (NULL_BRUSH);
Return gets;
}
}
Else if (nCtlColor==CTLCOLOR_DLG)
Return m_brush;
//TODO: if the default brush is not required, it returns another brush
Return gets;
}


Minimize button code (in a variety of methods, are unable to solve the problem of flicker) :
 WINDOWPLACEMENT LWNDPL; 
The WINDOWPLACEMENT * LPWNDPL;
LPWNDPL=& amp; LWNDPL;
GetWindowPlacement (LPWNDPL);
LPWNDPL - & gt; ShowCmd=SW_SHOWMINIMIZED;
SetWindowPlacement (LPWNDPL);

CodePudding user response:

BOOL CxxxxDlg: : OnEraseBkgnd (pDC) CDC *
{
//TODO: Add your message handler code here and/or call the default

return TRUE;//CDialog: : OnEraseBkgnd (pDC);
}

CodePudding user response:

OnPaint block in calls to the parent class function
//CDialogEx: : OnPaint ();

CodePudding user response:

reference 1st floor schlafenhamster response:
BOOL CxxxxDlg: : OnEraseBkgnd (pDC) CDC *
{
//TODO: Add your message handler code here and/or call the default

return TRUE;//CDialog: : OnEraseBkgnd (pDC);
}


OnEraseBkgnd returns TRUE and FALSE, and can be found online to some of the methods are tried, no use,
The main problem is in the process not minimized, everything is normal, as long as to minimize the time, and then refresh the flicker phenomenon occurs when some controls, don't know in the process of minimization and restore it after,

CodePudding user response:

Minimize button the use of the code "
Don't respond to minimize button, try using the default code,

CodePudding user response:

1, OnEraseBkgnd direct return TRUE
2, to include WS_CLIPCHILD and WS_CLIPSIBLIINGS window style

CodePudding user response:

refer to 6th floor worldy response:
1, OnEraseBkgnd direct return TRUE
2, the window style to include WS_CLIPCHILD and WS_CLIPSIBLIINGS

The second point is very important, let child dialogs is responsible for their own, regardless of the parent dialog

CodePudding user response:

refer to 6th floor worldy response:
1, OnEraseBkgnd direct return TRUE
2, the window style to include WS_CLIPCHILD and WS_CLIPSIBLIINGS

CodePudding user response:

Using CBKDialogST classes, recommended dialog background,
  • Related