一、坐标系转换
GetWindowRect
1、取得屏幕坐标2、转换成相对坐标
3、绘图
4、设计函数DrawRect(UINT id,UINT* width),根据线程时间片和EDIT控件ID位置 绘制矩形
void CDialog_Thread_Priority_test::DrawRect(UINT edt_ID, UINT* pWidth)
{
CRect r1,r2,r3;
GetWindowRect(&r1);//主窗口矩形坐标
GetDlgItem(edt_ID)->GetWindowRect(&r2);//控件屏幕坐标
//转换坐标
int x,y;
x=r2.left-r1.left;
y=r2.top-r1.top;
int width,height;
height=r2.bottom-r2.top;//取得控件高度
width=r2.right-r2.left;//取得控件宽度
r3.left=x+width+2;//x1
r3.top=y; //y1
r3.right=r3.left+*pWidth;//x2
r3.bottom=r3.top+height;//y2
CDC *pdc=GetWindowDC();
pdc->Rectangle(r3);
ReleaseDC(pdc);
}
二、多线程绘图
2.1创建多线程
2.2重写WindowProc函数
LRESULT CDialog_Thread_Priority_test::WindowProc(UINT message, WPARAM wParam, LPARAM lParam)
{
// TODO: 在此添加专用代码和/或调用基类
if (message==WM_USER_MSG)
{
DrawRect(IDC_EDIT1,&m_edt_time1);
DrawRect(IDC_EDIT3,&m_edt_time2);
DrawRect(IDC_EDIT4,&m_edt_time3);
DrawRect(IDC_EDIT5,&m_edt_time4);
DrawRect(IDC_EDIT6,&m_edt_time5);
DrawRect(IDC_EDIT7,&m_edt_time6);
DrawRect(IDC_EDIT8,&m_edt_time7);
UpdateData(false);
}
return CDialog::WindowProc(message, wParam, lParam);
}