mfc correctly closed the dialog modalities

In modal dialog box:

Normal user triggered OnOK, OnCancel messages are EndDialog by calling the function to close a modal dialog box, EndDialog function does not immediately clear the dialog box. But sets a flag, and allow the dialog box procedure returns control system. System is trying to retrieve from the application queue message before a detection flag. If the flag has been set, the system abort message loop, remove the dialog box, so when we want to call in the code EndDialog function to close the dialog box, and finally release the dialog object.

Function prototype: BOOL EndDialog (HWND hDlg, int  nResult);
  Parameters: 
  hDlg: represents a dialog window to be cleared. 
  NResult: specify the return value from the dialog creation functions to the application. 
  Return Value: If the function succeeds, the return value is nonzero; the function call fails if the returned value is zero. To get extended error information, call GetLastError

 


EndDialog DestroyWindow with distinction
(1) EndDialog (-1);


Close modal dialog box and call parameters as the return value of the parent.


(2) DestroyWindow (); :: PostQuitMessage (0);


DestroyWindow close modeless dialog. Exit the message loop, the real end of the process. There are a lot of program window closes, but does not mean out of operation. CDialog :: EndDialog


void EndDialog(int nResult);


parameter:

nResult dialog return value for the caller DoModal.
Description:
Call this member function to abort a modal dialog box. This function returns nResult. No matter when the modal dialog is being created, EndDialog must be used to end the process.

EndDialog can be called at any time, even when OnInitDialog, is displayed or turn it off before you get the input focus in the dialog box.

EndDialog will not immediately close the dialog box. It sets a flag to specify the current message handler returns to close the dialog box.

 

PS: problems encountered today: As the other end of the function call in a modal dialog box, without calling EndDialog function terminates the message loop, so the process can not exit normally, the system is suspended.

Reference Links:
https://blog.csdn.net/yangyihongyangjiying/java/article/details/44488343

Guess you like

Origin www.cnblogs.com/2018shawn/p/12652929.html