我在对话框中用取得CDC的方式在OnPaint中绘制了背景位图,但是控件都不能显示了,如何能让控件到最上面一直显示不被位图覆盖呢?背景图是个动画要不停重画。
谢谢高手指点

解决方案 »

  1.   

    void CSuperSPlayerDlg::OnPaint() 
    {
    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();
    }}控件就不能正常显示了,有什么办法能让控件一直都在最上面显示?
      

  2.   


    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.