Solved

Limiting CScrollView scrolling area

Posted on 1998-06-19
5
327 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
ID: 1318232
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
ID: 1318233
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
ID: 1318234
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
ID: 1318235
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
ID: 1318236
hem... sorry... I suppose I tried to help someone else this time...

sorry about that last comment...
0

Featured Post

Best Practices: Disaster Recovery Testing

Besides backup, any IT division should have a disaster recovery plan. You will find a few tips below relating to the development of such a plan and to what issues one should pay special attention in the course of backup planning.

Question has a verified solution.

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

Suggested Solutions

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…
Are you looking to recover an email message or a contact you just deleted mistakenly? Or you are searching for a contact that you erased from your MS Outlook ‘Contacts’ folder and now realized that it was important.
This tutorial will walk an individual through the steps necessary to enable the VMware\Hyper-V licensed feature of Backup Exec 2012. In addition, how to add a VMware server and configure a backup job. The first step is to acquire the necessary licen…
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…

770 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