在DLG中的onCtrColor使用
pDC->SetBkMode(TRANSPARENT);
return (HBRUSH)GetStockObject(NULL_BRUSH);
来设置控件的背景透明色,有两个问题:
1.   在DLG的onpaint中画图片背景,但窗体上的控件背景却不是DLG的背景,而是DLG启动前桌面为背景。
2.   控件背景透明,但如果有对话框如Messagebox把控件盖住后,关掉对话框后,遮盖的部分仍会留在那。都是因为对windows的绘图机制不熟,求高手指导~

解决方案 »

  1.   

    只需要将你要透明的控件修改就可以   你直接将窗口背景透明了当然就是你说的情况if (pWnd->GetDlgCtrlID() == IDC_MYSTATIC)  //透明ID为IDC_MYSTATIC的控件
       {
          // Set the text color to red
          pDC->SetTextColor(RGB(255, 0, 0));      // Set the background mode for text to transparent 
          // so background will show thru.
          pDC->SetBkMode(TRANSPARENT);      // Return handle to our CBrush object
          return (HBRUSH)GetStockObject(NULL_BRUSH);
       }
      

  2.   

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

    // TODO: Change any attributes of the DC here
    if(nCtlColor != CTLCOLOR_DLG)
    {
    pDC->SetBkMode(TRANSPARENT); 
    return (HBRUSH)GetStockObject(NULL_BRUSH); 
    }
    // TODO: Return a different brush if the default is not desired
    return hbr;
    }
      

  3.   

    本帖最后由 xianglitian 于 2011-09-29 14:31:46 编辑