关于界面绘图的问题解决

目前正在做一个项目,窗口被分成若干个区域,不同的区域有不同的背景色,在OnPaint()中实现,代码如下:

m_brush1.CreateSolidBrush(RGB(195, 176, 146));
 m_brush2.CreateSolidBrush(RGB(29, 15, 14));
 m_brush3.CreateSolidBrush(RGB(29, 15, 4));
 m_brush4.CreateSolidBrush(RGB(118, 94, 82));
 m_brush5.CreateSolidBrush(RGB(255, 255, 82));

以上画刷在OnInitialDialg中创建

 

void CMyDlg::OnPaint()
{
 CPaintDC dc(this); // device context for painting
 // TODO: Add your message handler code here
 // Do not call CDialog::OnPaint() for painting messages
 CRect clientRect;
 GetClientRect(&clientRect);

 CRect temp;
 temp.left = clientRect.left;
 temp.top = clientRect.top;
 temp.right = clientRect.right / 3 *2;
 temp.bottom = clientRect.Height() / 14  * 2;
 dc.FillRect(&temp, &m_brush1);

 temp.top = temp.bottom;
 temp.bottom = temp.top + clientRect.Height() / 14  * 3;
 dc.FillRect(&temp, &m_brush2);

 temp.top = temp.bottom;
 temp.bottom = g_pstuInterIO->rcButton.top;
 dc.FillRect(&temp, &m_brush3);

 temp.left = temp.right;
 temp.top = clientRect.top;
 temp.right = clientRect.right;
 dc.FillRect(&temp, &m_brush4);


 CRect wndrect;
 if (m_handwheel_sliderctrl.m_hWnd)
 {
  m_handwheel_sliderctrl.GetWindowRect(&wndrect);
  ScreenToClient(&wndrect);
  temp.top = wndrect.bottom + GAP_V;
  temp.bottom = temp.top + 1;
  dc.FillRect(&temp, &m_brush5);

 }

 if (m_feedoverride_sliderctrl.m_hWnd)
 {
  m_feedoverride_sliderctrl.GetWindowRect(&wndrect);
  ScreenToClient(&wndrect);
  temp.top = wndrect.bottom + GAP_V;
  temp.bottom = temp.top + 1;
  dc.FillRect(&temp, &m_brush5);
 }

 if (m_static_fprog.m_hWnd)
 {
  m_static_fprog.GetWindowRect(&wndrect);
  ScreenToClient(&wndrect);
  temp.top = wndrect.bottom + GAP_V;
  temp.bottom = temp.top + 1;
  dc.FillRect(&temp, &m_brush5);
 }

 dc.FillSolidRect(g_pstuInterIO->rcButton, COLOR_BACKBUTTON);
}

但是当界面中的其他static_text控件需要更新文本内容时,采用如下方式

m_static.setwindowtext(_T("OK"));m_static.invalidate();

原先的内容不能被擦除,当采用Invalidate对整个窗口重新绘制时,窗口闪烁比较明显。

后来采用如下方式只对该控件进行重画,避免了窗口的闪烁:

CRect rectUpdate;

m_static.GetWindowRect(&rectUpdate);//获取该控件对应的屏幕坐标
ScreenToClient(&rectUpdate);//将屏幕坐标转换成窗口的客户坐标
RedrawWindow(&rectUpdate);//只标记该区域更行,避免整个客户区刷新。

 

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值