重载WM_CTRLCOLOR消息 下面程序中的颜色你自己看着改吧 HBRUSH CDBDlg::OnCtlColor(CDC *pDC, CWnd *pWnd, UINT nCtlColor) { HBRUSH brush; switch(nCtlColor) { case CTLCOLOR_BTN: case CTLCOLOR_STATIC: { pDC->SetBkMode(TRANSPARENT); brush=(HBRUSH)::GetStockObject(NULL_BRUSH); break; } case CTLCOLOR_EDIT: { pDC->SetBkMode(TRANSPARENT); brush=(HBRUSH)::GetStockObject(LTGRAY_BRUSH); break; } case CTLCOLOR_LISTBOX: { pDC->SetBkMode(TRANSPARENT); brush=(HBRUSH)::GetStockObject(GRAY_BRUSH); break; } case CTLCOLOR_MSGBOX: { brush=(HBRUSH)::GetStockObject(LTGRAY_BRUSH); break; } case CTLCOLOR_SCROLLBAR: { brush=(HBRUSH)::GetStockObject(GRAY_BRUSH); break; } default: brush=CDialog::OnCtlColor(pDC, pWnd, nCtlColor); } return brush; }
HBRUSH CZilchDlg::OnCtlColor(CDC* pDC, CWnd* pWnd, UINT nCtlColor) { HBRUSH hbr = CDialog::OnCtlColor(pDC, pWnd, nCtlColor); if (pWnd->GetDlgCtrlID() == 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 hbr = m_brush; } return hbr; }
{
// TODO: Add your message handler code here and/or call default
BOOL b = CEdit::OnEraseBkgnd(pDC); CRect rc;
GetClientRect(&rc); pDC->FillSolidRect(&rc,RGB(255,255,255)); pDC->SetBkMode(TRANSPARENT);
HBITMAP hBitmap = (HBITMAP)LoadImage(NULL,_T("TMark.bmp"),IMAGE_BITMAP,0,0,LR_CREATEDIBSECTION|LR_DEFAULTSIZE|LR_LOADFROMFILE);
m_bitmap.Attach(hBitmap);
BITMAP bm;
m_bitmap.GetBitmap(&bm);
CDC dcImage;
if(!dcImage.CreateCompatibleDC(pDC))
return CEdit::OnEraseBkgnd(pDC); CBitmap* pOldBitmap = dcImage.SelectObject(&m_bitmap); pDC->BitBlt((rc.Width()-349)/2,(rc.Height()-296)/2,(rc.Width()+349)/2,(rc.Height()+296)/2,&dcImage,0,0,SRCCOPY);
dcImage.SelectObject(pOldBitmap);
DeleteObject(m_bitmap.Detach()); return b;
}
下面程序中的颜色你自己看着改吧
HBRUSH CDBDlg::OnCtlColor(CDC *pDC, CWnd *pWnd, UINT nCtlColor)
{
HBRUSH brush; switch(nCtlColor)
{
case CTLCOLOR_BTN:
case CTLCOLOR_STATIC:
{
pDC->SetBkMode(TRANSPARENT);
brush=(HBRUSH)::GetStockObject(NULL_BRUSH);
break;
}
case CTLCOLOR_EDIT:
{
pDC->SetBkMode(TRANSPARENT);
brush=(HBRUSH)::GetStockObject(LTGRAY_BRUSH);
break;
}
case CTLCOLOR_LISTBOX:
{
pDC->SetBkMode(TRANSPARENT);
brush=(HBRUSH)::GetStockObject(GRAY_BRUSH);
break;
}
case CTLCOLOR_MSGBOX:
{
brush=(HBRUSH)::GetStockObject(LTGRAY_BRUSH);
break;
}
case CTLCOLOR_SCROLLBAR:
{
brush=(HBRUSH)::GetStockObject(GRAY_BRUSH);
break;
}
default: brush=CDialog::OnCtlColor(pDC, pWnd, nCtlColor);
}
return brush;
}
{
HBRUSH hbr = CDialog::OnCtlColor(pDC, pWnd, nCtlColor); if (pWnd->GetDlgCtrlID() == 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
hbr = m_brush;
} return hbr;
}