代码
sizeTotal.cx = 2100;
sizeTotal.cy = 2970;
sizePage.cx = 50;
sizePage.cy = 50;
sizeLine.cx = 10;
sizeLine.cy = 10;void CMyView::OnInitialUpdate()
{
// Create memory DC
HDC hDC = ::GetDC(NULL);
m_hMemDC = CreateCompatibleDC(hDC);
m_hMemBitmap = CreateCompatibleBitmap(hDC, sizeTotal.cx, sizeTotal.cy);
m_hOldMemBitmap = (HBITMAP)::SelectObject(m_hMemDC, m_hMemBitmap);
::ReleaseDC(NULL, hDC); CScrollView::OnInitialUpdate(); //设置滚动视图尺寸
SetScrollSizes(MM_TEXT, sizeTotal, sizePage, sizeLine);
}
void CMyView::OnDraw(CDC* pDC)
{
CSoftCubeDoc* pDoc = GetDocument();
ASSERT_VALID(pDoc);
if (!pDoc)
return;
RECT rect = {0,0,sizeTotal.cx,sizeTotal.cy}; RECT clientRect;
GetClientRect(&clientRect);
pDC->DPtoLP(&clientRect); // Clear background
FillRect(m_hMemDC, &rect, (HBRUSH)GetStockObject(GRAY_BRUSH));
FillRect(m_hMemDC, &clientRect, (HBRUSH)GetStockObject(WHITE_BRUSH)); //Draw Grid
if(m_grid != FALSE)
{
DrawGrid(m_hMemDC,&clientRect);
} //在某些位置画矩形
if (!m_bPrinting)
{
// Blit on screen DC
BitBlt(pDC->m_hDC, clientRect.left, clientRect.top, clientRect.right-clientRect.left, clientRect.bottom-clientRect.top, m_hMemDC, clientRect.left, clientRect.top, SRCCOPY);
}
}现在当我滚动滚动条时,原来未滚动部分RECT是没问题的即原点0,0开始的一个区域,剩下的区域就是没刷新
我想实现的是比如弄个A4大小的Doc,可打印到A4的纸上,
sizeTotal.cx = 2100;
sizeTotal.cy = 2970;
sizePage.cx = 50;
sizePage.cy = 50;
sizeLine.cx = 10;
sizeLine.cy = 10;void CMyView::OnInitialUpdate()
{
// Create memory DC
HDC hDC = ::GetDC(NULL);
m_hMemDC = CreateCompatibleDC(hDC);
m_hMemBitmap = CreateCompatibleBitmap(hDC, sizeTotal.cx, sizeTotal.cy);
m_hOldMemBitmap = (HBITMAP)::SelectObject(m_hMemDC, m_hMemBitmap);
::ReleaseDC(NULL, hDC); CScrollView::OnInitialUpdate(); //设置滚动视图尺寸
SetScrollSizes(MM_TEXT, sizeTotal, sizePage, sizeLine);
}
void CMyView::OnDraw(CDC* pDC)
{
CSoftCubeDoc* pDoc = GetDocument();
ASSERT_VALID(pDoc);
if (!pDoc)
return;
RECT rect = {0,0,sizeTotal.cx,sizeTotal.cy}; RECT clientRect;
GetClientRect(&clientRect);
pDC->DPtoLP(&clientRect); // Clear background
FillRect(m_hMemDC, &rect, (HBRUSH)GetStockObject(GRAY_BRUSH));
FillRect(m_hMemDC, &clientRect, (HBRUSH)GetStockObject(WHITE_BRUSH)); //Draw Grid
if(m_grid != FALSE)
{
DrawGrid(m_hMemDC,&clientRect);
} //在某些位置画矩形
if (!m_bPrinting)
{
// Blit on screen DC
BitBlt(pDC->m_hDC, clientRect.left, clientRect.top, clientRect.right-clientRect.left, clientRect.bottom-clientRect.top, m_hMemDC, clientRect.left, clientRect.top, SRCCOPY);
}
}现在当我滚动滚动条时,原来未滚动部分RECT是没问题的即原点0,0开始的一个区域,剩下的区域就是没刷新
我想实现的是比如弄个A4大小的Doc,可打印到A4的纸上,
我改成这样还是不行
RECT rect = {0,0,sizeTotal.cx,sizeTotal.cy}; // Clear background
FillRect(m_hMemDC, &clientRect, (HBRUSH)GetStockObject(GRAY_BRUSH));
FillRect(m_hMemDC, &rect, (HBRUSH)GetStockObject(WHITE_BRUSH)); //Draw Grid
if(m_grid != FALSE)
{
DrawGrid(m_hMemDC,&rect);
} //在某些位置画矩形
if (!m_bPrinting)
{
// Blit on screen DC
BitBlt(pDC->m_hDC, rect.left, rect.top, rect.right-rect.left, rect.bottom-rect.top, m_hMemDC, rect.left, rect.top, SRCCOPY);
}
偶用你的代码,把DrawGrid换成一句:::TextOut(m_hMemDC, 1, 1, L"Hello, world", 12); 是没有问题的。要点就是绝对坐标。
我背景是网格DrawGrid也是绘制网格的,但他只绘制了一部分
结贴