MFC编程(一)

实现通过定时器来回滚动Label

  • 使用类:
    • CWnd:组件基类
    • CStatic:静态文本组件
  • 使用函数:
    • CWnd::GetClientRect(CRect):获取窗口尺寸和位置
    • CWnd::MoveWindow(int, int, int, int):重新设置组件大小和位置(左上宽高)
    • CWnd::UpdateData():更新窗口
  • 使用事件:

初始化变量

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

MFC编程(一)

MFC
本作品采用《CC 协议》,转载必须注明作者和本文链接
讨论数量: 0
(= ̄ω ̄=)··· 暂无内容!

讨论应以学习和精进为目的。请勿发布不友善或者负能量的内容,与人为善,比聪明更重要!