QA: Why does not keyboard navigation work with HTML control?

Yaroslav Goncharov (yaroslav@softspb.com), February 05, 2003.

Question

HTML control does not respond to keyboard events in my Pocket PC application. How can I enable keyboard navigation in the HTML control?

Answer

There are 2 aspects that can disable keyboard navigation: an invalid initial focus and a dialog-based parent.

A dialog-based parent consumes keyboard events and does not give a chance to the HTML control to get them. There are several possibilities to fix it, but for the simplest solution use a generic parent window instead of a dialog.

Another interesting point is keyboard focus. The HTML control consists from 2 windows. You should set a focus to the inner window to enable keyboard navigation. A good place to do it is the end of the parent window's WM_CREATE handler.

HWND hWndInternal = GetWindow(hwndHtmlCtrl, GW_CHILD); SetFocus(hWndInternal);

Related resources: