scrolling and selection 
Author Message
 scrolling and selection

Hi All,

I've a CWnd derived class called CCurveViewer that displays a simple curve.
I'm implementating selection and scrolling in the curve. I want when the
user select the curve by holding down mouse button and dragging it left or
right, as the mouse pointer approaches left or right client area boundary,
the curve should start scrolling extending the selection region. I've
implemented this logic using OnMouseMove handler but the problem is the user
has to keep mouse moving in a particular region to extend the selection
region. I want even if the mouse is not moving but the cursor is in a
specified region, the curve should scroll and select. Just like in most text
editors or Windows Explorer.

Here is the OnMouseMove. Works OK but has to keep mouse moving in a region
close to curve boundary.

void CCurveViewer::OnMouseMove(UINT nFlags, CPoint point)
{
 if (m_bCurveSelectionEnabled)
 {
  if((nFlags & MK_LBUTTON))
  {
   CRect rcWindow, rcClient, rcSelection, rcPrevSelection;

   GetClientRect(&rcClient);
   GetWindowRect(&rcWindow);
   GetSelectionRect(rcPrevSelection);
   m_lSelectionEnd = m_CurveViewerOps->GetSampleIndexFromXPosition(point.x,
rcWindow);
   m_CurveSelection = SELECTION_DRAG;

   if (point.x + 5 >= rcClient.right)
    Scroll(5);
   if (point.x - 5 <= rcClient.left)
    Scroll(-5);

   GetSelectionRect(rcSelection);
   InvalidateRect(&rcPrevSelection, FALSE);
   InvalidateRect(&rcSelection, FALSE);
  }
 }

I could detect if the mouse coordinates are in a specific region but where
should i check it. I need continuous scrolling and selection if the user has
started selection and mouse is in a specific curve region.

Thanks
Irfan



Sun, 24 Apr 2005 23:00:21 GMT  
 scrolling and selection
Create a "hot" region at the borders. When the mouse moves into that region during a drag,
start a timer. Each time the timer fires, you scroll in the appropriate direction.
OnLButtonUp cancels the timer.

Have you heard of #define? Are you aware that 5 is a meaningless number because on a
1600x1280 display this is almost unfindable? You might try something like
        ::GetSystemMetrics(SM_CYCAPTION) / 2
or something else that ties better to resolution.

#define MYSCROLL_NONE 0
#define MYSCROLL_DOWN 0x01
#define MYSCROLL_UP        0x02
#define MYSCROLL_LEFT    0x10
#define MYSCROLL_RIGHT 0x20
#define IsVertical(x) (Vert(x) != 0)
#define IsHorizontal(x) (Horz(x) != 0)
#define Vert(x) ((x) & 0x0F)
#define Horz(x) ((x) & 0xF0)

// direction is a member variable of your class

void CMyView::OnMouseMove(....)
    {
     CRect rect;
     GetClientRect(&rect);

     direction = MYSCROLL_NONE;

     if(point.y < limit) // scroll down
       direction |= MYSCROLL_DOWN;
     else
     if(point.y > rect.Height() - limit) // scroll up
       direction |= MYSCROLL_UP;

     if(point.x < limit) // scroll to right
       direction |= MYSCROLL_RIGHT;
     else
     if(point.x > rect.Width() - limit) // scroll to left
       direction |= MYSCROLL_LEFT;

#define INTERVAL 150 // or some suitable number
    if(direction != MYSCROLL_NONE)
       SetTimer(IDT_SCROLL, INTERVAL, NULL);
   ...
   } // OnMouseMove

void CMyView::OnTimer(...)
    {
     switch(id)
        { /* id */
         IDT_SCROLL:
              DoScroll();
              return;
        ...other cases herre if necessary
       } /* id */
   }

void CMyView::DoScroll()
   {
    switch(Vert(direction))
       { /* Vert */
        case MYSCROLL_UP:
            ... scroll up
            break;
       case MYSCROLL_DOWN:
             ....scroll down
            break;
      } /* Vert */
   switch(Horz(direction))
      { /* Horz */
        case MYSCROLL_LEFT:
            ...scroll left
            break;
       case MYSCROLL_RIGHT:
           ...scroll right
           break;
      } /* Horz */

Key to success in Windows is not to think of conditions like in non-event programming, and
react to them, but to use them as predicate to initiate actions that can be handled later.
                                        joe

Quote:

>Hi All,

>I've a CWnd derived class called CCurveViewer that displays a simple curve.
>I'm implementating selection and scrolling in the curve. I want when the
>user select the curve by holding down mouse button and dragging it left or
>right, as the mouse pointer approaches left or right client area boundary,
>the curve should start scrolling extending the selection region. I've
>implemented this logic using OnMouseMove handler but the problem is the user
>has to keep mouse moving in a particular region to extend the selection
>region. I want even if the mouse is not moving but the cursor is in a
>specified region, the curve should scroll and select. Just like in most text
>editors or Windows Explorer.

>Here is the OnMouseMove. Works OK but has to keep mouse moving in a region
>close to curve boundary.

>void CCurveViewer::OnMouseMove(UINT nFlags, CPoint point)
>{
> if (m_bCurveSelectionEnabled)
> {
>  if((nFlags & MK_LBUTTON))
>  {
>   CRect rcWindow, rcClient, rcSelection, rcPrevSelection;

>   GetClientRect(&rcClient);
>   GetWindowRect(&rcWindow);
>   GetSelectionRect(rcPrevSelection);
>   m_lSelectionEnd = m_CurveViewerOps->GetSampleIndexFromXPosition(point.x,
>rcWindow);
>   m_CurveSelection = SELECTION_DRAG;

>   if (point.x + 5 >= rcClient.right)
>    Scroll(5);
>   if (point.x - 5 <= rcClient.left)
>    Scroll(-5);

>   GetSelectionRect(rcSelection);
>   InvalidateRect(&rcPrevSelection, FALSE);
>   InvalidateRect(&rcSelection, FALSE);
>  }
> }

>I could detect if the mouse coordinates are in a specific region but where
>should i check it. I need continuous scrolling and selection if the user has
>started selection and mouse is in a specific curve region.

>Thanks
>Irfan

Joseph M. Newcomer [MVP]

Web: http://www3.pgh.net/~newcomer
MVP Tips: http://www3.pgh.net/~newcomer/mvp_tips.htm


Mon, 25 Apr 2005 01:36:21 GMT  
 scrolling and selection

Quote:

> Hi All,

> I've a CWnd derived class called CCurveViewer that displays a simple curve.
> I'm implementating selection and scrolling in the curve. I want when the
> user select the curve by holding down mouse button and dragging it left or
> right, as the mouse pointer approaches left or right client area boundary,
> the curve should start scrolling extending the selection region. I've
> implemented this logic using OnMouseMove handler but the problem is the user
> has to keep mouse moving in a particular region to extend the selection
> region. I want even if the mouse is not moving but the cursor is in a
> specified region, the curve should scroll and select. Just like in most text
> editors or Windows Explorer.

> Here is the OnMouseMove. Works OK but has to keep mouse moving in a region
> close to curve boundary.

> void CCurveViewer::OnMouseMove(UINT nFlags, CPoint point)
> {
>  if (m_bCurveSelectionEnabled)
>  {
>   if((nFlags & MK_LBUTTON))
>   {
>    CRect rcWindow, rcClient, rcSelection, rcPrevSelection;

>    GetClientRect(&rcClient);
>    GetWindowRect(&rcWindow);
>    GetSelectionRect(rcPrevSelection);
>    m_lSelectionEnd = m_CurveViewerOps->GetSampleIndexFromXPosition(point.x,
> rcWindow);
>    m_CurveSelection = SELECTION_DRAG;

>    if (point.x + 5 >= rcClient.right)
>     Scroll(5);
>    if (point.x - 5 <= rcClient.left)
>     Scroll(-5);

>    GetSelectionRect(rcSelection);
>    InvalidateRect(&rcPrevSelection, FALSE);
>    InvalidateRect(&rcSelection, FALSE);
>   }
>  }

> I could detect if the mouse coordinates are in a specific region but where
> should i check it. I need continuous scrolling and selection if the user has
> started selection and mouse is in a specific curve region.

> Thanks
> Irfan

Start a timer (SetTimer) when you want to start scrolling.  Handle the
WM_TIMER message and scroll a little bit on each message until you want
to stop scrolling.  Then call KillTimer.  You should also be using
SetCapture and ReleaseCapture so you can keep scrolling when the mouse
moves outside your window's client area.

--
Scott McPhillips [VC++ MVP]



Mon, 25 Apr 2005 02:23:11 GMT  
 
 [ 3 post ] 

 Relevant Pages 

1. Scrolling and Selection

2. scrolling and selection

3. CPrintDialog Printer selection ComboBox does not scroll for large number of printers

4. Clean Selection Only or Build Selection Only

5. any way to make the scroll in one datagrid bind to the scroll in another datagrid

6. ?? using scroll view with large scroll size

7. how:hide CListCtrl scroll bar and scroll programmatically

8. Attached a scroll-bar to MainFrame..Scrolling problem..

9. Moving Scroll bar of the Scroll View

10. How does Write scroll selection when its lost mouse messages ?

11. Default item selection in Context Menu

12. selection of all databases fails partially

 

 
Powered by phpBB® Forum Software