Click here to Skip to main content
15,881,715 members
Please Sign up or sign in to vote.
2.00/5 (1 vote)
See more:
Hello,
I want to know what is the best option to close a dialog based application, because I am really confused about these options:
C++
SendMessage(WM_CLOSE);
PostMessage(WM_CLOSE);
DestroyWindow();
OnOK();
OnCancel();
PostQuitMessage(0);

or whatever else...

Thank you for your understanding.
Posted
Updated 11-Dec-12 4:43am
v2

1 solution

It depend on where you are in the application :

in the main dialog, you can use :
C++
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.
C++
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.
C++
// To Insert in message handlers
ON_MESSAGE(WM_USER,CMainDialog::OnUserMessage)
// To post the message: AfxGetMainWnd()->PostMessage(WM_USER);

LRESULT CMainDialog::OnUserMessage(WPARAM wParam, LPARAM lParam)
{
  // To do: CleanUp
  
  EndDialog(IDOK);
}
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900