A problem of using CScrollView [modified]
-
Hi, All! I am developing an application to show the Text file. Now I derive a class from CScrollView. But I find that the view will flicker at the time I scroll the window when the text is too long to show in one page. So I declare a variable of CBitmap as a member of ScrollView class. Then in the member function of OnUpdate(), I declare a variable of CDC to create a compatibleDC and select the CBitmap into it. After that, I try to draw the view, save the view into CBitmap and Bitblt it into the Device Context of the window in the member funcation OnPaint(). Code:
class CEditorView : public CScrollView
{
......
private:
CBitmap m_bmpMem;//cache
......
}
void CEditorView::OnUpdate(CView* /*pSender*/, LPARAM /*lHint*/, CObject* /*pHint*/)
{
CSize sizeTotal;
//Calculate the size of View
GetViewSize(sizeTotal);
SetScrollSizes(MM_TEXT, sizeTotal);CDC \*pDC,memDC; CBitmap \*pOldBmp; pDC = GetDC(); ASSERT(pDC != NULL); memDC.CreateCompatibleDC(pDC); memDC.SetMapMode(m\_nMapMode); m\_bmpMem.CreateCompatibleBitmap(pDC,sizeTotal.cx,sizeTotal.cy); pOldBmp = memDC.SelectObject(&m\_bmpMem); OnDraw(&memDC); memDC.SelectObject(pOldBmp); ReleaseDC(pDC); InvalidateRect(NULL); UpdateWindow();
}
void CEditorView::OnDraw(CDC* pDC)
{
CEditorDoc* pDoc = GetDocument();
ASSERT(pDoc != NULL);
/*
Draw the content in View through pDC.
*/
}
void CEditorView::OnPaint()
{
CPaintDC dc(this); // device context for painting
CDC MemDC;
CBitmap *pOldBitmap;
CSize size;OnPrepareDC(&dc); size = GetTotalSize(); // Need a memory DC MemDC.CreateCompatibleDC(&dc); //Set MapMode MemDC.SetMapMode(m\_nMapMode); // Select in the bitmap pOldBitmap = MemDC.SelectObject(&m\_bmpMem); // Blt it dc.BitBlt( 0, -size.cy, size.cx, size.cy, &MemDC, 0, -size.cy, SRCCOPY ); // Clean up MemDC.SelectObject(pOldBitmap); CScrollView::OnPaint();
}
Question: 1. After I do as above, no text can be shown. I find that it will be shown only when I make the Message Declaration of OnPaint as comment. I don't know how to resolve it. I hope some one could be kind to tell me how to do. Thks! 2. What on earth the relation between OnPaint() and OnDraw()? Why the content can't be seen when I add the function OnPaint()? Pls help me! Thks a lot!! whiteclouds
There is some white cloud floating on the blue sky. That's the landscape I like.
modified on Monday, March 8, 2010 4:45
-
Hi, All! I am developing an application to show the Text file. Now I derive a class from CScrollView. But I find that the view will flicker at the time I scroll the window when the text is too long to show in one page. So I declare a variable of CBitmap as a member of ScrollView class. Then in the member function of OnUpdate(), I declare a variable of CDC to create a compatibleDC and select the CBitmap into it. After that, I try to draw the view, save the view into CBitmap and Bitblt it into the Device Context of the window in the member funcation OnPaint(). Code:
class CEditorView : public CScrollView
{
......
private:
CBitmap m_bmpMem;//cache
......
}
void CEditorView::OnUpdate(CView* /*pSender*/, LPARAM /*lHint*/, CObject* /*pHint*/)
{
CSize sizeTotal;
//Calculate the size of View
GetViewSize(sizeTotal);
SetScrollSizes(MM_TEXT, sizeTotal);CDC \*pDC,memDC; CBitmap \*pOldBmp; pDC = GetDC(); ASSERT(pDC != NULL); memDC.CreateCompatibleDC(pDC); memDC.SetMapMode(m\_nMapMode); m\_bmpMem.CreateCompatibleBitmap(pDC,sizeTotal.cx,sizeTotal.cy); pOldBmp = memDC.SelectObject(&m\_bmpMem); OnDraw(&memDC); memDC.SelectObject(pOldBmp); ReleaseDC(pDC); InvalidateRect(NULL); UpdateWindow();
}
void CEditorView::OnDraw(CDC* pDC)
{
CEditorDoc* pDoc = GetDocument();
ASSERT(pDoc != NULL);
/*
Draw the content in View through pDC.
*/
}
void CEditorView::OnPaint()
{
CPaintDC dc(this); // device context for painting
CDC MemDC;
CBitmap *pOldBitmap;
CSize size;OnPrepareDC(&dc); size = GetTotalSize(); // Need a memory DC MemDC.CreateCompatibleDC(&dc); //Set MapMode MemDC.SetMapMode(m\_nMapMode); // Select in the bitmap pOldBitmap = MemDC.SelectObject(&m\_bmpMem); // Blt it dc.BitBlt( 0, -size.cy, size.cx, size.cy, &MemDC, 0, -size.cy, SRCCOPY ); // Clean up MemDC.SelectObject(pOldBitmap); CScrollView::OnPaint();
}
Question: 1. After I do as above, no text can be shown. I find that it will be shown only when I make the Message Declaration of OnPaint as comment. I don't know how to resolve it. I hope some one could be kind to tell me how to do. Thks! 2. What on earth the relation between OnPaint() and OnDraw()? Why the content can't be seen when I add the function OnPaint()? Pls help me! Thks a lot!! whiteclouds
There is some white cloud floating on the blue sky. That's the landscape I like.
modified on Monday, March 8, 2010 4:45
-
Hi, All! I am developing an application to show the Text file. Now I derive a class from CScrollView. But I find that the view will flicker at the time I scroll the window when the text is too long to show in one page. So I declare a variable of CBitmap as a member of ScrollView class. Then in the member function of OnUpdate(), I declare a variable of CDC to create a compatibleDC and select the CBitmap into it. After that, I try to draw the view, save the view into CBitmap and Bitblt it into the Device Context of the window in the member funcation OnPaint(). Code:
class CEditorView : public CScrollView
{
......
private:
CBitmap m_bmpMem;//cache
......
}
void CEditorView::OnUpdate(CView* /*pSender*/, LPARAM /*lHint*/, CObject* /*pHint*/)
{
CSize sizeTotal;
//Calculate the size of View
GetViewSize(sizeTotal);
SetScrollSizes(MM_TEXT, sizeTotal);CDC \*pDC,memDC; CBitmap \*pOldBmp; pDC = GetDC(); ASSERT(pDC != NULL); memDC.CreateCompatibleDC(pDC); memDC.SetMapMode(m\_nMapMode); m\_bmpMem.CreateCompatibleBitmap(pDC,sizeTotal.cx,sizeTotal.cy); pOldBmp = memDC.SelectObject(&m\_bmpMem); OnDraw(&memDC); memDC.SelectObject(pOldBmp); ReleaseDC(pDC); InvalidateRect(NULL); UpdateWindow();
}
void CEditorView::OnDraw(CDC* pDC)
{
CEditorDoc* pDoc = GetDocument();
ASSERT(pDoc != NULL);
/*
Draw the content in View through pDC.
*/
}
void CEditorView::OnPaint()
{
CPaintDC dc(this); // device context for painting
CDC MemDC;
CBitmap *pOldBitmap;
CSize size;OnPrepareDC(&dc); size = GetTotalSize(); // Need a memory DC MemDC.CreateCompatibleDC(&dc); //Set MapMode MemDC.SetMapMode(m\_nMapMode); // Select in the bitmap pOldBitmap = MemDC.SelectObject(&m\_bmpMem); // Blt it dc.BitBlt( 0, -size.cy, size.cx, size.cy, &MemDC, 0, -size.cy, SRCCOPY ); // Clean up MemDC.SelectObject(pOldBitmap); CScrollView::OnPaint();
}
Question: 1. After I do as above, no text can be shown. I find that it will be shown only when I make the Message Declaration of OnPaint as comment. I don't know how to resolve it. I hope some one could be kind to tell me how to do. Thks! 2. What on earth the relation between OnPaint() and OnDraw()? Why the content can't be seen when I add the function OnPaint()? Pls help me! Thks a lot!! whiteclouds
There is some white cloud floating on the blue sky. That's the landscape I like.
modified on Monday, March 8, 2010 4:45
-
whiteclouds wrote:
What on earth the relation between OnPaint() and OnDraw()? Why the content can't be seen when I add the function OnPaint()?
Thank Rage! The message u provide is very useful. And I had make it clear. By the way, I had resolved this problem. This problem was caused by the wrong parameters when calling dc.BitBlt(...) in the function OnPaint(). :)
There is some white cloud floating on the blue sky. That's the landscape I like.