Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Focus rectangle not showing even if control has focus

Tags:

winapi

mfc

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: enter image description here
  • switching to another application with Alt-Tab
  • switching back to my application
  • clicking on the control
  • now the focus rectangle is shown as expected: enter image description here
  • 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.

like image 574
Jabberwocky Avatar asked Dec 13 '25 17:12

Jabberwocky


1 Answers

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).

like image 194
Anders Avatar answered Dec 16 '25 22:12

Anders



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!