CView::OnEraseBkgnd() is called from below function.
BOOL CWnd::OnWndMsg(UINT message, WPARAM wParam, LPARAM lParam, LRESULT* pResult)
{
[...]
case AfxSig_b_D_v:
lResult = (this->*mmf.pfn_b_D)(CDC::FromHandle(reinterpret_cast<HDC>(wParam)));
break;
[...]
}
https://learn.microsoft.com/en-us/cpp/mfc/reference/cdc-class?view=msvc-160#fromhandle clearly mentions, "The pointer may be temporary and should not be stored beyond immediate use."
-SM