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

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

问题描述

我试图做一个基于Win32 / * nix comsole的ASCII游戏。我想使用没有标准C ++或在* nix / windows(.h)上的库。

I'm trying to make a Win32/*nix comsole-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

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

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系统上,控制台作为一个单独的进程运行。当您关闭shell时,它会发送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天全站免登陆