销毁窗口前显示的消息框
messagebox display before window is destroyed
我正在编写一个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,然后程序立即终止?
我正在处理WM_CLOSE和WM_DESTROY在我的主WndProc如下:
case WM_CLOSE:
DestroyWindow(hwnd);
return 0;
case WM_DESTROY:
PostQuitMessage(0);
return 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);
}
显示消息后,只需调用ExitProcess
。
相关文章:
- SDL 映像:无法打开映像,仅显示错误消息
- if/else 语句输出由于加号或减号而未显示正确的消息
- C++MSVC-显示未捕获的异常消息
- 大多数代码不仅显示欢迎消息和"enter pin"?
- boost::p rogram_options - 验证失败时,显示用户在错误消息中输入的值
- 可视C++消息框中函数的显示地址
- 错误 LNK1104:错误消息中显示的路径未在其他依赖项中定义
- C++未显示自定义异常消息
- 如何使用消息框函数显示 BSTR 值
- ROS2 COLCON构建未在Windows中显示任何错误消息
- winrt消息对话框未显示
- 为什么显示密码而不是消息
- 出现分段错误时,更改显示的消息错误
- C++/CLI 项目如何在控制台窗口中显示消息
- 从C函数上显示QTEXTEDIT上的消息
- git_remote_fetch返回错误并显示消息:"there is no TLS stream available"
- 格式化输出以显示在错误列表的消息部分中
- VS 代码显示编译 clang 的错误消息
- 显示错误消息框时出错.我该如何显示它
- 当我按值传递参数时,c++构建消息显示一个引用参数