 |
操作系统: win 9x
编程工具: vc++ 6
我创建了一个基于对话框的程序,我设置对话框的背景为一个位图,我怎样才能将标签控件设置成透明的?我在主窗口中是这样写的.
HBRUSH CCheDlg::OnCtlColor(CDC* pDC, CWnd* pWnd, UINT nCtlColor)
{
HBRUSH hbr = CDialog::OnCtlColor(pDC, pWnd, nCtlColor);
if (nCtlColor == CTLCOLOR_STATIC)
{
pDC->SetBkMode(TRANSPARENT);
}
return hbr;
}
结果没有实现透明效果,我又试着继承CStatic类,在类中我处理了WM_ERASEBKGND消息,结果还是不行.我想知道还有没有其他的方法?(mory)
|
| |
|
 |
HiRong的意见:
从CStatic类中继承一个新类,映射WM_PAINT消息.其中bitmap为对话框的背景图片.
void CMyStatic::OnPaint()
{
CPaintDC dc(this); // device context for painting
CRect rect;
GetClientRect(&rect);
CString m_strStatic;
CWnd* wndStatic = dc.GetWindow();
wndStatic->GetWindowText(m_strStatic);
CBitmap bitmap;
bitmap.LoadBitmap(IDB_BACK);
CDC dcmem;
dcmem.CreateCompatibleDC(&dc);
CBitmap* poldbitmap = dcmem.SelectObject(&bitmap);
dc.BitBlt(0,0,rect.Width(),rect.Height(),&dcmem,0,0,SRCCOPY);
dcmem.SelectObject(poldbitmap);
dc.SetBkMode(TRANSPARENT);
dc.TextOut(2,2,m_strStatic);
// Do not call CStatic::OnPaint() for painting messages
}
CityWanderer的意见:
从CStatic类中继承一个新类,映射WM_PAINT消息:
Void CStaticTrans::OnPaint()
{
CPaintDC dc(this); // device context for painting
// TODO: Add your message handler code here
CString str;
GetWindowText(str);
dc.SetBkMode(TRANSPARENT);
dc.TextOut(0,0,str);
// Do not call CStatic::OnPaint() for painting messages
}
dragon的意见:
HBRUSH CCheDlg::OnCtlColor(CDC* pDC, CWnd* pWnd, UINT nCtlColor)
{
HBRUSH hbr = CDialog::OnCtlColor(pDC, pWnd, nCtlColor);
if (nCtlColor == CTLCOLOR_STATIC)
{
pDC->SetBkMode(TRANSPARENT);
}
return hbr;
}
这段代码差不多就可以了,当nCtlColor == CTLCOLOR_STATIC时,要设置为透明,还要返回一个空画刷即可;对于其他控件返回默认即可。
此问题由HiRong等回答。
附加关键字:编程, 源程序, programming, source code, C/C++, MFC, C++ Builder, Borland C++, Turbo C, C, BCB, 标准控件, screen, button, combo, checkbox, listbox。
|
| |
|
| |
|
| |
|
|