如何在不影响ALT + F4或在任务栏中将其关闭的情况下重新调整窗口的关闭按钮的用途? [英] How do I repurpose a window's close button without affecting ALT+F4 or closing it in the taskbar?

查看:92
本文介绍了如何在不影响ALT + F4或在任务栏中将其关闭的情况下重新调整窗口的关闭按钮的用途?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用本机C ++和WinAPI编写程序.

I am making a program with native C++ and the WinAPI.

该程序有一个主应用程序窗口,我希望它具有一定的持久性.通过红色的X按钮关闭窗口似乎很自然,当我实际上不想退出程序时,我经常不小心按下它(Teamspeak就是这种情况).因此,我试图将红色的X按钮重新设置为最小化按钮,以避免意外退出.

This program has a main application window that I want to be somewhat persistent. It seems kind of natural to close a window via the red X button, and I often accidentally press it when I don't actually want to exit the program (this happens to me with Teamspeak). So, I'm trying to repurpose the red X button into a minimize button to avoid accidental exiting.

但是,我的应用程序应该有一些退出标准系统控件的程序的方法.我想允许使用ALT + F4,然后右键单击任务栏图标以将其关闭.我尝试拦截WM_CLOSE和SYSCOMMAND(SC_CLOSE),但这似乎禁用了退出程序的所有标准系统方法(在Process Explorer中无法杀死它-并不是真正的标准方法).

However, my application should have some way to exit the program with standard system controls. I want to allow ALT+F4 and right clicking on the taskbar icon to close. I tried intercepting WM_CLOSE and SYSCOMMAND (SC_CLOSE) but this seems to disable all standard system methods of exiting the program (short of killing it in Process Explorer - not really a standard method).

有没有办法只拦截窗口的红色X按钮?我注意到Windows Live Messenger可以做到这一点,但我不知道该怎么做.

Is there a way to only intercept the window's red X button? I noticed that Windows Live Messenger does this but I have no idea how.

推荐答案

处理WM_NCLBUTTONDOWN消息,并使用WM_NCHITTEST进行检查,单击是否将传递给HTCLOSE控件(这是您的红色[X ]解析为).或者,可以处理WM_NCHITTEST本身,并通过用其他内容代替返回值来防止发现窗口GUI的HTCLOSE部分.

Handle WM_NCLBUTTONDOWN message and use WM_NCHITTEST to check it the click is about to be delivered to HTCLOSE control (this is what your red [X] resolves to). Or alternatively, handle WM_NCHITTEST itself and prevent from discovering HTCLOSE part of your window GUI by replacing return value with something else.

这篇关于如何在不影响ALT + F4或在任务栏中将其关闭的情况下重新调整窗口的关闭按钮的用途?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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