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