0

Win32 プログラムを作成していて、プログラムを終了する前にメッセージ ボックスを表示しようとしています。エラーを表示し、ユーザーがエラーを読んでOKを押した後に閉じたい。

これが私が試したことです:

MessageBoxA(hwnd, "An Error occured! Please restart the program and try again.", "Error", MB_ICONERROR);
PostQuitMessage(0);

MessageBoxA(0, "An Error occured! Please restart the program and try again.", "Error", MB_ICONERROR);
PostQuitMessage(0);

MessageBoxA(hwnd, "An Error occured! Please restart the program and try again.", "Error", MB_ICONERROR);
DestroyWindow(hwnd);

MessageBoxA(0, "An Error occured! Please restart the program and try again.", "Error", MB_ICONERROR);
DestroyWindow(hwnd);

hwnd私のアプリケーションのメイン (そして唯一の) ウィンドウはどこですか? メッセージボックスを表示しないだけでなく、プログラムをすぐに終了しません。多くのメッセージボックスが作成されているかのようにビープ音が連続して聞こえますが、表示されません。

メッセージボックスが表示され、ユーザーが [OK] を押すと、プログラムがすぐに終了するようにコードを変更するにはどうすればよいですか?

メインの WndProc で WM_CLOSE と WM_DESTROY を次のように処理しています。

case WM_CLOSE:
    DestroyWindow(hwnd);
    return 0;

case WM_DESTROY:
    PostQuitMessage(0);
    return 0;
4

2 に答える 2

0

メッセージを表示したら、を呼び出しますExitProcess

于 2013-03-11T11:21:57.810 に答える
0

ここで、このアプローチを試してください (簡単に応答を求めてから、EndDialog を呼び出すかどうかを決定します)。

#include <windows.h>
#include <commctrl.h>
#include <stdio.h>
#include "resource.h"

HINSTANCE hInst;

BOOL CALLBACK DlgMain(HWND hwndDlg, UINT uMsg, WPARAM wParam, LPARAM lParam)
{
    switch(uMsg)
    {
    case WM_INITDIALOG:
    {
    }
    return TRUE;

    case WM_CLOSE:
    {
        MessageBox(hwndDlg, "An Error occured! Please restart the program and try again.", "Error", MB_ICONERROR);
        EndDialog(hwndDlg, 0);
    }
    return TRUE;

    case WM_COMMAND:
    {
        switch(LOWORD(wParam))
        {
        }
    }
    return TRUE;
    }
    return FALSE;
}


int APIENTRY WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int nShowCmd)
{
    hInst=hInstance;
    InitCommonControls();
    return DialogBox(hInst, MAKEINTRESOURCE(DLG_MAIN), NULL, (DLGPROC)DlgMain);
}
于 2013-03-10T05:52:25.913 に答える