对话框有一张背景图片,如何让对话框上的控件不挡着背景图片?控件能不能设置为透明的?

解决方案 »

  1.   

    处理控件的ON_WM_CTLCOLOR,设置透明就行。
      

  2.   

    肯定能啊
    你重载所有子控件的OnPaint,用你对话框的DC
      

  3.   

    肯定能啊
    你重载所有子控件的OnPaint,用你对话框的DC,自己计算好区域,拷贝过去就好了litbox/listctrl/treectrl我的都实现透明了
      

  4.   

    BOOL CDlgSysSetup::OnEraseBkgnd(CDC* pDC)
    {
    CRect rect;
    GetClientRect(&rect);
    CBitmap m_pBmp;
    BITMAP bm;
    CDC dcMem;
    m_pBmp.LoadBitmap(IDB_SKY);
    m_pBmp.GetBitmap(&bm);//得到位图尺寸
    dcMem.CreateCompatibleDC(pDC);
    CBitmap* pOldBitmap = dcMem.SelectObject(&m_pBmp);pDC->SetStretchBltMode(COLORONCOLOR);//这个模式不设置的话会导致图片严重失真
    pDC->StretchBlt(0,0,rect.Width() ,rect.Height(),
       &dcMem,0,0,bm.bmWidth,bm.bmHeight,SRCCOPY);dcMem.SelectObject(pOldBitmap);
    return TRUE;//return CBkDialog::OnEraseBkgnd(pDC);
    }HBRUSH CDlgSysSetup::OnCtlColor(CDC* pDC, CWnd* pWnd, UINT nCtlColor)
    {
    switch( nCtlColor)
    {
    case CTLCOLOR_EDIT:
       return (HBRUSH)GetStockObject(WHITE_BRUSH); //设置背景色
    case CTLCOLOR_DLG:
    case CTLCOLOR_BTN:
    case CTLCOLOR_STATIC:
       pDC->SetBkMode(TRANSPARENT); 
       return (HBRUSH)GetStockObject(HOLLOW_BRUSH); //设置背景色
    default:
       return (HBRUSH)GetStockObject(HOLLOW_BRUSH); //设置背景色}}
    这个例子我试了,不能通过
      

  5.   


    HBRUSH CxxxDlg::OnCtlColor(CDC* pDC, CWnd* pWnd, UINT nCtlColor) 
    {
    HBRUSH hbr = CDialog::OnCtlColor(pDC, pWnd, nCtlColor);

    // TODO: Change any attributes of the DC here
    int id = pWnd->GetDlgCtrlID();   
    if(nCtlColor== CTLCOLOR_STATIC )     
    {   
    switch(id) 

    case IDC_STATIC:
    pDC->SetBkMode(TRANSPARENT); 
    hbr=(HBRUSH)GetStockObject(HOLLOW_BRUSH); 
    default: 
    break; 

    }

    // TODO: Return a different brush if the default is not desired
    return hbr;
    }
      

  6.   

    我试了下,只能改变static和edit控件,不能改BTN和LIST CONTROL,要改这些还要别的办法吗?
      

  7.   

    ListBox的话改为if(nCtlColor== CTLCOLOR_LISTBOX )   
      

  8.   

    LIST CONTROL,不好意思看错了
      

  9.   

    OnCtlColor这个对纯色肯定有效  但对复杂的背景色 估计你还得写写你父对话框画背景的代码 没试验过
    如果控件类型少 就都重载了 这个肯定没问题 但显然挺麻烦的。