Solved

Limiting Scrolling - Image in Window

Posted on 2000-03-20
2
166 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
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

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
bigDiff challenge 17 135
isEverywhere  challenge 19 86
MaxSpan challenge 9 124
changeXy challenge 13 93
Introduction: Dynamic window placements and drawing on a form, simple usage of windows registry as a storage place for information. Continuing from the first article about sudoku.  There we have designed the application and put a lot of user int…
Introduction: Hints for the grid button.  Nested classes, templated collections.  Squash that darned bug! Continuing from the sixth article about sudoku.   Open the project in visual studio. First we will finish with the SUD_SETVALUE messa…
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.
Exchange organizations may use the Journaling Agent of the Transport Service to archive messages going through Exchange. However, if the Transport Service is integrated with some email content management application (such as an antispam), the admini…

726 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