Solved

Limiting Scrolling - Image in Window

Posted on 2000-03-20
2
163 Views
Last Modified: 2013-11-20
I have a problem with a feature that I added for scrolling around an
image in a window.  The feature allows a user to right click on the
image and drag it around.  The problem is that it will allow a user to
scroll an image right out of the window and this screws up the display
of the image (this happens when the window size is larger than the
image size).  Eg. image has a width of 100 pixels, but window size
has width 200 pixels.  I can right click on the image, move the mouse
left (you kind of have to move the mouse back and forth for the
problem to appear), and have the image scroll off of the screen to the
left.  I want to prevent this from happening.  Here's the code that
I currently have that attempts to do that.
pDoc->LeftImage->GetNumPixels() returns the total width of the image
that is displayed in the window.

void CDibEditorView::OnMouseMove(UINT nFlags, CPoint point)
{
      // TODO: Add your message handler code here and/or call default
      CDibEditorDoc* pDoc = GetDocument();
      
      
      if (pDoc->state == 1) {
            
            if ((nFlags & MK_RBUTTON) != 0) {   // if right mouse button is pressed
                  CPoint ScrollPosition = GetScrollPosition();
                  
                  ScrollPosition.x -= (point.x - pDoc->mouse_from.x); // calculates the amount that the mouse has been moved since the last OnMove call.
                  ScrollPosition.y -= (point.y - pDoc->mouse_from.y);
                  // Must find out size of the client area of the window
                  LPRECT pRect;
                  GetClientRect( pRect );
                  
                  if (pDoc->LeftImage->GetNumPixels() - ScrollPosition.x < pRect->right) {
                        ScrollPosition.x = 0;
                  }
                  if (pDoc->LeftImage->GetNumLines() - ScrollPosition.y < pRect->bottom) {
                        ScrollPosition.y = 0;
                  }
                  ScrollToPosition(ScrollPosition);
                  
                  pDoc->mouse_from.x = point.x;
                  pDoc->mouse_from.y = point.y;
                  
            }
      }
      
      
      CScrollView::OnMouseMove(nFlags, point);
}

Currently, the program crashes at GetClientRect( pRect ) with an
access violation.  I'm wondering about how to best go about
fixing my code to get the results that I desire.  I'm not sure whether
the code that I've written will fix things (after fixing the crashing
problem) or whether a different approach is needed.
0
Comment
Question by:mosaicer
2 Comments
 
LVL 12

Accepted Solution

by:
migel earned 50 total points
ID: 2639352
Hi!
// Must find out size of the client area of the window
>>LPRECT pRect;
>>GetClientRect( pRect );
problem is here !
ypou must supply pointer to the existing RECT obj that is:

RECT Rect;
GetClientRect( &Rect );
0
 

Author Comment

by:mosaicer
ID: 2640939
Thanks.  I came to the same conclusion soon after posting the question.
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
Installing Microsoft R server on REDHAT or SUSE Linux 4 131
Shell script to login to remote m/c and execute commands 10 78
has22 challenge 11 80
wait notify demo infinite loop 3 96
Introduction: The undo support, implementing a stack. Continuing from the eigth article about sudoku.   We need a mechanism to keep track of the digits entered so as to implement an undo mechanism.  This should be a ‘Last In First Out’ collec…
If you use Adobe Reader X it is possible you can't open OLE PDF documents in the standard. The reason is the 'save box mode' in adobe reader X. Many people think the protected Mode of adobe reader x is only to stop the write access. But this fe…
This video will show you how to get GIT to work in Eclipse.   It will walk you through how to install the EGit plugin in eclipse and how to checkout an existing repository.
As a trusted technology advisor to your customers you are likely getting the daily question of, ‘should I put this in the cloud?’ As customer demands for cloud services increases, companies will see a shift from traditional buying patterns to new…

896 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

11 Experts available now in Live!

Get 1:1 Help Now