15,978
社区成员
发帖
与我相关
我的任务
分享
void CTestUIDlg::OnPaint()
{
DlgParamInit();
//绘制按钮的文字;
}
BOOL CTestUIDlg::DlgParamInit()
{
GetClientRect(ClientRect);//得到客户区坐标
m_Step = (ClientRect.bottom-ClientRect.top)/10.0;
CRect ButtonRect(0,0,INT(2*m_Step),int(m_Step));
TitleRect.top = int(0.25*ButtonRect.Height());
TitleRect.bottom = int(1.75*ButtonRect.Height());
TitleRect.left = ButtonRect.Height();
TitleRect.right = ClientRect.right - ButtonRect.Height();
TextRect.top = 2*ButtonRect.Height();
TextRect.bottom = 9*ButtonRect.Height();
TextRect.left = int(1.125*ButtonRect.Width());
TextRect.right = int(ClientRect.Width()-1.125*ButtonRect.Width());
//改变按钮位置
GetDlgItem(IDC_BUTTON1)->MoveWindow(ClientRect.left,2*ButtonRect.Height(),ButtonRect.Width(),ButtonRect.Height(),TRUE);
GetDlgItem(IDC_BUTTON3)->MoveWindow(ClientRect.left,4*ButtonRect.Height(),ButtonRect.Width(),ButtonRect.Height(),TRUE);
GetDlgItem(IDC_BUTTON5)->MoveWindow(ClientRect.left,6*ButtonRect.Height(),ButtonRect.Width(),ButtonRect.Height(),TRUE);
GetDlgItem(IDC_BUTTON7)->MoveWindow(ClientRect.left,8*ButtonRect.Height(),ButtonRect.Width(),ButtonRect.Height(),TRUE);
GetDlgItem(IDC_BUTTON2)->MoveWindow(ClientRect.right-ButtonRect.Width(),2*ButtonRect.Height(),ButtonRect.Width(),ButtonRect.Height(),TRUE);
GetDlgItem(IDC_BUTTON4)->MoveWindow(ClientRect.right-ButtonRect.Width(),4*ButtonRect.Height(),ButtonRect.Width(),ButtonRect.Height(),TRUE);
GetDlgItem(IDC_BUTTON6)->MoveWindow(ClientRect.right-ButtonRect.Width(),6*ButtonRect.Height(),ButtonRect.Width(),ButtonRect.Height(),TRUE);
GetDlgItem(IDC_BUTTON8)->MoveWindow(ClientRect.right-ButtonRect.Width(),8*ButtonRect.Height(),ButtonRect.Width(),ButtonRect.Height(),TRUE);
//设置对话框中按钮字体大小
ButtonFont.CreateFont(ClientRect.right/40,0, 0, 0, 700, false, false, 0, 1,
OUT_DEFAULT_PRECIS, CLIP_DEFAULT_PRECIS,DEFAULT_QUALITY,
DEFAULT_PITCH | FF_SWISS | FF_SCRIPT | FF_ROMAN | FF_MODERN, "宋体");
SendMessageToDescendants(WM_SETFONT,(WPARAM)HFONT(ButtonFont),MAKELPARAM(TRUE,0));
// 设置标题区域形状及颜色
CClientDC *pDC = new CClientDC(this);
CBrush TitleBrush;
TitleBrush.CreateSolidBrush(RGB(0,128,255));
pDC->SelectObject(&TitleBrush);
pDC->RoundRect(TitleRect, CPoint(40,40));
pDC->RoundRect(TextRect, CPoint(30,30));
//更改标题TextOut输出字体
TitleFont.CreatePointFont(ClientRect.Height(),"华文行楷",NULL);
pDC->SelectObject(&TitleFont);
pDC->SetBkMode(TRANSPARENT);//让输出字体没有空白背景
pDC->SetTextColor(RGB(0,0,255));
return 0;
}
//按下按钮之后,绘制标题
BOOL CTestUIDlg::SetTitleTxt(CString Title)
{
CClientDC *pDC = new CClientDC(this);
CString x;
x.Format(Title);
//更改标题TextOut输出字体
TitleFont.CreatePointFont(ClientRect.Height(),"华文行楷",NULL);
pDC->SelectObject(&TitleFont);
pDC->SetBkMode(TRANSPARENT);//让输出字体没有空白背景
pDC->SetTextColor(RGB(0,0,255));
pDC->DrawText(x,TitleRect,DT_CENTER);
return 0;
}