GetViewportOrg is 16 bit!
I am implementing a mixed text/draw MDI application using document base class COleServerDoc and view base class CScrollView. Small documents are drawn beautifully, but the problem is larger ones. When the document is larger about 80 kb, or 2000 lines,
scrolling by dragging the scroll bar square will reset the window view to the beginning. In the OnDraw method I afxDump what GetViewportOrg returns: to my astonishment the y-value fails to exceed 32768 when scrolling down, it returns to zero at the same time when the display returns to the beginning of the document. This is an obvious 16 bit limitation. Is there any way around this?
I have tried another alternative: CRichEditDoc/CRichEditView, but I have trouble in making that MDI, and I'm not sure I can implement the drawing in this environment. I would rather stick to the base classes COleServerDoc/CScrollView.
Any ideas? Thanks.
# 1 Re: GetViewportOrg is 16 bit!
I had this problem too.
The only solution i found was not to use the Viewport functions,
and rely on the scroll position to simulate the viewport origin.
In a CScrollView derived class i had to overwrite the following
functions:
OnPrepareDC(CDC* pDC, CPrintInfo* pInfo)
{
CView::OnPrepareDC(pDC, pInfo);
//do some de preparations here
}
OnVScroll(UINT nSBCode, UINT nPos, CScrollBar* pScrollBar)
{
//nPos is 16 bit int
SCROLLINFO si;
si.cbSize=sizeof(SCROLLINFO);
si.fMask=SIF_ALL;
GetScrollInfo(SB_VERT,&si);
int yPos;
if(nSBCode==SB_THUMBTRACK)
yPos=si.nTrackPos; //32 bit int
else
yPos=si.nPos; //32 bit int
CScrollView::OnVScroll(nSBCode, yPos, pScrollBar);
}
OnHScroll(...) is similar to OnVScroll
SetScrollSizes(int nMapMode, SIZE sizeTotal, const SIZE &sizePage, const SIZE &sizeLine)
{
//FROM CScrollView
int nOldMapMode = m_nMapMode;
m_nMapMode = nMapMode;
m_totalLog = sizeTotal;
//BLOCK: convert logical coordinate space to device coordinates
{
CWindowDC dc(NULL);
ASSERT(m_nMapMode > 0);
dc.SetMapMode(m_nMapMode);
// total size
m_totalDev = m_totalLog;
dc.LPtoDP((LPSIZE)&m_totalDev); //this override allows 32 bit coordinates
//In the original function: dc.LPtoDP((LPPOINT)&m_totalDev); which transforms m_totalDev to 16 bit signed integer (-32768 .. 32768)
m_pageDev = sizePage;
dc.LPtoDP((LPSIZE)&m_pageDev);
m_lineDev = sizeLine;
dc.LPtoDP((LPSIZE)&m_lineDev);
if (m_totalDev.cy < 0)
m_totalDev.cy = -m_totalDev.cy;
if (m_pageDev.cy < 0)
m_pageDev.cy = -m_pageDev.cy;
if (m_lineDev.cy < 0)
m_lineDev.cy = -m_lineDev.cy;
} // release DC here
// now adjust device specific sizes
ASSERT(m_totalDev.cx >= 0 && m_totalDev.cy >= 0);
if (m_pageDev.cx == 0)
m_pageDev.cx = m_totalDev.cx / 10;
if (m_pageDev.cy == 0)
m_pageDev.cy = m_totalDev.cy / 10;
if (m_lineDev.cx == 0)
m_lineDev.cx = m_pageDev.cx / 10;
if (m_lineDev.cy == 0)
m_lineDev.cy = m_pageDev.cy / 10;
if (m_hWnd != NULL)
{
// window has been created, invalidate now
UpdateBars();
if (nOldMapMode != m_nMapMode)
Invalidate(TRUE);
}
}
and you have to modify OnDraw
(You may call GetScrollPos)