Click here to Skip to main content
11,493,391 members (69,414 online)
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 393
1 Maciej Los 286
2 F-ES Sitecore 224
3 KarstenK 210
4 CPallini 208
0 Sergey Alexandrovich Kryukov 10,132
1 OriginalGriff 8,630
2 Sascha Lefèvre 3,624
3 Maciej Los 3,392
4 Richard Deeming 2,500


Advertise | Privacy | Mobile
Web01 | 2.8.150520.1 | Last Updated 11 Dec 2012
Copyright © CodeProject, 1999-2015
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