C++/MFC-多线程绘图

一、坐标系转换

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创建多线程

C++/MFC-多线程

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);
}



  • 0
    点赞
  • 7
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值