What happens when you close a c++ console application(关闭 C++ 控制台应用程序时会发生什么)
问题描述
我想这个问题说明了一切,但是,如果有人关闭了 C++ 控制台应用程序会发生什么?如,单击顶角的x".它会立即关闭吗?它会抛出某种异常吗?这是未定义的行为吗?
I guess the question says it all, but, what happens if someone closes a c++ console app? As in, clicks the "x" in the top corner. Does it instantly close? Does it throw some sort of exception? Is it undefined behavior?
推荐答案
关闭带有x"在顶角的 c++ 控制台应用程序会抛出一个 CTRL_CLOSE_EVENT
,如果您设置,您可以捕获和处理使用 SetConsoleCtrlHandler 函数的控制处理程序.在那里,您可以覆盖关闭功能并执行您想做的任何事情,然后仍然可以选择执行默认行为.
Closing a c++ console app with the "x" in the top corner throws an CTRL_CLOSE_EVENT
which you could catch and process if you set a control handler using the SetConsoleCtrlHandler function. In there you could override the close functionality and perform whatever you wished to do, and then optionally still perform the default behavior.
这篇关于关闭 C++ 控制台应用程序时会发生什么的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:关闭 C++ 控制台应用程序时会发生什么


基础教程推荐
- 为 C/C++ 中的项目的 makefile 生成依赖项 2022-01-01
- 管理共享内存应该分配多少内存?(助推) 2022-12-07
- 如何“在 Finder 中显示"或“在资源管理器中显 2021-01-01
- 为什么语句不能出现在命名空间范围内? 2021-01-01
- Windows Media Foundation 录制音频 2021-01-01
- 如何使图像调整大小以在 Qt 中缩放? 2021-01-01
- 从 std::cin 读取密码 2021-01-01
- 如何在不破坏 vtbl 的情况下做相当于 memset(this, ...) 的操作? 2022-01-01
- 在 C++ 中循环遍历所有 Lua 全局变量 2021-01-01
- 使用从字符串中提取的参数调用函数 2022-01-01