1
我正在編寫包裝舊版MFC richtext編輯器的WPF應用程序。我已經將richtext編輯器包裝在HwndHost中。 HwndHost控件位於WPF TabControl旁邊。WPF快捷方式在HwndHost中輸入時激活豐富的編輯控件
在 http://www.kempy.co.uk/code/Test.png 從聚焦問題,導航問題(上/下/左/右/標籤/輸入),我已成功地解決,我還有一個showstopping問題除了
截圖運行應用程序:
無論何時在面板上作爲快捷鍵的富文本控件中鍵入一個字符,該快捷鍵都會被激活,並且RichEdit控件從不會獲取該字符。附上一個簡單的測試項目來演示http://www.kempy.co.uk/code/Test.zip的行爲。即使富文本控件具有鍵盤焦點,在豐富的編輯控件中按P或C將會聚焦面板或單擊該按鈕。
僅供參考,這裏是允許的豐富的編輯控件來處理Tab鍵,回車鍵,上,下,左代碼,右
#undef TranslateAccelerator
virtual bool TranslateAccelerator (System::Windows::Interop::MSG% msg, ModifierKeys modifiers) = IKeyboardInputSink::TranslateAccelerator
{
AFX_MANAGE_STATE(AfxGetStaticModuleState());
if (msg.message == WM_KEYDOWN)
{
// we want tabs when the rich edit is focused, send rich edit control a tab WM_CHAR
if (msg.wParam == (IntPtr)VK_TAB)
{
if (GetFocus() == m_pRichEdit->GetSafeHwnd())
{
m_pRichEdit->SendMessage(WM_CHAR, '\t', 0);
return true;
}
else
{
return false;
}
}
else if (
msg.wParam == (IntPtr)VK_UP
|| msg.wParam == (IntPtr)VK_DOWN
|| msg.wParam == (IntPtr)VK_LEFT
|| msg.wParam == (IntPtr)VK_RIGHT
|| msg.wParam == (IntPtr)VK_RETURN)
{
// need cursor keys and enter/return, send KEYDOWN messages to rich edit control
m_pRichEdit->SendMessage(msg.message, msg.wParam.ToInt32(), msg.lParam.ToInt32());
return true;
}
}
return false;
}