OpenGL with MFC Scrollview

Hi,

Does anyone know how to enable scrolling in a window customized for OpenGL?

I have inherited from the ScrollView class. The view is customized for OpenGL using Ortho2D Projection. I can see the scroll bars and can click it. However, the window just gets messed up, having wrong/no update of the content. Moreover, the window is meant to enable user performing mouse clicks. I found that outside a certain area, the user mouse click has no effect. Can anyone tell me how to solve?

Many Thanks!!!

The scrolling logic of a CScrollView is tied into the Windows GDI. If you want a scroll bar to actually effect an OpenGL view, you will have to do a lot of the work yourself. Here is my suggestion:

  1. derive your view from CView (so that none of CScrollView’s scrolling is interfering in your code).
  2. add horizontal and vertical scroll bars as needed.
  3. process the WM_HSCROLL and WM_VSCROLL messages and implement your scrolling logic (ie, what you want the screen to do when someone presses the scroll bars).

Thanks a lot Korval!!

I agree with you suggestion, I think you have saved me much time!!

…or, derive your view from CScrollView and override the OnPrepareDC func:

void CMyScrollViewSubclass::OnPrepareDC(CDC* pDC, CPrintInfo* pInfo)
{
CView::OnPrepareDC(pDC, pInfo);
}

i think that will be easier - although i havent tried anything like this, so it might not work (but try it and let me know…)

He’s still got to process the WM_HSCROLL and WM_VSCROLL messages. Also, CScrollView does more than override OnPrepareDC. He’d have to search through CScrollView and rip out most of what it does and replace it with his own. Which would be more work than writing it from a CView, since he’d have to do that work anyway.

he has to process scroll messages anyway, if the scrollbars are to be of any use.

Even through scrollview does more internal stuff than preparing DC, none of it has any impact if OnPrepareDC is overriden, so let it do whatever it wants, we dont care!

Thank you for all your replies. I have successfully implemented the scrolling in OpenGL view. I just implement my own scrolling logic without using any CScrollView functionalities, although my view has been inherited from this MFC class a long time ago. It seems it is much easier to implement by myself rather than using the CScrollView, if the view is for OpenGL.