[英]Accelerator keys not working when modeless popup has the focus
我的主CDialog
有時會顯示一個子無模式對話框,如下所示:
僅當用戶將其配置為自動顯示時才會顯示。
它通過主對話框OnInitDialog
顯示,其中調用了此 function:
void CChristianLifeMinistryEditorDlg::DisplayAssignHistoryDialog()
{
BOOL bShowAssignHistoryDialog;
bShowAssignHistoryDialog = theApp.GetNumberSetting(_T("Options"), _T("SM_ShowAssignHist"), TRUE);
if (bShowAssignHistoryDialog)
{
m_pAssignHistoryDlg = std::make_unique<CAssignHistoryDlg>(); // .release();
if (m_pAssignHistoryDlg != nullptr)
{
m_pAssignHistoryDlg->SetAssignHistMap(&m_mapSPtrHist, &m_HistoryOriginal);
m_pAssignHistoryDlg->Create(IDD_DIALOG_ASSIGN_HISTORY, this);
m_pAssignHistoryDlg->ShowWindow(SW_SHOWNORMAL);
m_pAssignHistoryDlg->UpdateWindow();
m_pAssignHistoryDlg->EnableTree(false);
}
}
}
我注意到我的一些主要 windows 加速器熱鍵並不總是有效。 然后我意識到這是因為彈出窗口 window 具有焦點。 如果我單擊主對話框上的任意位置以使其獲得焦點,那么我的加速器熱鍵 function。
即使無模式 window 可能有焦點,有什么方法可以讓主編輯器輕松處理它的熱鍵? 一個標准的方法來滿足這個?
主要的 window 像這樣處理加速器:
BOOL CChristianLifeMinistryEditorDlg::PreTranslateMessage(MSG * pMsg)
{
if (m_hAccelTable)
{
if (::TranslateAccelerator(GetSafeHwnd(), m_hAccelTable, pMsg))
return TRUE;
}
}
並且彈出無模式 window 也使用PreTranslateMessage
(如果它是相關的):
BOOL CAssignHistoryDlg::PreTranslateMessage(MSG* pMsg)
{
BOOL bNoDispatch{}, bDealtWith = bDealtWith = FALSE ;
if ( (pMsg->message == WM_KEYDOWN || pMsg->message == WM_KEYUP ||
pMsg->message == WM_CHAR)
&& pMsg->wParam == VK_RETURN)
{
// Eat it.
bNoDispatch = TRUE ;
bDealtWith = TRUE ;
}
if (!bDealtWith)
bNoDispatch = CResizingDialog::PreTranslateMessage(pMsg);
return bNoDispatch ;
}
我會將您的m_hAccelTable
從CChristianLifeMinistryEditorDlg
傳遞給CAssignHistoryDlg
並將其添加到CAssignHistoryDlg::PreTranslateMessage
的開頭:
if (m_hAccelTable)
{
if (::TranslateAccelerator(GetParent(), m_hAccelTable, pMsg))
return TRUE;
}
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.