如何检查是否单击了窗口上的关闭按钮?(红宝石) [英] How to check if you clicked the close button on the window? (Ruby)

查看:25
本文介绍了如何检查是否单击了窗口上的关闭按钮?(红宝石)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想问一下 Ruby 中的什么命令可以让您检查用 Ruby 制作的应用程序或正在运行的应用程序是否即将关闭?例如,我运行了一个可执行文件,然后单击了窗口上的关闭按钮.我想弹出一个对话框,上面写着你即将关闭".按下确定"按钮后,窗口最终关闭.

I just want to ask what command in Ruby allows you to check if an application made in Ruby or running application is about to be closed? For example, I have an executable file that i ran and I clicked the close button on the window. I want to make a pop up of a dialog that says "you are about to close". Once you pressed the OK button, the window finally closes.

如何在 Ruby 中做到这一点?

How can you do this in Ruby?

推荐答案

我不知道在 Ruby 中是如何工作的,但总的来说,在 Windows 上,当一个窗口收到关闭请求时,它的窗口过程会收到一个 WM_CLOSE 消息.这是向用户显示提示的地方.如果应用程序想要阻止窗口关闭(因为用户想要拒绝它等),应用程序可以简单地跳过销毁窗口,而不是将消息传递给默认消息处理程序(DefWindowProc()).

I don't know how things work in Ruby, but in general, on Windows, when a window receives a request to close, its window procedure receives a WM_CLOSE message. This is the place to display prompts to the user. If the app then wants to block the window from closing (because the user wants to reject it, etc), the app can simply skip destroying the window, and not pass the message on to the default message handler (DefWindowProc()).

如果用户点击窗口的关闭按钮,或从窗口弹出的系统菜单中选择关闭"选项,或在窗口处于焦点时按下ALT-F4,窗口收到一个 WM_SYSCOMMAND(SC_CLOSE) 消息,如果消息传递到默认消息处理程序,则窗口会收到 WM_CLOSE 消息.

In the case where the user clicks on the window's close button, or chooses the "Close" option from the window's pop-up system menu, or presses ALT-F4 while the window is in focus, the window receives a WM_SYSCOMMAND(SC_CLOSE) message, and if the message is passed on to the default message handler, the window then receives the WM_CLOSE message.

获取该信息并根据需要将其转换为 Ruby.

Take that information and translate it to Ruby as needed.

这篇关于如何检查是否单击了窗口上的关闭按钮?(红宝石)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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