Note that there are some explanatory texts on larger screens.

plurals
  1. POWPF HwndHost keyboard focus
    primarykey
    data
    text
    <p>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.</p> <p>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 up the focus in the rest of the application.</p> <p>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.</p> <p>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)?</p> <p><a href="http://dl.dropbox.com/u/190212/public/wpf_hwndhost.png" rel="nofollow noreferrer">alt text http://dl.dropbox.com/u/190212/public/wpf_hwndhost.png</a></p> <p>EDIT: Here's the C++/CLI code for the window host:</p> <pre><code>template &lt;typename T&gt; inline T intPtrToPtr(IntPtr value) { return reinterpret_cast&lt;T&gt;(static_cast&lt;void*&gt;(value)); } public ref class ChartWindowHost : public HwndHost, IKeyboardInputSink { private: ChartWindow* chartWindow; // this is a C++ class doing the actual work protected: virtual HandleRef BuildWindowCore(HandleRef parent) override { chartWindow = new ChartWindow; const HINSTANCE hInstance = intPtrToPtr&lt;HINSTANCE&gt;(Marshal::GetHINSTANCE(Assembly::GetExecutingAssembly()-&gt;GetModules()[0])); const HWND parentWindow = intPtrToPtr&lt;HWND&gt;(parent.Handle); chartWindow-&gt;Create(hInstance, parentWindow); return HandleRef(this, IntPtr(chartWindow-&gt;GetHandle())); } virtual void DestroyWindowCore(HandleRef /*window*/) override { chartWindow-&gt;Destroy(); delete chartWindow; chartWindow = NULL; } }; </code></pre>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload