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 4:42am
tomay30001.2K
Edited 11-Dec-12 4: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 CPallini 395
1 Sergey Alexandrovich Kryukov 333
2 BillWoodruff 309
3 OriginalGriff 307
4 George Jonsson 275
0 OriginalGriff 5,095
1 CPallini 4,285
2 Sergey Alexandrovich Kryukov 3,767
3 George Jonsson 2,941
4 Gihan Liyanage 2,386


Advertise | Privacy | Mobile
Web02 | 2.8.140916.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