Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

Limiting Scrolling - Image in Window

Posted on 2000-03-20
2
Medium Priority
?
174 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 200 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

New feature and membership benefit!

New feature! Upgrade and increase expert visibility of your issues with Priority Questions.

Question has a verified solution.

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

Introduction: Load and Save to file, Document-View interaction inside the SDI. Continuing from the second article about sudoku.   Open the project in visual studio. From the class view select CSudokuDoc and double click to open the header …
Have you tried to learn about Unicode, UTF-8, and multibyte text encoding and all the articles are just too "academic" or too technical? This article aims to make the whole topic easy for just about anyone to understand.
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.
Visualize your data even better in Access queries. Given a date and a value, this lesson shows how to compare that value with the previous value, calculate the difference, and display a circle if the value is the same, an up triangle if it increased…

610 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