繼this question我已決定重寫我的主窗口CMainFrame
的PreTranslateMessage
功能,以檢查是否已發送一個WM_MOUSEWHEEL
消息,如果它已經和消息的目標是組合框然後阻止該消息被分派。決定類型從HWND MFC對象
不過,我有一個問題,確定該消息的目標是一個組合框,這裏是我目前正在:
BOOL CMainFrame::PreTranslateMessage(MSG* pMsg)
{
CWnd* pWnd = CWnd::FromHandle(pMsg->hwnd);
if(pWnd)
{
if(pMsg->message == WM_MOUSEWHEEL)
{
CRuntimeClass* pRuntimeClass = pWnd->GetRuntimeClass();
bool bIsCombo = pRuntimeClass->IsDerivedFrom(RUNTIME_CLASS(CComboBox)) || pWnd->IsKindOf(RUNTIME_CLASS(CComboBox));
if(bIsCombo && !reinterpret_cast<CComboBox*>(pWnd)->GetDroppedState())
return TRUE;
}
}
return CFrameWndEx::PreTranslateMessage(pMsg);
}
然而,這不起作用,因爲運行時類總是似乎是CWnd
,所以我很想知道是否有辦法讓這個工作起作用?使用從CWnd*
到CComboBox*
的dynamic_cast
也似乎不起作用。
在此先感謝!