There is one other option you can use to fix these problems, instead of creating the dialog window manually. You can use a Windows hook. This will enable you to retrieve all keyboard messages for the current thread and then call TranslateAccelerator so that accelerator keys will be processed. There is one problem with this approach, however. When the focus is on the WebBrowser control and you attempt to change focus between controls on the Web page by pressing tab, the focus will never leave the WebBrowser window. This means that you can Tab between controls on the Web page or between controls in your application, but not both.
There are four steps required to set up a Windows hook to work around the keystroke problems in a Win32 SDK dialog. First, declare your hook procedure in your header file.
static LRESULT CALLBACK GetMsgHookProc(int nCode, WPARAM wParam, LPARAM lParam);
Next, set your hook procedure during initialization by calling SetWindowsHookEx. Also, make sure to save the returned hook handle so that you can unhook the procedure when you are shutting down or when it is no longer needed.
// Declare this global handle in one of your project files.
HHOOK g_hook;
// Place this code inside an initialization
// method in your implementation file (.cpp)
g_hook = SetWindowsHookEx(WH_GETMESSAGE, GetMsgHookProc,
NULL, GetCurrentThreadId());
After that, implement your hook procedure and call TranslateAccelerator.
LRESULT CALLBACK CYourClass::GetMsgHookProc(int nCode, WPARAM wParam,
LPARAM lParam)
{
LPCKFSEARCH pThis = (LPCKFSEARCH)GetWindowLong(hwndMain, DWL_USER);
if (pThis && nCode >= 0)
{
MSG* pMsg = (MSG*)lParam;
// m_pOleInPlaceActObj is an IOleInPlaceActiveObject
// data member of the view class that is initialized
// after the WebBrowser control is loaded.
if (pThis->m_pOleInPlaceActObj)
pThis->m_pOleInPlaceActObj->TranslateAccelerator(pMsg);
// This causes the tab to work in the WebBrowser window. If you do not do
// this, tabbing will happen in the dialog only. You have the choice of
// tabbing in the dialog or the WebBrowser window, not both.
if (pMsg->wParam == VK_TAB)
ZeroMemory(pMsg, sizeof(MSG));
}
return CallNextHookEx(g_hook, nCode, wParam, lParam);
}
Finally, when your application is shutting down or when you no longer need the hook, unhook the procedure.
UnhookWindowsHookEx(g_hook);
注意:LPCKFSEARCH 我始终找不到在哪里定义,其实在ATL中可以
CComQIPtr<IOleControlSite, &IID_IOleControlSite>
spCtrlSite(m_spClientSite);
起到相同的作用。