IDocHostUIHandler::TranslateAcceleratorショートカット不応答解決方法(すなわちctrl+c、ctrl+vが機能しない解決方法)

4125 ワード

ctrl+c,ctrl+vが機能しない場合、CHtmlViewを使用している場合は、そのBUGの1つであり、リソースファイルに以下の内容を加えることで解決できます:////////////////////////////////////////////////////////////////////////////////////////////////////////////////XTPRO2 ACCELERATORS BEGIN     “C”,            ID_EDIT_COPY,           VIRTKEY, CONTROL, NOINVERT     “X”,            ID_EDIT_CUT,            VIRTKEY, CONTROL, NOINVERT     “V”,            ID_EDIT_PASTE,VIRTKEY,CONTROL,NOINVERT ENDはC,X,Vの先頭の3行が入っていて、これは比較的簡単です.今日の討論のテーマはCHtmlViewの問題ではなく、標準Winodws API SDKのプログラミングの下で、IWebBrowser 2のショートカットキーの問題をどのように処理するかである.
一.TranslateAcceleratorはなぜ呼び出されないのですか?IDocHostUIHandler::TranslateAccelerator Method is Called by MSHTML when IOleInPlaceActiveObject::TranslateAccelerator or IOleControlSite::TranslateAccelerator is called
IOleInPlaceActiveObject::TranslateAccelerator -  Processes menu accelerator-key messages from the container’s message queue. This method should only be used for objects created by a DLL object application. An object created by an EXE object application gets keystrokes from its own message pump, so the container does not get those messages.If you need to implement this method, you can do so by simply wrapping the call to the Window’s TranslateAccelerator function.
IOleControlSite::TranslateAccelerator – Instructs the control site to process the keystroke.This method is called by a control that can be UI-active. In such cases, a control can process all keystrokes first through IOleInPlaceActiveObject::TranslateAccelerator, according to normal OLE Compound Document rules. Inside that method, the control can give the container certain messages to process first by calling IOleControlSite::TranslateAccelerator and using the return value to determine if any processing took place. Otherwise, the control always processes the message first. If the control does not use the keystroke as an accelerator, it passes the keystroke to the container through this method. 以上のY文では、IOleInPlaceActiveObjectまたはIOleControl SiteのTranslateAcceleratorメソッドが呼び出される必要があります.IDocHostUIHandler::TranslateAcceleratorが応答します.IDocHostUIHandler::TranslateAcceleratorはアクティブに応答するのではなく、アプリケーションフレームワークが呼び出されます.呼び出された場所はメッセージポンプで処理されています.
二.TranslateAcceleratorを呼び出すにはどうすればいいですか?CHtmlViewでは、次のようにTranslateAcceleratorを呼び出します.
BOOL CHtmlView::PreTranslateMessage(MSG* pMsg)
{
 //       
 //…..
 
 // check if the browser control wants to handle the message
 BOOL bRet = FALSE;
 if(m_pBrowserApp != NULL)
 {
  CComQIPtr spInPlace = m_pBrowserApp;
  if (spInPlace)
   bRet = (spInPlace->TranslateAccelerator(pMsg) == S_OK) ? TRUE : FALSE;
 }
 return bRet;
}

PreTranslateMessageは、MFCにおけるメッセージ配信前の前処理メッセージメカニズムである、発信者決定メッセージ配信パスを提供することを目的とする.
私のプログラムにはこのような関数がないので、メッセージを送るのは難しいです.IWebBrowser 2はctrl+c、ctrl+v、ctrl+xなどのすべてのキーボードショートカットに応答できません.したがって、解決の鍵は、メッセージ配信メカニズムを実装することです.次のエントリ関数を参照してください.
//MFC       ,     
BOOL AFXAPI AfxInternalPumpMessage()
{
 _AFX_THREAD_STATE *pState = AfxGetThreadState();
 if (!::GetMessage(&(pState->m_msgCur), NULL, NULL, NULL))
 {
  // Note: prevents calling message loop things in ‘ExitInstance’
  // will never be decremented
  return FALSE;
 }
  // process this message
 if (pState->m_msgCur.message != WM_KICKIDLE && !AfxPreTranslateMessage(&(pState->m_msgCur)))
 {
  ::TranslateMessage(&(pState->m_msgCur));
  ::DispatchMessage(&(pState->m_msgCur));
 }
  return TRUE;
}

在::TranslateMessage(&(pState->m_msgCur);以前、ブラウザウィンドウがフォーカスを取得する場合、TranslateMessage(&(pState->m_msgCur))の実行を禁止するべきであったので、その前に自分のAfxPreTranslateMessage関数を加えるべきである.この関数でCHtmlView::PreTranslateMessage(.)を呼び出します.これにより、ショートカットキーが応答しないという問題が解決する.
三.総括およびその他の態様IWebBrowser 2におけるレプリケーションの鍵:1.メニューコピー、コンストラクション関数に追加する必要があります:OleInitialize(NULL);2.ショートカットキーのコピーは、IOleInPlaceActiveObjectインタフェースを処理する必要があります.一般的にCHtmlView::PreTranslateMessage(MSG*pMsg)で処理します.CHtmlViewクラスではなく、MFC/ATLなどを使用していない場合は、メッセージの入り口で処理する必要があります.そうしないと、WebBrowserキーが応答しない可能性があります.PreTranslateMessageの戻り値を合理的に処理するには、FALSEのときにメッセージを伝えます.