MFC Cbutton、Cstatic、Edit/控件修改字体及颜色

主要是重载WM_CTRCOLOR信号:


标题一:Cbutton、Cstatic、Edit字体及颜色修改


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

	// TODO:  Change any attributes of the DC here

	CFont * cFont=new CFont;
	cFont->CreateFont(16,0,0,0,FW_SEMIBOLD,FALSE,FALSE,0,
		ANSI_CHARSET,OUT_DEFAULT_PRECIS,
		CLIP_DEFAULT_PRECIS,DEFAULT_QUALITY,
		DEFAULT_PITCH&FF_SWISS,TEXT("Arial"));
	// 对特定的控件做修改

	switch(nCtlColor)
	{
	  case CTLCOLOR_EDIT: //对所有编辑框的设置
		{
			pDC->SetBkMode(TRANSPARENT);
			pDC->SetTextColor(RGB(200,255,0));
			//pWnd->SetFont(cFont);
			HBRUSH B = CreateSolidBrush(RGB(125,125,255));
			return (HBRUSH) B;
		}

	  case  CTLCOLOR_BTN:
		{
			
		}

	  case  CTLCOLOR_DLG:
		{
			
		}
	default:
		//break;
		return CDialog::OnCtlColor(pDC,pWnd, nCtlColor);
	}

	
	// TODO:  Return a different brush if the default is not desired
	return hbr;
}


标题二:控件字体及颜色修改


switch(pWnd->GetDlgCtrlID())
{
	case IDC_EDIT1:
		{
			pDC->SetBkMode(TRANSPARENT);
			pDC->SetTextColor(RGB(200,255,0));
			//pWnd->SetFont(cFont);
			HBRUSH B = CreateSolidBrush(RGB(125,125,255));
			return (HBRUSH) B;
		}
	default:
		break;
}


你可能感兴趣的:(VS/MFC)