Click here to Skip to main content
Rate this: bad
good
Please Sign up or sign in to vote.
See more: VC6 C++ C MFC
Hello,
I want to know what is the best option to close a dialog based application, because I am really confused about these options:
SendMessage(WM_CLOSE);
PostMessage(WM_CLOSE);
DestroyWindow();
OnOK();
OnCancel();
PostQuitMessage(0);
or whatever else...
 
Thank you for your understanding.
Posted 11-Dec-12 5:42am
tomay30001.2K
Edited 11-Dec-12 5:43am
v2

1 solution

Rate this: bad
good
Please Sign up or sign in to vote.

Solution 1

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.
// 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);
}
  Permalink  

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

  Print Answers RSS
0 Sergey Alexandrovich Kryukov 335
1 OriginalGriff 250
2 Kornfeld Eliyahu Peter 130
3 DamithSL 120
4 Peter Leow 95
0 OriginalGriff 7,355
1 DamithSL 5,199
2 Sergey Alexandrovich Kryukov 4,942
3 Maciej Los 4,906
4 Kornfeld Eliyahu Peter 4,514


Advertise | Privacy | Mobile
Web04 | 2.8.141223.1 | Last Updated 11 Dec 2012
Copyright © CodeProject, 1999-2014
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100