窗口映射模式的问题(关于beginning Visual C++的一个例子)100分求高手帮忙!
关于beginning Visual C++的一个例子问题,是这样,我跟做的一个画图程序,里面涉及到好多坐标映射变化的问题,一开始View类应该用的用的MM_TEXT模式,后来为了能scroll用了Scrollview类不知道这个默认映射会不会改变了,但在初始化的时候这样写了:
CSketcherView::CSketcherView()
: m_FirstPoint(0,0)
, m_SecondPoint(0,0)
, m_pTempElement(NULL)
, m_pSelected(NULL)
, m_MoveMode(FALSE)
, m_CursorPos(CPoint(0,0))
, m_FirstPos(CPoint(0,0))
,m_Scale(1)
{
SetScrollSizes(MM_TEXT, CSize(0,0)); // Set arbitrary scrollers
}
然后所有映射模式变换的地方我在下面贴出:
CScrollView::OnPrepareDC(pDC, pInfo);
CSketcherDoc* pDoc = GetDocument();
pDC->SetMapMode(MM_ANISOTROPIC); // Set the map mode
CSize DocSize = pDoc->GetDocSize(); // Get the document size
// y extent must be negative because we want MM_LOENGLISH
DocSize.cy = -DocSize.cy; // Change sign of y
pDC->SetWindowExt(DocSize); // Now set the window extent
// Get the number of pixels per inch in x and y
int xLogPixels = pDC->GetDeviceCaps(LOGPIXELSX);
int yLogPixels = pDC->GetDeviceCaps(LOGPIXELSY);
// Calculate the viewport extent in x and y
long xExtent = static_cast<long>(DocSize.cx)*m_Scale*xLogPixels/100L;
long yExtent = static_cast<long>(DocSize.cy)*m_Scale*yLogPixels/100L;
pDC->SetViewportExt(static_cast<int>(xExtent),
static_cast<int>(-yExtent)); // Set viewport extent
}
void CSketcherView::ResetScrollSizes(void)
{
CClientDC aDC(this);
OnPrepareDC(&aDC); // Set up the device context
CSize DocSize = GetDocument()->GetDocSize(); // Get the document size
aDC.LPtoDP(&DocSize); // Get the size in pixels
SetScrollSizes(MM_TEXT, DocSize); // Set up the scrollbars
}
一直都没有出现MM_LOENGLISH,但是在OnPrepareDC类中注释却出现了// y extent must be negative because we want MM_LOENGLISH
也确实变了负号!
在记下来的几个有关映射模式的类中也出现了符号如:
void CSketcherView::OnPrint(CDC* pDC, CPrintInfo* pInfo)
{
// Output the document file name
pDC->SetTextAlign(TA_CENTER); // Center the following text
pDC->TextOut(pInfo->m_rectDraw.right/2, -20,
(static_cast<CPrintData*>(pInfo->m_lpUserData))->m_DocTitle);
pDC->SetTextAlign(TA_LEFT); // Left justify text
// Calculate the origin point for the current page
int xOrg = (static_cast<CPrintData*>(pInfo->m_lpUserData))->m_DocRefPoint.x +
600*((pInfo->m_nCurPage - 1)%
((static_cast<CPrintData*>(pInfo->m_lpUserData))->m_nWidths));
int yOrg = (static_cast<CPrintData*>(pInfo->m_lpUserData))->m_DocRefPoint.y -
900*((pInfo->m_nCurPage - 1)/
((static_cast<CPrintData*>(pInfo->m_lpUserData))->m_nWidths));
// Calculate offsets to center drawing area on page as positive values
int xOffset = (pInfo->m_rectDraw.right - 600)/2;
int yOffset = -(pInfo->m_rectDraw.bottom + 900)/2;
// Change window origin to correspond to current page & save old origin
CPoint OldOrg = pDC->SetWindowOrg(xOrg-xOffset, yOrg+yOffset);
// Define a clip rectangle the size of the printed area
pDC->IntersectClipRect(xOrg,yOrg,xOrg+600,yOrg-900);
OnDraw(pDC); // Draw the whole document
pDC->SelectClipRgn(NULL); // Remove the clip rectangle
pDC->SetWindowOrg(OldOrg); // Restore old window origin
}
总之,就是弄得我好晕,请问我没有显式的改写映射模式为:MM_LOENGLISH为什么最很多类都用了负号呢?这样程序又确实能正常运行,我按照MM_TEXT模式想法来改却出错,请大家帮帮忙