How to end a dialog mfc application from CDialog::OnInitDialog or immediately after this function ends?

StackOverflow https://stackoverflow.com/questions/7718836

  •  08-02-2021
  •  | 
  •  

Вопрос

In one case of my application, I want to end the application in the dialog's OnInitDialog or immediately after this function. Is there any way to do it?

I tried using windows messages – in OnInitDialog calling SendMessage and in the handler of the sent message calling OnClose – but it didn't do what I intended since the dialog still appeared.

Это было полезно?

Решение

PostQuitMessage(0) in the WM_INITDIALOG handler body will do the job.

Другие советы

You can simulate the user clicking the X in the corner of the dialog by sending a WM_SYSCOMMAND message:

PostMessage(WM_SYSCOMMAND, SC_CLOSE, 0);
Лицензировано под: CC-BY-SA с атрибуция
Не связан с StackOverflow
scroll top