Archived

This topic is now archived and is closed to further replies.

ChrisO

OpenGL OpenGL & MFC scrollbars

Recommended Posts

I'm building an opengl app using MFC MDI to display various graphs in multiple child windows. Most of the time the graphs are too large to fit in the window, resizing them to fit in the window is no option (The graphs would be far too small) the solution would be to have scrollbars around the opengl view so I can scroll the graphs, I tried, but I can't get scrollbars around the view...how would I do this? [edited by - ChrisO on October 15, 2003 5:59:14 AM]

Share this post


Link to post
Share on other sites
The simplest solution to your problem is to create your view with scroll bars, by adding WS_VSCROLL and WS_HSCROLL to the style member of the CREATESTRUCT you can access in PreCreateWindow:



BOOL CTexView::PreCreateWindow(CREATESTRUCT& cs)
{

// Modify the wndclass as required...

cs.style |= WS_CLIPCHILDREN | WS_CLIPSIBLINGS | WS_VSCROLL;
return(CView::PreCreateWindow(cs));

}
Once you''ve done that, you can trap WM_VSCROLL and WM_HSCROLL messages with OnHScroll and and OnVScroll, and do your scrolling from there.



void CTexView::OnVScroll(UINT nSBCode, UINT nPos, CScrollBar* pScrollBar)
{

int y, yOrig;

// Call this view''s OnVScroll handler...

CView::OnVScroll(nSBCode, nPos, pScrollBar);

// Get the current scroll position...

y = yOrig = GetScrollPos(SB_VERT);

// Check the type of the scroll...

switch(nSBCode)
{

case SB_LINEUP: {
y -= 20;
} break;

case SB_LINEDOWN: {
y += 20;
} break;

case SB_PAGEUP: {
y -= m_Height;
} break;

case SB_PAGEDOWN: {
y += m_Height;
} break;

case SB_THUMBPOSITION: {
y = nPos;
} break;

case SB_THUMBTRACK: {
y = nPos;
} break;

}

// Check the new scroll value...

if(y > m_TotalHeight) y = m_TotalHeight;
if(y < 0) y = 0;

// Apply the scroll to the window...

if(y != yOrig)
{

SetScrollPos(SB_VERT, y);
m_ScrollOffset = y;
RedrawWindow();

}

}
You could also try using CScrollView. This gives you better scroll bars than WS_HSCROLL/WS_VSCROLL, but it doesn''t have any support for OpenGL, and moves the window''s GDI viewport around using the ScrollWindow() function. I tried using this; overrode all the functions with GDI stuff in them, and still couldn''t get it to work (when it scrolled, the OpenGL view just disappeared). Anyway, I''m using WS_HSCROLL/WS_VSCROLL in my editor, and it''s working very well...

[Insert witty signature here]

Share this post


Link to post
Share on other sites