Static控件和状态栏文字滚动效果实现
来源:互联网 发布:山大网络教育报名 编辑:程序博客网 时间:2024/05/21 16:22
文字横向滚动的关键在于在计时器里递增文字位置的偏移并重绘,还要处理边界和循环绘制的效果,下面是一个基于CStatic的文字横向滚动的例子
void CMyStatic::OnTimer(UINT nIDEvent)
{
// TODO: Add your message handler code here and/or call default
CString strText;
GetWindowText(strText);
if (strText == m_strText)
{
CDC* pDC = GetDC();
pDC->SelectObject(&m_font);
CSize size = pDC->GetTextExtent(strText);
ReleaseDC(pDC);
CRect rect;
GetClientRect(rect);
int iWidth = rect.Width();
if (size.cx > iWidth)
{
Invalidate();
UpdateWindow();
m_iExtend += 2;
if (m_iExtend > size.cx)
m_iExtend -= size.cx + 8;
}
}
else
{
m_iExtend = 0;
m_strText = strText;
}
CStatic::OnTimer(nIDEvent);
}
void CMyStatic::OnPaint()
{
// TODO: Add your message handler code here
CPaintDC dc(this);
CRect rc;
GetClientRect(rc);
CString strText;
GetWindowText(strText);
CDC memDC;
memDC.CreateCompatibleDC(&dc);
CBitmap bmp;
bmp.CreateCompatibleBitmap(&dc, rc.Width(), rc.Height());
memDC.SelectObject(&bmp);
memDC.SelectObject(&m_font);
dc.SelectObject(&m_font);
memDC.FillSolidRect(rc, RGB(255, 255, 255);
CSize size = memDC.GetTextExtent(strText);
if (size.cx > rc.Width())
{
if (size.cx - m_iExtend > 0)
memDC.TextOut(rc.left - m_iExtend, rc.top + (rc.Height() - size.cy)/2, strText);
if (rc.left - m_iExtend + 8 +size.cx < rc.right)
memDC.TextOut(rc.left - m_iExtend + 8+size.cx , rc.top + (rc.Height() - size.cy)/2, strText);
}
else
memDC.TextOut(rc.left, rc.top + (rc.Height() - size.cy)/2, strText);
dc.BitBlt(rc.left, rc.top, rc.Width(), rc.Height(), &memDC, rc.left, rc.top, SRCCOPY);
memDC.DeleteDC();
bmp.DeleteObject();
}
CMyStatusBar m_wndStatusBar;
3. Also change the indicator array in MainFrm.cpp as:
static UINT indicators[] ={ID_SEPARATOR,IDS_SCROLL_PANE,//scrolling textID_INDICATOR_CAPS,ID_INDICATOR_NUM,ID_INDICATOR_SCRL,};
4. Add IDS_SCROLL_PANE in the string table with few blanks. The size of pane will depend on this blank string. There are other painfull ways of sizing a pane too.
5. Add following member to CMyStatusBar: Cstring m_strScrollText;
6. Add OnTimer() to the CMyStatusBar:
void CMyStatusBar::OnTimer(UINT nIDEvent){// TODO: Add your message handler code here and/or call defaultif (m_strScrollText.IsEmpty()){KillTimer(1);SetPaneText(CommandToIndex(IDS_SCROLL_PANE), "");return;}static UINT str_idx = 0; //offset into string//if end of string, return to topif (str_idx >= (UINT) (m_strScrollText.GetLength() / 2) - 1){str_idx = 0;}//display stringSetPaneText(CommandToIndex(IDS_SCROLL_PANE), ((LPCSTR)m_strScrollText)+str_idx);//scroll one characterstr_idx = str_idx + 1;CStatusBar::OnTimer(nIDEvent);}
7. Destroy timer:
void CMyStatusBar::OnDestroy(){CStatusBar::OnDestroy();// TODO: Add your message handler code hereKillTimer(1);}
8. Add a method to start scrolling text. This method must be called after the mainframe (and the status bar) has been constructed to display scrolling text. Perhaps from the CWinApp::InitInstance().
void CMyStatusBar::StartDisplay(void){//set text for scrollingm_strScrollText = " Hello! World. "//to make it circular scrollm_strScrollText += m_strScrollText;KillTimer(1);VERIFY(SetTimer(1, 200, NULL) != 0); //timer}
- Static控件和状态栏文字滚动效果实现
- 自定义textview控件实现文字滚动效果
- js实现文字滚动效果
- js实现文字滚动效果
- JS实现文字滚动效果
- android 实现文字滚动效果
- marquee实现文字滚动效果
- 简单实现 特效<状态栏文字来回滚动>
- 状态栏文字的滚动
- 状态栏滚动文字
- 状态栏滚动文字
- 自定义View实现文字跑马灯效果(垂直滚动和水平滚动)
- C#中使Label控件中的文字实现从左到右滚动效果
- 一个js实现任务栏文字滚动效果
- Blackberry上实现文字滚动效果
- Marquee实现文字走马灯滚动效果
- js实现文字定时上下滚动效果
- android 用textview实现文字滚动效果
- 浅谈ASP和中小企业信息化联姻的障碍
- 浅谈C++类(1)--概念和构造函数
- ASP.NET 设置架构
- Web服务搜索与执行引擎(十)——细看SAAJ的使用
- 突破信任瓶颈 ASP春天渐近
- Static控件和状态栏文字滚动效果实现
- 提高IIS网站服务器的效率的八种方法
- Linux必学命令
- ASP.NET 配置节架构
- 马上要开始工作了,也要向自己的前辈一样学习写blog了
- 晕了
- 电脑辐射危害入防护
- ubuntu6.06安装指南
- 安全问题 ASP首要短板