Solved

Limiting Scrolling - Image in Window

Posted on 2000-03-20
2
169 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

Independent Software Vendors: 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

Introduction: Ownerdraw of the grid button.  A singleton class implentation and usage. Continuing from the fifth article about sudoku.   Open the project in visual studio. Go to the class view – CGridButton should be visible as a class.  R…
Exception Handling is in the core of any application that is able to dignify its name. In this article, I'll guide you through the process of writing a DRY (Don't Repeat Yourself) Exception Handling mechanism, using Aspect Oriented Programming.
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.
There's a multitude of different network monitoring solutions out there, and you're probably wondering what makes NetCrunch so special. It's completely agentless, but does let you create an agent, if you desire. It offers powerful scalability …

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