各位高手请帮忙,我new 了一个新工程项目,然后添加dialog资源 ID=ID_DIALOG_BAR,我在MainFrm.h定义一个CDialogBar的变量,m_ControlBar,然后在MainFrm.cpp create,然后,这个dialog就会显示在主界面中,我想问的是,如何更改dialog(ID_DIALOG_BAR)的背景色和如何把它的背景设为一个图片,请帮忙。谢谢。

解决方案 »

  1.   

    http://www.codeguru.com/dialog/background_garcia.shtml
    http://www.codeguru.com/dialog/IrrBmpDlg.html
    http://www.codeguru.com/dialog/dlg_back_text_color.shtml
      

  2.   

    怎么不行呀?我按照他的做法,我是位dialog建立了一类, CControlButton,然后我在它的这个函数中写的:
    BOOL CControlButton::OnInitDialog() 
    {
    /* CButton *MyButton;
    HBITMAP Bitmap;
    Bitmap=::LoadBitmap(AfxGetResourceHandle(),MAKEINTRESOURCE(IDB_BITMAP2));
    MyButton=(CButton*)GetDlgItem(IDC_BUTTON1);
    MyButton->SetBitmap(Bitmap);*/ CDialog::OnInitDialog();
     m_brushBackground.CreateSolidBrush(RGB(255, 255, 255));  // TODO: Add extra initialization here

    return TRUE;  // return TRUE unless you set the focus to a control
                  // EXCEPTION: OCX Property Pages should return FALSE
    }
    另一个函数:HBRUSH CControlButton::OnCtlColor(CDC* pDC, CWnd* pWnd, UINT nCtlColor) 
    {
    //HBRUSH hbr = CDialog::OnCtlColor(pDC, pWnd, nCtlColor);
    // TODO: Change any attributes of the DC here
    // TODO: Return a different brush if the default is not desired
    return m_brushBackground;
    }
    结果没什么反映,为什么?
      

  3.   

    try this example below, maybe useful ...http://www.codeproject.com/dialog/winampwnd.aspGood luck!
      

  4.   

    BOOL CLogIn::OnEraseBkgnd(CDC* pDC) 
    {
    CRect rect;
    GetWindowRect( &rect );
    CDC *pMem;
    CBitmap *m_OldBitmap;
    CBitmap mShowbit; pMem = new CDC(); if( str_Back.IsEmpty() )
    mShowbit.LoadBitmap( IDB_BACK );
    else{
    HBITMAP   bitmap;
    mShowbit.Detach();
    bitmap = (HBITMAP)::LoadImage( NULL , str_Back , IMAGE_BITMAP , 0 , 0 , LR_CREATEDIBSECTION|LR_LOADFROMFILE|LR_DEFAULTSIZE );
    mShowbit.Attach(bitmap);
    } pMem->CreateCompatibleDC( pDC );
    m_OldBitmap=pMem->SelectObject( &mShowbit );
    pDC->BitBlt( 0 , 0 , rect.Width() , rect.Height() , pMem , 0 , 0 , SRCCOPY );
    pMem->SelectObject( m_OldBitmap );    return true;
    }