Solved

Limiting Scrolling - Image in Window

Posted on 2000-03-20
2
162 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
Comment Utility
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
Comment Utility
Thanks.  I came to the same conclusion soon after posting the question.
0

Featured Post

How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

Join & Write a Comment

Introduction: Displaying information on the statusbar.   Continuing from the third article about sudoku.   Open the project in visual studio. Status bar – let’s display the timestamp there.  We need to get the timestamp from the document s…
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.
It is a freely distributed piece of software for such tasks as photo retouching, image composition and image authoring. It works on many operating systems, in many languages.

743 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