自绘对话框标题栏

 

void CDD2Dlg::OnNcPaint() 
{
	//使用默认的操作先刷新
	CDialog::OnNcPaint();

	//计算TitleBar的坐标区域
	CRect titleRect;
	GetWindowRect(&titleRect);
	DWORD DialogBaseUnits = GetDialogBaseUnits();
	WORD DialogBaseUnits_X = LOWORD(DialogBaseUnits)/4;
	WORD DialogBaseUnits_Y = HIWORD(DialogBaseUnits)/8;
	titleRect.top += GetSystemMetrics(SM_CYBORDER) * DialogBaseUnits_Y;
	titleRect.left += GetSystemMetrics(SM_CXBORDER) * DialogBaseUnits_X;
	titleRect.right -= GetSystemMetrics(SM_CXBORDER) * DialogBaseUnits_X;
	titleRect.bottom = titleRect.top + GetSystemMetrics(SM_CYCAPTION);

	//创建DC设备
	CDC pDC;
	pDC.CreateDC("DISPLAY", NULL, NULL,NULL);
	int saveDC = pDC.SaveDC(); //保存设备

	//使用自定义颜色填充
	CBrush brush(RGB(255,0,0));
	pDC.FillRect(&titleRect,&brush);

	//正中位置显示字符串
	pDC.SetBkMode(TRANSPARENT);
	pDC.SetTextColor(RGB(0,128,128));
	pDC.DrawText("ABCD",titleRect,DT_CENTER|DT_VCENTER|DT_SINGLELINE);

	pDC.RestoreDC(saveDC); //恢复设备
	pDC.DeleteDC(); //删除设备	
}


   

你可能感兴趣的:(null)