在VC2005中创建一个对话框项目,增加一个Radio按钮,然后在设置了OnCtlColor对话框背景图 如下:
CTestBrushDlgDlg::CTestBrushDlgDlg(CWnd* pParent /*=NULL*/)
: CDialog(CTestBrushDlgDlg::IDD, pParent)
{
m_hIcon = AfxGetApp()->LoadIcon(IDR_MAINFRAME);
m_nullBrush.CreateStockObject(NULL_BRUSH);
CBitmap bitmap;
bitmap.LoadBitmap(IDB_BACKUP) ;
m_brush.CreatePatternBrush(&bitmap);
}
HBRUSH CTestBrushDlgDlg::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_STATIC )
{
pDC->SetBkMode(TRANSPARENT);
return m_nullBrush;
}
return (HBRUSH)(m_brush.m_hObject);
}
1. 当设置工程的“Character Set"为"Use Unicode Character Set", 这个radio的背景是整个图片,而不是透明.
2. 当设置工程的“Character Set"为"Use Multi-Byte Character Set", 显示正常.
CTestBrushDlgDlg::CTestBrushDlgDlg(CWnd* pParent /*=NULL*/)
: CDialog(CTestBrushDlgDlg::IDD, pParent)
{
m_hIcon = AfxGetApp()->LoadIcon(IDR_MAINFRAME);
m_nullBrush.CreateStockObject(NULL_BRUSH);
CBitmap bitmap;
bitmap.LoadBitmap(IDB_BACKUP) ;
m_brush.CreatePatternBrush(&bitmap);
}
HBRUSH CTestBrushDlgDlg::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_STATIC )
{
pDC->SetBkMode(TRANSPARENT);
return m_nullBrush;
}
return (HBRUSH)(m_brush.m_hObject);
}
1. 当设置工程的“Character Set"为"Use Unicode Character Set", 这个radio的背景是整个图片,而不是透明.
2. 当设置工程的“Character Set"为"Use Multi-Byte Character Set", 显示正常.