Professional UI Solutions
Site Map   /  Register
 
 

Forum

Please Log In to post a new message or reply to an existing one. If you are not registered, please register.

NOTE: Some forums may be read-only if you are not currently subscribed to our technical support services.

Forums » Prof-UIS Tech Support » Loss of Mouse Wheel event within CView when focus changes to treeview control Collapse All
Subject Author Date
Art Poley Sep 27, 2004 - 9:39 AM

I have an MDI application that contains a Dockable CExtTabPageContainerFlatWnd with three different tree controls.  I then have several Doc/Views available for manipulation of graphic objects.  The Mouse wheel event, ON_WM_MOUSEWHEEL, is used within my views to provide a mechanism for the user to zoom in/out.  What I’m noticing is whenever I manipulate/change focus to my treeview and then back to my CView the mousewheel event is no longer being delivered.  Each tree control is being created with the following:


 if( !this->Create(
  WS_CHILD|WS_VISIBLE|WS_VSCROLL|WS_HSCROLL|WS_TABSTOP
  |TVS_HASBUTTONS|TVS_HASLINES|TVS_LINESATROOT
  |TVS_INFOTIP|TVS_DISABLEDRAGDROP
  |TVS_SHOWSELALWAYS|TVS_TRACKSELECT,
  CRect(0,0,0,0),
  m_pTabsContainer,
  UINT(IDC_STATIC)
  )
  )


Any thoughts as to why?


Thanks in advance,


*** Art Poley ***

Technical Support Sep 28, 2004 - 7:02 AM

Dear Art,

We recommend you to use the MFC’s message pretranslating mechanism to implement the user-friendly mouse wheel handling. The main frame’s PreTranslateMessage method may look like:

 
BOOL CMainFrame::PreTranslateMessage( MSG * pMSG )
{
   if( pMSG->message == WM_MOUSEWHEEL )
   {
      if( m_wndTree1.PreTranslateMessage( pMSG ) )
         return TRUE;
      if( m_wndTree2.PreTranslateMessage( pMSG ) )
         return TRUE;
      if( m_wndTree3.PreTranslateMessage( pMSG ) )
         return TRUE;
      . . .
      CView * pView = GetActiveView();
      if( pView != NULL )
         if( pView->PreTranslateMessage( pMSG ) )
            return TRUE;
   }
   return CBaseClassOfYourMainFrame::PreTranslateMessage( pMSG );
}
This method in the view class or tree control-derived class may look like:
BOOL CYourControlOrView::PreTranslateMessage( MSG * pMSG )
{
   if( pMSG->message == WM_MOUSEWHEEL )
   {
        if( CExtToolControlBar::g_bMenuTracking )
            return FALSE;
        if( CExtPopupMenuWnd::IsMenuTracking() )
            return FALSE;
        if( GetSafeHwnd() == NULL )
            return FALSE;
        if( ! IsWindowVisible() )
            return FALSE;
        if( ! IsWindowEnabled() )
            return FALSE;
        CPoint ptCursor = pMsg->lParam;
        HWND hWndFromPoint = ::WindowFromPoint( ptCursor );
        if( hWndFromPoint != m_hWnd )
            return FALSE;
        CScrollBar * pScrollBarWnd = GetScrollBarCtrl( SB_VERT );
        if( pScrollBarWnd->GetSafeHwnd() != NULL )
        {
            if( ! pScrollBarWnd->IsWindowEnabled() )
                return FALSE;
        }
        else
        {
            DWORD dwWndStyle = CWnd::GetStyle();
            if( ( dwWndStyle & WS_VSCROLL ) == 0 )
                return FALSE;
        }
        int uWheelScrollLines = (int)
            g_PaintManager.GetMouseWheelScrollLines();
        int nToScroll =
            ::MulDiv( -zDelta, uWheelScrollLines, WHEEL_DELTA );
        if( nToScroll > 0 )
        {
            for( ; nToScroll > 0; nToScroll -- )
                SendMessage( 
   WM_VSCROLL, SB_LINEDOWN, LPARAM(pScrollBarWnd->GetSafeHwnd()) );
        }
        else if( nToScroll < 0 )
        {
            for( nToScroll = 
   - nToScroll; nToScroll > 0; nToScroll -- )
                SendMessage( 
   WM_VSCROLL, SB_LINEUP, LPARAM(pScrollBarWnd->GetSafeHwnd()) );
        }
    }
    return CBaseClassOfYourControlOrView::PreTranslateMessage
   ( pMSG );
}
This code will let you scroll the controls covered by the mouse pointer absolutely independently of the focused window state. This is the best way to handle the mouse wheel. The same mouse wheel behavior is implemented in the MS Office applications. Of course, you may improve the scrolling code and implement the horizontal scrolling when the CTRL key is pressed or when no vertical scrolling is available. It is also possible to implement the page up/down scrolling when some key is hold down.