CHtmlView class and focus

Deadly 提交于 2019-12-11 21:51:49

问题


I have an SDI application written in MFC. The frame is divided into 1 row and 2 columns using a splitter window. Below are details of Row and Column (R0C0 means Row#0 and Col#0)

  1. R0C0 view is a CFormView with multiple input controls like text box, combo box etc.
  2. R0C1 view is a CHtmlView that contains HTML content relavant to the control that has input focus in the R0C0

I am able to update the HTML content and also invoke Javascript functions through my MFC code.

Problem: When user clicks on the R0C1, continaing CHtmlView, the focus is now on the html page. I wish to allow the user to tab out of R0C1 using the key board and return back to R0C0. Can you help with this please? The user can obviously click on the R0C0 view using mouse but we have a user who needs to use Keyboard for using this functionality.

Let me know if the question is not descriptive enough and I'll simplify it further.

Appreciate your time.

Thanks, Byte


回答1:


Try to overload CHtmlView::OnTranslateAccelerator. I have successfully used this trick to disable refresh with F5 key. Derive your own class from CHtmlView and overload

virtual HRESULT OnTranslateAccelerator(LPMSG lpMsg, const GUID* pguidCmdGroup, DWORD nCmdID);

like this:

HRESULT CMyHtmlView::OnTranslateAccelerator(LPMSG lpMsg, const GUID* pguidCmdGroup, DWORD nCmdID)
{
    if(lpMsg->message == WM_KEYDOWN && GetAsyncKeyState(VK_TAB) != 0 )
    {
        // change focus
        return S_OK;
    } 
    return CHtmlView::OnTranslateAccelerator( lpMsg, pguidCmdGroup, nCmdID);
}


来源:https://stackoverflow.com/questions/2544398/chtmlview-class-and-focus

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!