Solved

Limiting CScrollView scrolling area

Posted on 1998-06-19
5
328 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

Backup Solution for AWS

Read about how CloudBerry Backup fully integrates your backups with Amazon S3 and Amazon Glacier to provide military-grade encryption and dramatically cut storage costs on any platform.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
vSphere client error 503 5 131
Robocopy questions 45 309
how to use laptop or pad camera in vb.net windows application 2 105
VMware SRM - Datastore not showing in Array Replication 11 120
How to fix error ""Failed to validate the vCentre certificate. Either install or verify the certificate by using the vSphere Data Protection Configuration utility" when you are trying to connect to VDP instance from Vcenter.
By default, Carbonite Server Backup manages your encryption key for you using Advanced Encryption Standard (AES) 128-bit encryption. If you choose to manage your private encryption key, your backups will be encrypted using AES 256-bit encryption.
This tutorial will walk an individual through the steps necessary to install and configure the Windows Server Backup Utility. Directly connect an external storage device such as a USB drive, or CD\DVD burner: If the device is a USB drive, ensure i…
This tutorial will walk an individual through the process of installing the necessary services and then configuring a Windows Server 2012 system as an iSCSI target. To install the necessary roles, go to Server Manager, and select Add Roles and Featu…

756 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