15 мая 2023 года "Исходники.РУ" отмечают своё 23-летие!
Поздравляем всех причастных и неравнодушных с этим событием!
И огромное спасибо всем, кто был и остаётся с нами все эти годы!

Главная Форум Журнал Wiki DRKB Discuz!ML Помощь проекту


CRectTracker with a CScrollView window

R. Kevin Burton -- kburton@mail.tds.net
Monday, November 18, 1996

Environment: VC++ 4.1, NT 3.51

I would like to use a CRectTracker with a CScrollView window. The effect
that I would like to acheive is to have the rectangle that is being
drawn as it is being dragged and then when it hits the edge of the
client view the view will scroll over. This would allow pan and scroll
of the window using only the mouse. My first attempt acheives the pan
and scroll part but the rectangle is not drawn properly when the  window
scrolls.

Basically I derived a class from CRectTracker and inserted my scrolling
code in the DrawRectTracker() that I have overridden. The code Is
included below. Does anyone have any suggestions?

----- ZoomTracker.h

#ifndef __ZOOMTRACKER__
#define __ZOOMTRACKER__
 
class CZoomTracker : public CRectTracker
{
public:
    CZoomTracker();
    CZoomTracker(LPCRECT lpSrcRect, UINT nStyle);
    virtual ~CZoomTracker();
 
    void DrawTrackerRect(LPCRECT lpRect, CWnd *pWndClipTo, CDC *pDC,
CWnd *pWnd);
};

----- ZoomTracker.cpp

#include "stdafx.h"
#include "ZoomTracker.h"
 
CZoomTracker::CZoomTracker() : CRectTracker()
{
}
 
CZoomTracker::CZoomTracker(LPCRECT lpSrcRect, UINT nStyle) :
    CRectTracker(lpSrcRect, nStyle) 
{
}
 
CZoomTracker::~CZoomTracker()
{
}
 
void CZoomTracker::DrawTrackerRect(LPCRECT lpRect, 
                                   CWnd *pWndClipTo, 
                                   CDC *pDC, CWnd *pWnd)
{
        CScrollView *pView = DYNAMIC_DOWNCAST(CScrollView, pWnd);
        if(pView)
        {
                CPoint scrollPoint = pView->GetScrollPosition();
                CSize totalSize = pView->GetTotalSize();
                CRect clientRect;
                CRect currentRect(lpRect);
                pView->GetClientRect(&clientRect);
                if(lpRect->right > clientRect.right)
                {
                       scrollPoint.x += lpRect->right -
clientRect.right;
              }
                if(lpRect->left < clientRect.left)
                {
                       scrollPoint.x -= clientRect.left - lpRect->left;
                }

                if(lpRect->bottom > clientRect.bottom)
                {
                       scrollPoint.y += lpRect->bottom -
clientRect.bottom;
                }
                if(lpRect->top < clientRect.top)
                {
                       scrollPoint.y -= clientRect.top - lpRect->top;
                }
                pView->ScrollToPosition( scrollPoint );
                CRectTracker::DrawTrackerRect(lpRect, pWndClipTo, pDC,
pWnd);
        }
        else
        {
                TRACE("This is not\n");
                CRectTracker::DrawTrackerRect(lpRect, pWndClipTo, pDC,
pWnd);
        }
}


-- 
Kevin Burton
kburton@waun.tdsnet.com

-- 
Kevin Burton
kburton@waun.tdsnet.com



Charles N. Johnson -- charlej9@mail.idt.net
Tuesday, November 19, 1996

[Mini-digest: 2 responses]

Kevin: I sound like a broken record...but try looking at "Visual C++4
How-To" by Stanfield and Arvensen in section 1.4, page 22: "How Do
I...Automatically Scroll A View During Mouse Drags?"

[Moderator's note: Fine, but what's the point of having a mailing
list to answer questions if all the answers are "go buy yet another
book"?]

Cheers--
Charles

----------
> From: Kevin Burton 
> To: mfc-l@netcom.com
> Subject: CRectTracker with a CScrollView window
> Date: Monday, November 18, 1996 12:05 PM
> 
> Environment: VC++ 4.1, NT 3.51
> 
> I would like to use a CRectTracker with a CScrollView window. The effect
> that I would like to acheive is to have the rectangle that is being
> drawn as it is being dragged and then when it hits the edge of the
> client view the view will scroll over. This would allow pan and scroll
> of the window using only the mouse. My first attempt acheives the pan
> and scroll part but the rectangle is not drawn properly when the  window
> scrolls.
> 
> Basically I derived a class from CRectTracker and inserted my scrolling
> code in the DrawRectTracker() that I have overridden. The code Is
> included below. Does anyone have any suggestions?
> 
> ----- ZoomTracker.h
> 
> #ifndef __ZOOMTRACKER__
> #define __ZOOMTRACKER__
>  
> class CZoomTracker : public CRectTracker
> {
> public:
>     CZoomTracker();
>     CZoomTracker(LPCRECT lpSrcRect, UINT nStyle);
>     virtual ~CZoomTracker();
>  
>     void DrawTrackerRect(LPCRECT lpRect, CWnd *pWndClipTo, CDC *pDC,
> CWnd *pWnd);
> };
> 
> ----- ZoomTracker.cpp
> 
> #include "stdafx.h"
> #include "ZoomTracker.h"
>  
> CZoomTracker::CZoomTracker() : CRectTracker()
> {
> }
>  
> CZoomTracker::CZoomTracker(LPCRECT lpSrcRect, UINT nStyle) :
>     CRectTracker(lpSrcRect, nStyle) 
> {
> }
>  
> CZoomTracker::~CZoomTracker()
> {
> }
>  
> void CZoomTracker::DrawTrackerRect(LPCRECT lpRect, 
>                                    CWnd *pWndClipTo, 
>                                    CDC *pDC, CWnd *pWnd)
> {
>         CScrollView *pView = DYNAMIC_DOWNCAST(CScrollView, pWnd);
>         if(pView)
>         {
>                 CPoint scrollPoint = pView->GetScrollPosition();
>                 CSize totalSize = pView->GetTotalSize();
>                 CRect clientRect;
>                 CRect currentRect(lpRect);
>                 pView->GetClientRect(&clientRect);
>                 if(lpRect->right > clientRect.right)
>                 {
>                        scrollPoint.x += lpRect->right -
> clientRect.right;
>               }
>                 if(lpRect->left < clientRect.left)
>                 {
>                        scrollPoint.x -= clientRect.left - lpRect->left;
>                 }
> 
>                 if(lpRect->bottom > clientRect.bottom)
>                 {
>                        scrollPoint.y += lpRect->bottom -
> clientRect.bottom;
>                 }
>                 if(lpRect->top < clientRect.top)
>                 {
>                        scrollPoint.y -= clientRect.top - lpRect->top;
>                 }
>                 pView->ScrollToPosition( scrollPoint );
>                 CRectTracker::DrawTrackerRect(lpRect, pWndClipTo, pDC,
> pWnd);
>         }
>         else
>         {
>                 TRACE("This is not\n");
>                 CRectTracker::DrawTrackerRect(lpRect, pWndClipTo, pDC,
> pWnd);
>         }
> }
> 
> 
> -- 
> Kevin Burton
> kburton@waun.tdsnet.com
> 
> -- 
> Kevin Burton
> kburton@waun.tdsnet.com
-----From: "Umesh Chandwani" 

I'm not sure what the problem is but here's a suggestion worth trying.

You are incrementing scrollPoint by physical units & then u are
calling pView->ScrollToPosition() which takes logical units.
You should convert physical units to logical units & then call
ScrollToPosition.
Hint :- Use DPtoLP to convert physical to Logical units.

Umesh.




| Вернуться в корень Архива |