我现在有一段代码设置CEditView视打印预览的上下左右边距,但是设置CView视就不好使谁要是有设置CView视的代码给我一段最好,说说这是怎么回事也可以
void CMyView::SetPageMargin(CDC *pDC, CPrintInfo *pInfo, int l, int t, int r, int b)
// l, t, r, b分别表示左上右下边距, 单位为0.1mm
{
int nOldMode = pDC->GetMapMode();
pDC->SetMapMode(MM_LOMETRIC);
// 计算一个设备单位等于多少0.1mm
double scaleX = 254.0 / (double)GetDeviceCaps(
pDC->m_hAttribDC, LOGPIXELSX);
double scaleY = 254.0 / (double)GetDeviceCaps(
pDC->m_hAttribDC, LOGPIXELSY);
int x = GetDeviceCaps(pDC->m_hAttribDC,
PHYSICALOFFSETX);
int y = GetDeviceCaps(pDC->m_hAttribDC,
PHYSICALOFFSETY);
int w = GetDeviceCaps(pDC->m_hAttribDC,
PHYSICALWIDTH);
int h = GetDeviceCaps(pDC->m_hAttribDC,
PHYSICALHEIGHT);
int nPageWidth = (int)((double)w*scaleX + 0.5);
// 纸宽,单位0.1mm
int nPageHeight = (int)((double)h*scaleY + 0.5);
// 纸高,单位0.1mm
m_nPhyLeft = (int)((double)x*scaleX + 0.5);
// 物理左边距,单位0.1mm
m_nPhyTop = (int)((double)y*scaleY + 0.5);
// 物理上边距,单位0.1mm
pDC->DPtoLP(&pInfo->m_rectDraw);
CRect rcTemp = pInfo->m_rectDraw;
rcTemp.NormalizeRect();
m_nPhyRight = nPageWidth - rcTemp.Width() -
m_nPhyLeft; // 物理右边距,单位0.1mm
m_nPhyBottom = nPageHeight - rcTemp.Height() -
m_nPhyTop; // 物理下边距,单位0.1mm
// 若边距小于物理边距,则调整它们
if (l < m_nPhyLeft) l = m_nPhyLeft;
if (t < m_nPhyTop) t = m_nPhyTop;
if (r < m_nPhyRight) r = m_nPhyRight;
if (b < m_nPhyBottom) b = m_nPhyBottom;
// 计算并调整pInfo->m_rectDraw的大小
pInfo->m_rectDraw.left = l - m_nPhyLeft;
pInfo->m_rectDraw.top = - t + m_nPhyTop;
pInfo->m_rectDraw.right -= r - m_nPhyRight;
pInfo->m_rectDraw.bottom += b - m_nPhyBottom;
pDC->LPtoDP(&pInfo->m_rectDraw);
pDC->SetMapMode(nOldMode);
// 恢复原来的映射模式
}
void CMyView::SetPageMargin(CDC *pDC, CPrintInfo *pInfo, int l, int t, int r, int b)
// l, t, r, b分别表示左上右下边距, 单位为0.1mm
{
int nOldMode = pDC->GetMapMode();
pDC->SetMapMode(MM_LOMETRIC);
// 计算一个设备单位等于多少0.1mm
double scaleX = 254.0 / (double)GetDeviceCaps(
pDC->m_hAttribDC, LOGPIXELSX);
double scaleY = 254.0 / (double)GetDeviceCaps(
pDC->m_hAttribDC, LOGPIXELSY);
int x = GetDeviceCaps(pDC->m_hAttribDC,
PHYSICALOFFSETX);
int y = GetDeviceCaps(pDC->m_hAttribDC,
PHYSICALOFFSETY);
int w = GetDeviceCaps(pDC->m_hAttribDC,
PHYSICALWIDTH);
int h = GetDeviceCaps(pDC->m_hAttribDC,
PHYSICALHEIGHT);
int nPageWidth = (int)((double)w*scaleX + 0.5);
// 纸宽,单位0.1mm
int nPageHeight = (int)((double)h*scaleY + 0.5);
// 纸高,单位0.1mm
m_nPhyLeft = (int)((double)x*scaleX + 0.5);
// 物理左边距,单位0.1mm
m_nPhyTop = (int)((double)y*scaleY + 0.5);
// 物理上边距,单位0.1mm
pDC->DPtoLP(&pInfo->m_rectDraw);
CRect rcTemp = pInfo->m_rectDraw;
rcTemp.NormalizeRect();
m_nPhyRight = nPageWidth - rcTemp.Width() -
m_nPhyLeft; // 物理右边距,单位0.1mm
m_nPhyBottom = nPageHeight - rcTemp.Height() -
m_nPhyTop; // 物理下边距,单位0.1mm
// 若边距小于物理边距,则调整它们
if (l < m_nPhyLeft) l = m_nPhyLeft;
if (t < m_nPhyTop) t = m_nPhyTop;
if (r < m_nPhyRight) r = m_nPhyRight;
if (b < m_nPhyBottom) b = m_nPhyBottom;
// 计算并调整pInfo->m_rectDraw的大小
pInfo->m_rectDraw.left = l - m_nPhyLeft;
pInfo->m_rectDraw.top = - t + m_nPhyTop;
pInfo->m_rectDraw.right -= r - m_nPhyRight;
pInfo->m_rectDraw.bottom += b - m_nPhyBottom;
pDC->LPtoDP(&pInfo->m_rectDraw);
pDC->SetMapMode(nOldMode);
// 恢复原来的映射模式
}
可以在显示图像或其他内容的OnDraw()函数或OnPaint()内修改目的设备
的具体左上角、右上角坐标可能可以。
pDC->LPtoDP(&pInfo->m_rectDraw);//用在这里试试
pDC->SetMapMode(nOldMode);
// 恢复原来的映射模式
}