MFC中关闭窗口的几种方式

    技术2025-07-20  10

    一. 关闭主窗口

    1、ExitProcess(0);

    2、AfxGetMainWnd()->SendMessage(WM_CLOSE);

    3、PostQuitMessage(0);//最常用

    二. 关闭对话框

    1、DestroyWindow();

    在使用时有可能出现断错误:

    程序崩溃是由DestroyWindow函数使用不当造成的。 MSDN中DestroyWindow函数中有这样一句话: A thread cannot use DestroyWindow to destroy a window created by a different thread. 这句话的意思是:在一个线程中我们不能使用DestroyWindow()函数销毁另一个线程创建的窗体。

    2、EndDialog(0);

    用于点击按钮关闭本窗口时推荐使用。

    Processed: 0.012, SQL: 10