It depend on where you are in the application :
in the main dialog, you can use :
EndDialog(code)
in an other modal dialog, you should use the returned value of the DoModal method to stop or not your application when you are back in a main dialog method.
void CMainDialog::OnButtonClick()
{
CSubDialog dlg;
if(dlg.DoModal()==IDOK)
EndDialog(IDOK);
}
in a modeless dialog, post a specific message to your main dialog and do action in it.
ON_MESSAGE(WM_USER,CMainDialog::OnUserMessage)
LRESULT CMainDialog::OnUserMessage(WPARAM wParam, LPARAM lParam)
{
EndDialog(IDOK);
}