Hello i've been looking for a couple of days now how to avoid controls themselves from flickering in a CDialog.
I am using CMemDC and erasing the background to draw some basic shapes with GDI
void CCustomDialog::OnPaint()
{
CPaintDC pDC(this);
CMemDC dc(&pDC);
Gdiplus::Graphics graphics(dc.GetSafeHdc());
CRect clip;
dc.GetClipBox(&clip);
dc.FillSolidRect(clip, GetSysColor(COLOR_WINDOW));
DefWindowProc(WM_PAINT, (WPARAM)dc->m_hDC, (LPARAM)0);
Gdiplus::Pen pen(Gdiplus::Color(150, 125, 255, 100), 5.0);
graphics.DrawEllipse(&pen, 200, 50 m_interator, 100, 100);
}
This class inherits from CDialog and will then itself be a base class to other dialogs to control the "theme".
however when i invalidate and then update the window on a mouse move event
void CCustomDialog::OnMouseMove(UINT nFlags, CPoint point)
{
m_interator ;
Invalidate();
UpdateWindow();
CDialog::OnMouseMove(nFlags, point);
}
The Ellipse doesn't flicker at all but all the other buttons, labels and edit controls do.
I haven't found anything to avoid this and i myself do not know enough about MFC to avoid it.
Any ideas?
I was thinking maybe I can set the DC of the controls to be the same CMemDC, but i'm not sure how to do that yet, will post here if I figure it out.
CodePudding user response:
You can set the style WS_CLIPCHILDREN
in the dialog resource, for example:
IDD_STEP_DLG DIALOGEX 0, 0, 344, 215
// here:
STYLE DS_SETFONT | DS_FIXEDSYS | WS_MAXIMIZEBOX | WS_POPUP | WS_CLIPCHILDREN | WS_CAPTION | WS_SYSMENU | WS_THICKFRAME
CAPTION "Dialog"
FONT 8, "MS Shell Dlg", 400, 0, 0x1
BEGIN
LTEXT "Static",IDC_PREP_HISTOGRAM_PLACE,0,0,343,214,SS_NOTIFY | WS_TABSTOP
END