LRESULT WidDispatch::HandleMessage( UINT uMsg, WPARAM wParam, LPARAM lParam ) { LRESULT lResult = 1; Point pt(lParam); Widget* pWid = NULL; if (uMsg != WM_PAINT && uMsg != WM_TIMER && uMsg != WM_LBUTTONUP) { pWid = GetObject(m_h2oCaptured); if (pWid != NULL) { lResult = pWid->SendWidMessage(uMsg, wParam, lParam); return lResult; } } ProcessMessage(uMsg, wParam, lParam, lResult, 0); return lResult; }
BOOL WidDispatch::ProcessMessage( UINT uMsg, WPARAM wParam, LPARAM lParam, LRESULT& lResult, DWORD dwMsgMapID ) { Point pt(lParam); Widget* pWid = NULL; switch(uMsg) { case WM_ERASEBKGND: return lResult; case WM_PAINT: { // Handle WM_PAINT message Rect rcPaint; if( !::GetUpdateRect(m_hWnd, &rcPaint, FALSE) ) return 1; PAINTSTRUCT ps; ::BeginPaint(m_hWnd, &ps); OnPaint(ps.rcPaint); ::EndPaint(m_hWnd, &ps); } break; case WM_MOUSEMOVE: { pWid = GetWidPt(pt); if (pWid == NULL) { pWid = GetObject(m_h2oLastMouseMove); if (pWid != NULL) { pWid->SendWidMessage(WM_MOUSELEAVE); ClearH2O(m_h2oLastMouseMove); return lResult; } } else { HWID hWidNowMouse = pWid->GetHwid(); if (m_h2oLastMouseMove.first != hWidNowMouse) { Widget* pLastMouse = GetObject(m_h2oLastMouseMove); if (pLastMouse != NULL) { pLastMouse->SendWidMessage(WM_MOUSELEAVE); } SetMouseMoveH2O(std::make_pair(hWidNowMouse, pWid)); } lResult = pWid->SendWidMessage(WM_MOUSEMOVE, wParam, lParam); return lResult; } } break; case WM_LBUTTONDOWN: { WFX_CONDITION(m_hWnd != NULL); ::SetFocus(m_hWnd); pWid = GetWidPt(pt); if (pWid != NULL) { if (pWid->GetHwid() != m_h2oFocused.first && pWid != m_h2oFocused.second) { if (m_h2oFocused.second != NULL) { m_h2oFocused.second->SendWidMessage(WM_KILLFOCUS, (WPARAM)pWid->GetHwid()); } pWid->SendWidMessage(WM_SETFOCUS, (WPARAM)m_h2oFocused.first); } SetCapture(pWid); SetFocus(pWid); SetLButtonDown(pWid); lResult = pWid->SendWidMessage(uMsg, wParam, lParam); } else { if (m_h2oFocused.second != NULL) { m_h2oFocused.second->SendWidMessage(WM_KILLFOCUS, INVALID_HWID); } } } break; case WM_LBUTTONUP: { pWid = GetObject(m_h2oCaptured); if (pWid == NULL) { pWid = GetWidPt(pt); } if (m_h2oCaptured.first != INVALID_HWID) { ReleaseCapture(); ClearH2O(m_h2oCaptured); } if (pWid != NULL) { lResult = pWid->SendWidMessage(uMsg, wParam, lParam); Widget* pLastMM = GetObject(m_h2oLastMouseMove); if (pLastMM != NULL) { pLastMM->SendWidMessage(WM_MOUSELEAVE); } ClearH2O(m_h2oLastMouseMove); } pWid = GetWidPt(pt); if (pWid != NULL && m_h2oLButtonDown.first == pWid->GetHwid() && m_h2oLButtonDown.second == pWid) { pWid->SendWidMessage(WUM_LBUTTONCLICK, wParam, lParam); } ClearH2O(m_h2oLButtonDown); } break; case WM_TIMER: { pWid = GetWidgetFromTimer((UINT_PTR)wParam); if (pWid != NULL) { lResult = pWid->SendWidMessage(uMsg, wParam, lParam); } } break; case WM_KEYDOWN: case WM_MOUSEHWHEEL: case WM_MOUSEWHEEL: { pWid = GetObject(m_h2oFocused); if (pWid != NULL) { lResult = pWid->SendWidMessage(uMsg, wParam, lParam); } } break; case WM_COMMAND: { if (lParam == 0) { break; } HWND hWndChild = (HWND)lParam; lResult = ::SendMessageW(hWndChild, OCM__BASE + uMsg, wParam, lParam); break; } default: lResult = 0; } return lResult; }