即使控件具有焦点,也不会显示焦点矩形(Focus rectangle not showing even if control has focus)

编程入门 行业动态 更新时间:2024-10-28 08:21:41
即使控件具有焦点,也不会显示焦点矩形(Focus rectangle not showing even if control has focus)

我在MFC应用程序中遇到以下问题:

即使控件具有焦点,控件中的焦点矩形也不会始终显示。

重现步骤:

启动应用程序 点击控件 焦点矩形未显示: 使用Alt-Tab切换到另一个应用程序 切换回我的应用程序 点击控件 现在焦点矩形按预期显示: 从现在开始,控件上的焦点矩形会在获得焦点时正确显示。

这就像有两个“模式”,一个是显示焦点矩形,另一个是未显示。

其他事实:

控件确实具有焦点,因为使用向上/向下箭头键更改所选项目 它在Windows 10上运行 当我们处于未显示焦点矩形的“模式”时,程序的行为保持正确。

有人遇到过这样的问题吗? 我想知道这是否是一些“聪明”的微软功能。

I'm encountering following problem in my MFC application:

The focus rectangle in controls is not always showing up, even if the control has the focus.

Steps to reproduce:

starting the application clicking on the control focus rectangle is not shown: switching to another application with Alt-Tab switching back to my application clicking on the control now the focus rectangle is shown as expected: from now on the focus rectangles on controls are shown correctly as they gain focus.

It's like there were two "modes" one where focus rectangles are shown and one where they are not shown.

Other facts:

the control really does have the focus, as changing the selected item works using the up/down arrow keys it's running on Windows 10 when we are in the "mode" where the focus rectangles are not shown, the behaviour of the program remains correct.

Has anybody encountered such a problem? I wonder if this is some "clever" Microsoft feature.

最满意答案

这是一个称为“键盘提示”( SPI_GETKEYBOARDPREF和SPI_GETKEYBOARDCUES )的Windows功能,Windows的新版本默认在基于对话框的窗口中隐藏它们(焦点矩形和带下划线的键盘访问键)。 此功能是在Windows 2000中引入的 。

Windows对话框管理器根据最后一个输入 (鼠标或键盘)初始化对话框:

窗口的默认状态是显示所有指标。 但作为一个特殊技巧,对话框管理器将在初始化对话框后发送带有UIS_INITIALIZE的WM_UPDATEUISTATE消息,如果最后一个输入事件是鼠标事件,则会关闭指示符。

您可以使用MAKELONG(UIS_CLEAR, UISF_HIDEFOCUS)将WM_UPDATEUISTATE消息发布到对话框窗口,以显示焦点矩形(如果您希望覆盖Windows默认值)。

This is a Windows feature known as "Keyboard Cues" (SPI_GETKEYBOARDPREF and SPI_GETKEYBOARDCUES) and newer versions of Windows defaults to hiding them (focus rectangle and underlined keyboard access keys) in dialog based windows. This feature was introduced in Windows 2000.

The Windows dialog manager initializes dialogs based on the last input (mouse or keyboard):

The default state for a window is to show all indicators. But as a special trick, the dialog manager will send a WM_UPDATE­UI­STATE message with UIS_INITIALIZE after the dialog has been initialized, which turns off the indicators if the last input event was a mouse event.

You can post a WM_UPDATE­UI­STATE message to your dialog window with MAKELONG(UIS_CLEAR, UISF_HIDEFOCUS) to display the focus rectangle (if you wish to override the Windows defaults).

更多推荐

focus,焦点,shown,显示,电脑培训,计算机培训,IT培训"/> <meta name="description

本文发布于:2023-08-07 20:36:00,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1465709.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:焦点   矩形   控件   Focus   focus

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!