0
votes

How would one prevent the little dotted square that appears on a button when it has the keyboard focus in a dialog. (w/ apologies for the technical jargon). At one point I hacked together a solution by subclassing a button WindowProc and subverting some windows messages, but wanted to know the correct way.

There's actually a problem with another control in the dialog also involving the keyboard. This other control is actually also a button, but being used as a group box or panel, not as a functioning button. But when I hit the tab key in the dialog, this group box "button" comes to the foreground obscuring the static controls on top of it, so I wanted to prevent that.

For both of the above, I tried turning off WS_TABSTOP - didn't help.)

2
You could try setting the focus to something else upon WM_SETFOCUS message being received.Brian R. Bondy
You know I believe that will actually work for the group box button. It did not work for the normal button however - it prevented the dotted square, but caused other problems (the button in question is actually a pushlike check box with the appearance of a normal button, but stays pushed when "checked". Its also of type BS_ICON, and I'm drawing a different icon on it depending on the state. so that didn't work correctly when disabling WM_SETFOCUS.Mark

2 Answers

1
votes

Both of my problems mentioned above were solved by subclassing the WndProcs and returning 0 in response to message 0x128 and discarding it. Even Spy++ could not identify this message 0x128, and I don't have it in any header. But its sent to every control in the dialog the first time tab is hit in the dialog.

(I did try BN_SETFOCUS as described above and also WM_SETFOCUS but it didn't help.)

So if anyone knows where to find what windows message 0x128 is...

0
votes

The correct way is to write your own button control instead of using the default Windows one.

Alternatively, you can prevent if from ever getting keyboard focus.