If you mean, you want to simulate the close button click,
PostMessage
WM_CLOSE
to your main frame window.
AfxGetMainWnd()->PostMessage(WM_CLOSE);
On the other hand, if you mean you want to handle the Close button click, just add a message handler for
WM_CLOSE
.