CBitmap *pOldBmp=m_surfaceDC->SelectObject(&MPlayer);//将位图选进设备 } if (IsIconic()) { CPaintDC dc(this); // device context for painting SendMessage(WM_ICONERASEBKGND, (WPARAM) dc.GetSafeHdc(), 0); // Center icon in client rectangle int cxIcon = GetSystemMetrics(SM_CXICON); int cyIcon = GetSystemMetrics(SM_CYICON); CRect rect; GetClientRect(&rect); int x = (rect.Width() - cxIcon + 1) / 2; int y = (rect.Height() - cyIcon + 1) / 2; // Draw the icon dc.DrawIcon(x, y, m_hIcon); } else { CWnd* pWnd = AfxGetMainWnd( ); CDC* pControlDC = (CClientDC*)pWnd->GetDC(); pControlDC->BitBlt(0,0,300,106,m_surfaceDC,0,0,SRCCOPY); CDialog::OnPaint(); }}控件就不能正常显示了,有什么办法能让控件一直都在最上面显示?
将 CWnd* pWnd = AfxGetMainWnd( ); CDC* pControlDC = (CClientDC*)pWnd->GetDC(); pControlDC->BitBlt(0,0,300,106,m_surfaceDC,0,0,SRCCOPY);改为 CPaintDC dc(this); dc.BitBlt(100,100,1000,1000,m_surfaceDC,0,0,SRCCOPY); 原因: 摘自mfc程序设计二版 (chapter1) Your First MFC ApplicationIn MFC, you'll always draw to the screen with a CDC object of some type, but you must use a CPaintDC object only inside OnPaint handlers.
{
if(m_isFirstPaint)
{
m_isFirstPaint=false;
m_surfaceDC=new CDC;
CWnd* pWnd = AfxGetMainWnd( );
CDC* pControlDC = pWnd->GetDC();
m_surfaceDC->CreateCompatibleDC(pControlDC); CBitmap MPlayer;
if(!MPlayer.LoadBitmap(IDB_BGBMP)) //装载界面位图
return;
CBitmap *pOldBmp=m_surfaceDC->SelectObject(&MPlayer);//将位图选进设备
}
if (IsIconic())
{
CPaintDC dc(this); // device context for painting SendMessage(WM_ICONERASEBKGND, (WPARAM) dc.GetSafeHdc(), 0); // Center icon in client rectangle
int cxIcon = GetSystemMetrics(SM_CXICON);
int cyIcon = GetSystemMetrics(SM_CYICON);
CRect rect;
GetClientRect(&rect);
int x = (rect.Width() - cxIcon + 1) / 2;
int y = (rect.Height() - cyIcon + 1) / 2; // Draw the icon
dc.DrawIcon(x, y, m_hIcon);
}
else
{ CWnd* pWnd = AfxGetMainWnd( );
CDC* pControlDC = (CClientDC*)pWnd->GetDC(); pControlDC->BitBlt(0,0,300,106,m_surfaceDC,0,0,SRCCOPY); CDialog::OnPaint();
}}控件就不能正常显示了,有什么办法能让控件一直都在最上面显示?
CWnd* pWnd = AfxGetMainWnd( );
CDC* pControlDC = (CClientDC*)pWnd->GetDC(); pControlDC->BitBlt(0,0,300,106,m_surfaceDC,0,0,SRCCOPY);改为
CPaintDC dc(this);
dc.BitBlt(100,100,1000,1000,m_surfaceDC,0,0,SRCCOPY);
原因:
摘自mfc程序设计二版
(chapter1) Your First MFC ApplicationIn MFC, you'll always draw to the screen with a CDC object of some type, but you must use a CPaintDC object only inside OnPaint handlers.