请教如何设置dialog透明,但是在onpaint里面画的图不透明?现在只会设置dialog透明,但是画的图也一起透明了。

解决方案 »

  1.   

    http://download.csdn.net/detail/zhoujielunzhimi/5538917
      

  2.   

    图片要想透明话,只能用GDI+ 来实现。。Alpha值来改变
      

  3.   

    “在onpaint里面画的图不透明”
    SetWindowRgn , rgn 只包含 onpaint 的图。
      

  4.   


    我是想要画的图不够明。但是dialog透明。不是想画的图也透明
      

  5.   

    就是“在onpaint里面画的图不透明”
    SetWindowRgn , rgn 只包含 onpaint 的图。
    如 onpaint 中 画一个 矩形, 那么 rgn 就是 这个矩形,
    用 SetWindowRgn 后 就这个 矩形可见了 ,其他都 看不到 了 (透明了·)
      

  6.   

    给一个例子:void CTransDlgDlg::RgnSubtractCtrls(CRgn &rgn,int offX,int offY)
    {
    CWnd *pWnd=0;
    int ID[]={IDOK,IDC_BUTTON1,IDCANCEL};
    for(int jj=0;jj<sizeof(ID)/sizeof(int);jj++)
    {
    pWnd=GetDlgItem(ID[jj]);
    CRect rc;
    pWnd->GetWindowRect(&rc);
    ScreenToClient(&rc);
    rc.OffsetRect(offX,offY);
    CRgn ctlRgn;
    ctlRgn.CreateRectRgnIndirect(&rc);
    rgn.CombineRgn(&rgn,&ctlRgn,RGN_XOR);
    ctlRgn.DeleteObject();
    }
    } void CTransDlgDlg::OnButton1() 
    {
    // TODO: Add your control notification handler code here
    static BOOL sw=FALSE;
    if(!sw)
    {
    sw=TRUE;
    CRect rcWin;
    GetWindowRect(&rcWin);
    CRect rcClt;
    GetClientRect(&rcClt);
    ClientToScreen(&rcClt);
    //
    rcClt.OffsetRect(-rcWin.left,-rcWin.top);
    int offX=rcClt.left;
    int offY=rcClt.top;
    rcWin.OffsetRect(-rcWin.left,-rcWin.top);
    //
    CRgn tmp;
    tmp.CreateRectRgnIndirect(&rcClt);
    //
    RgnSubtractCtrls(tmp,offX,offY);
    //
    CRgn rgn;  
    rgn.CreateRectRgnIndirect(&rcWin);

    rgn.CombineRgn(&rgn, &tmp, RGN_DIFF);
    SetWindowRgn(rgn,TRUE);
    tmp.DeleteObject();
    rgn.DeleteObject();
    m_Trans.SetWindowText("不透明"); }
    else
    {
    sw=FALSE;
    SetWindowRgn(0,TRUE);
    m_Trans.SetWindowText("透明");
    }
    }BOOL CTransDlgDlg::OnEraseBkgnd(CDC* pDC) 
    {
    // TODO: Add your message handler code here and/or call default
    CRect rc;
    GetClientRect(&rc);
    pDC->FillSolidRect(&rc,RGB(255,200,200));
    return TRUE;
    //return CDialog::OnEraseBkgnd(pDC);
    }
    使用: 建个 dlg 工程 ,加一个 按钮 IDC_BUTTON1
    把 上面代码OnButton1()放 按钮响应中。头中 声明一个
    void CTransDlgDlg::RgnSubtractCtrls;
    编译运行, 点 这个按钮。可以 看到 对话框 的 客户区 除了这 3个 按钮 ,其他 都透明了