About draw a picture in dialog box
-
I have a class that can draw picture in dialog box using the following code:
void CDialogbox::OnPaint() { CPaintDC dc(this); // device context for painting CRect m_rect; GetWindowRect(m_rect); //... m_myclass.Draw(dc,m_rect); // Draw the image to dialog box }
These codes works fine as I just anticipated. But when I want to use memory DC for caching, it did not work:void CDialogbox::OnPaint() { CPaintDC dc(this); // device context for painting CDC m_memdc; m_memdc.CreateCompatibleDC(&dc); //Create a memory DC CRect m_rect; GetWindowRect(m_rect); //... m_myclass.Draw(dc,m_memdc); // First draw to memory DC dc.BitBlt(m_rect.left,m_rect.right,m_rect.Width(),m_rect.Height(),&m_memdc,0,0,SRCCOPY); // Second copy from memory DC to Paint DC }
Does anyone can help me? :confused:Lisoft
-
I have a class that can draw picture in dialog box using the following code:
void CDialogbox::OnPaint() { CPaintDC dc(this); // device context for painting CRect m_rect; GetWindowRect(m_rect); //... m_myclass.Draw(dc,m_rect); // Draw the image to dialog box }
These codes works fine as I just anticipated. But when I want to use memory DC for caching, it did not work:void CDialogbox::OnPaint() { CPaintDC dc(this); // device context for painting CDC m_memdc; m_memdc.CreateCompatibleDC(&dc); //Create a memory DC CRect m_rect; GetWindowRect(m_rect); //... m_myclass.Draw(dc,m_memdc); // First draw to memory DC dc.BitBlt(m_rect.left,m_rect.right,m_rect.Width(),m_rect.Height(),&m_memdc,0,0,SRCCOPY); // Second copy from memory DC to Paint DC }
Does anyone can help me? :confused:Lisoft
m_myclass.Draw(dc,m_memdc); // First draw to memory DC??????????? Why parameter 2 is a DC ----------------- conglt
-
I have a class that can draw picture in dialog box using the following code:
void CDialogbox::OnPaint() { CPaintDC dc(this); // device context for painting CRect m_rect; GetWindowRect(m_rect); //... m_myclass.Draw(dc,m_rect); // Draw the image to dialog box }
These codes works fine as I just anticipated. But when I want to use memory DC for caching, it did not work:void CDialogbox::OnPaint() { CPaintDC dc(this); // device context for painting CDC m_memdc; m_memdc.CreateCompatibleDC(&dc); //Create a memory DC CRect m_rect; GetWindowRect(m_rect); //... m_myclass.Draw(dc,m_memdc); // First draw to memory DC dc.BitBlt(m_rect.left,m_rect.right,m_rect.Width(),m_rect.Height(),&m_memdc,0,0,SRCCOPY); // Second copy from memory DC to Paint DC }
Does anyone can help me? :confused:Lisoft
The problem is you did not selected any bitmap to the memdc. CreateCompatibleDC will create a dc with 1x1 pixel wide bitmap. So you have to create a bitmap also. See the example. CPaint dc( this ); CDC dcMem; dcMem.CreateCompatibleDC( &dc ); CBitmap bitmap; bitmap.CreateCompatibleBitmap( &dc, width, height ); CBitmap* pOldBitmap = dcMem.SelectObject( &bitmap ); // // Draw // dc.BitBlt( 0, 0, width, height, &dcMem, 0, 0, SRCCOPY ); dcMem.SelectObject( pOldBitmap ); GoodLuck! - NS -
-
The problem is you did not selected any bitmap to the memdc. CreateCompatibleDC will create a dc with 1x1 pixel wide bitmap. So you have to create a bitmap also. See the example. CPaint dc( this ); CDC dcMem; dcMem.CreateCompatibleDC( &dc ); CBitmap bitmap; bitmap.CreateCompatibleBitmap( &dc, width, height ); CBitmap* pOldBitmap = dcMem.SelectObject( &bitmap ); // // Draw // dc.BitBlt( 0, 0, width, height, &dcMem, 0, 0, SRCCOPY ); dcMem.SelectObject( pOldBitmap ); GoodLuck! - NS -