c++ - 为什么我的窗口已关闭,但应用程序有时仍在后台运行
问题描述
主.cpp:
#include <Windows.h>
LRESULT CALLBACK WndProc(HWND hWnd,
UINT msgID,
WPARAM wParam,
LPARAM lParam)
{
return DefWindowProc(hWnd, msgID, wParam, lParam);
}
int CALLBACK WinMain(_In_ HINSTANCE hIns,
_In_opt_ HINSTANCE hPreIns,
_In_ LPSTR lpCmdLine,
_In_ int nCmdShow)
{
WNDCLASS wc = { 0 };
wc.style = CS_HREDRAW | CS_VREDRAW;
wc.lpfnWndProc = WndProc;
wc.cbClsExtra = 0;
wc.cbWndExtra = 0;
wc.hInstance = hIns;
wc.hIcon = NULL;
wc.hCursor = NULL;
wc.hbrBackground = (HBRUSH)(COLOR_WINDOW + 1);
wc.lpszMenuName = NULL;
wc.lpszClassName = "MAINWINDOW";
RegisterClass(&wc);
HWND hWnd = CreateWindow("MAINWINDOW",
"mainwindow",
WS_OVERLAPPEDWINDOW,
100, 100, 500, 500,
NULL, NULL, hIns, NULL);
ShowWindow(hWnd, SW_SHOW);
MSG nMsg = { 0 };
while (GetMessage(&nMsg, NULL, 0, 0))
{
TranslateMessage(&nMsg);
DispatchMessage(&nMsg);
}
return 0;
}
我认为如果我关闭窗口,应用程序也应该关闭。但是,有时它按我的想法工作,有时窗口关闭但应用程序仍在运行。为什么以及如何确保在我关闭窗口后肯定退出应用程序
解决方案
推荐阅读
- scala - 为什么 maven 在进行全新安装时会给我这个 Scala 错误
- android - 活动窗口隐藏汉堡图标和导航工具栏
- python-3.x - 使用 PyQT5 在 QLCDNumber 上显示传感器输出
- c# - 在实体框架中执行sql查询时如何绑定部分类的额外属性?
- ios - React-Native + Apollo-Link-State + AWS Appsync:默认值不存储在缓存中
- c# - unity c# byte array to struct 包含数据数组
- javascript - 无法读取未定义的属性 - ReactJS
- c# - 想要打开多个音频文件并在 UWP 中播放
- android - 未找到 KeyStore 机读旅行证件实施
- python - Anaconda 打不开没有错误信息没有