且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

如何检查是否单击了窗口上的关闭按钮?(红宝石)

更新时间:2023-11-30 17:32:52

我不知道在 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.