Problem with handling tab key (focusing controls) in a window created by a dll

Michael_L 20 Reputation points
2024-08-06T16:27:07.8233333+00:00

Hello,

I'm developing virtual musical instrument software which can be used as a plugin in Digital Audio Workstations (DAW). The software is based on Steinberg's VST3 SDK and it is written in C++ in Visual Studio 2022.

VST3 plugins are DLLs. After being loaded by the host DAW, they expand the functionality of the DAW. Plugins usually come with their own GUI. The plugin DLL contains code for GUI creation, which is controlled by VST3 API functions the DLL provides and which get called by the host when importing the plugin.

The GUI of my plugin uses only standard Windows controls. I created my own wrapper classes for these controls, because it is difficult to use Windows Forms or MFC together with the Steinberg SDK.

Keyboard handling is all done by the host rather than handling WM_KEYDOWN messages by the plugin. The host notifies the plugin about a key being pressed through an API function. When receiving such a notification, my plugin evaluates the key that was pressed and reacts appropriately.

When you start the plugin, the first control in the GUI (an edit control) gets focused. By pressing the TAB key, one can focus the other controls one after another like in other Windows applications. Basically, this works fine.

Now here's the weird thing: Pressing TAB once moves the focus as expected from the edit control to the second control (which is a track bar). Now pressing TAB a second time is supposed to move the focus to the third control (a check box). However, the focus doesn't move from the track bar to the checkbox until you press TAB three times.

But this happens only once after launching the plugin. All following TABs act as desired: every single TAB moves the focus to the next control, even when you go back to the trackbar and press TAB to move focus to the check box. This proves that my TAB handling is working fine.

But there is another weird thing: if you launch the plugin and left-click anywhere inside its main window before pressing TAB, the problem described above doesn't occur. After clicking, you can move the focus from one control to the next every time you press TAB. Even moving the focus from the track bar to the checkbox requires only one TAB.

I couldn't find out yet what is the reason for this behavior. As a workaround, I simulate a mouse click inside the main window right after the first appearance of this window using SendInput(). This solves the problem that you have to press TAB three times to move focus from the track bar to the check box. But I consider this a very dirty workaround and like to fix the problem in a proper way.

Any ideas what could cause this strange behaviour and what to do to get rid of it? I would appreciate any help on this. Thanks in advance.

Regards, Michael

Windows API - Win32
Windows API - Win32
A core set of Windows application programming interfaces (APIs) for desktop and server applications. Previously known as Win32 API.
2,592 questions
{count} votes

Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.