MFC编程(一)
实现通过定时器来回滚动Label
- 使用类:
- CWnd:组件基类
- CStatic:静态文本组件
- 使用函数:
- CWnd::GetClientRect(CRect):获取窗口尺寸和位置
- CWnd::MoveWindow(int, int, int, int):重新设置组件大小和位置(左上宽高)
- CWnd::UpdateData():更新窗口
- 使用事件:
- VM_TIMER CWnd::OnTimer(UINT):定时器事件
- BN_CLICKED:按钮点击事件
初始化变量
public: CDemo1Dlg(CWnd* pParent = NULL); // standard constructor int positionX; int speed; CStatic m_title;
OnInitDialog()
this->positionX = 100; this->speed = 20; m_title.MoveWindow(this->positionX, 100, 180, 30); this->SetTimer(1, 100, NULL);
OnTimer()
CRect lpRect; this->GetClientRect(lpRect); CRect staticRect; m_title.GetClientRect(staticRect); // TODO: Add your control notification handler code here UpdateData(); if (this->positionX + staticRect.right >= lpRect.right) { this->speed = -10; } else if (this->positionX <= lpRect.left) { this->speed = 10; } this->positionX += this->speed; m_title.MoveWindow(this->positionX, 100, 180, 30); UpdateData(); CDialog::OnTimer(nIDEvent);
本作品采用《CC 协议》,转载必须注明作者和本文链接