C ++:如何检查我的窗口即将关闭? [英] C++: How do I check if my window is about to close?

查看:165
本文介绍了C ++:如何检查我的窗口即将关闭?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试制作一个基于Win32 / * nix控制台的ASCII游戏。我不想使用任何不是标准C ++或* nix / windows(.h)的库。

I'm trying to make a Win32/*nix console-based ASCII game. I want to use no libraries whatsoever that aren't standard C++ or on *nix/windows(.h).

我希望它像游戏循环一样被结构化。 Aka:

I want it to be structured like a game loop. Aka:

while (!WIN_CLOSE_FUNCTION()) {
  //Do crap
}
//Do other shutdown crap
return 0;

任何人都可以指出这是什么功能?如果它是平台依赖的,给我一个例子在Windows和* nix。

Can anyone point me to what function this would be? If it is platform dependent, give me one example on Windows and *nix.

推荐答案

类似的问题可能会帮助你关闭c ++控制台应用程序时会发生什么

Similar question that might help you What happens when you close a c++ console application

接受的答案是:
使用顶部的x关闭一个c ++控制台应用程序会抛出一个CTRL_CLOSE_EVENT,如果使用SetConsoleCtrlHandler设置了一个控制处理程序功能

The accepted answer is: 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.

有用的链接:

  • Console Event Handling
  • SetConsoleCtrlHandler

On * nix:

在Linux和其他Unix系统上,c鞋垫作为单独的过程运行。关闭外壳时,会将SIGHUP信号发送到当前活动的进程或后台未执行的进程。如果程序员没有处理,程序就会终止。如果您使用终端和活动进程关闭SSH会话,则会发送相同的信号。

On Linux and other Unix systems, the console runs as a separate process. As you close the shell, it sends the SIGHUP signal to the currently active process or processes that are not executed in the background. If the programmer does not handle it, the process simply terminates. The same signal is sent if you close the SSH session with a terminal and an active process.

由@Zyx在上述链接中提供的回答

answer provided by @Zyx in the question linked above

这篇关于C ++:如何检查我的窗口即将关闭?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆