Are you saying
PostMessage(AfxGetMainWnd()->m_hWnd, WM_CLOSE, NULL, NULL);