WPF HwndHost keyboard focus
- by Adal
The chart area in the screenshot is a HwndHost control which hosts a native Win32 window (with it's own registered WNDCLASS) implemented in C++/CLI and drawn with Direct2D. The HwndHost is hosted in a WPF Border control.
The problem I have is that I can't set the keyboard focus to the hosted Win32 window. I want the focus to move to the hosted Win32 window when the used clicks on the chart area. I tried calling SetFocus on WM_LBUTTONDOWN, but that screws app the focus in the rest of the application.
Currently, even if I click on the Win32 window, the focus remains on the tree-view on the left, and if I press the up/down cursor keys, the tree-view will get them, not the chart window.
How do I make the hosted Win32 window receive keyboard input from when the user clicks on the chart area, until it clicks on another control (like the tree-view, or the toolbar)?