Solved

Limiting CScrollView scrolling area

Posted on 1998-06-19
5
325 Views
Last Modified: 2013-11-20
If you look at the display for a typical text file in Visual C++ you will see a grey area along the left hand border.  This prevents the characters from being placed too close to the left hand border, and gives a target area for mouse operations such as select line.  Scrolling does not effect the size of this area, it's always there.  Furthermore, the scroll bars go all the way to the left hand edge.

This is pretty slick, anyone know how it's done?  In particular I would like to do the same thing along the top of a vertically scrolling window.
0
Comment
Question by:jstolan
  • 3
5 Comments
 
LVL 15

Expert Comment

by:Tommy Hui
Comment Utility
That window is not a CScrollView. That window is a special window written so that the scrolling does not scroll the gray area horizontally (but it does scroll vertically). This isn't too hard if you realize that the ScrollWindow() API contains a rectangle to scroll.

The scrollbars are not inside this window because it is a child of the MDI frame. The MDI frame sends messages to the window whenever it needs to be scrolled. So there's quite a bit of communciation between the MDI frame and the scrolling window. The scrollbars sends the scroll messages to the MDI frame, which in turns sends the scroll messages to the scrolling window.

Of course, when the MDI frame is resized, it resizes and repositions all of its children.
0
 
LVL 2

Author Comment

by:jstolan
Comment Utility
thui

Thank you for your response.  However, I would really appreciate some sample code if you have it.  Or at least some direction as to where to find it.  I have quite a bit of code written based on a CScrollView class, and it's really not worth the effort to rewrite it just to get this added functionality.  Unless of course, I can get some sample code to lessen the effort.
0
 
LVL 1

Accepted Solution

by:
amby earned 100 total points
Comment Utility
I think that in fact you have to create a Class derived from CView, in place of CScrollView...

the reasons are that if you derive it from CView, you are 100% handling scrolling code... And the implementation of that is very simple (I had once to translate a class from CSrollView-derived to CView derived, it is a little work but now it is working fine...)

what you have to do:

replace into the class declaration file:
class MyView : public CView
{
.

// Overrides
// ClassWizard generated virtual function overrides
//{{AFX_VIRTUAL(CMyView)

//}}AFX_VIRTUAL
.
//----- added to reposition the scrollers when have to
//{{AFX_MSG(CMyView)
afx_msg void OnSize(UINT nType, int cx, int cy);
//}}AFX_MSG
}

and in the definition file, do not forget:

IMPLEMENT_DYNCREATE(CMyView, CView)

BEGIN_MESSAGE_MAP(CMyView, CView)
      //{{AFX_MSG_MAP(CLangMgrTextView)
      ON_WM_SIZE()
      //}}AFX_MSG_MAP
END_MESSAGE_MAP()

To completely handle you scrolls, add 2 scrollers (=attributes of your class) to your application in the OnCreate member (handler of WM_CREATE):

int CMyView::OnCreate()
{
    m_hScroll.Create( SBS_HORZ | other_styles, rect, this, ID_HSCROLL );
    m_vScroll.Create( SBS_VERT | other_styles, rect, this, ID_HSCROLL );
}

to handle painting, I usually use an 'offset' attribute for eache sense:
int m_hOffset
int m_vOffset

do not forget to handle your WM_VSCROLL and WM_HSCROLL to handle scrolling (use the ScrollWindow function, which is fast)

I don't know if this is enough to help you, in fact if you do that in his way, I am really convinced that you will soon have good results

Good luck

0
 
LVL 1

Expert Comment

by:amby
Comment Utility
you can try to handle the WM_WINDOWPOSCHANGING message,

the parameter of this massage is a structure containing the position of the window, try modifying them
0
 
LVL 1

Expert Comment

by:amby
Comment Utility
hem... sorry... I suppose I tried to help someone else this time...

sorry about that last comment...
0

Featured Post

What is SQL Server and how does it work?

The purpose of this paper is to provide you background on SQL Server. It’s your self-study guide for learning fundamentals. It includes both the history of SQL and its technical basics. Concepts and definitions will form the solid foundation of your future DBA expertise.

Join & Write a Comment

The article will include the best Data Recovery Tools along with their Features, Capabilities, and their Download Links. Hope you’ll enjoy it and will choose the one as required by you.
The Delta outage: 650 cancelled flights, more than 1200 delayed flights, thousands of frustrated customers, tens of millions of dollars in damages – plus untold reputational damage to one of the world’s most trusted airlines. All due to a catastroph…
This tutorial will walk an individual through the process of installing of Data Protection Manager on a server running Windows Server 2012 R2, including the prerequisites. Microsoft .Net 3.5 is required. To install this feature, go to Server Manager…
This tutorial will walk an individual through setting the global and backup job media overwrite and protection periods in Backup Exec 2012. Log onto the Backup Exec Central Administration Server. Examine the services. If all or most of them are stop…

762 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

7 Experts available now in Live!

Get 1:1 Help Now