有时如果我们在应用中需要提供一个滚动的信息提示条(类似于页面上的跑马灯marquee),其实也很容易做到,类似于我们前面做的菜单,下面我们也讨论一下吧。
跑马灯包括的数据结构如下:
struct
_IGMarquee
{
const AEEVTBL(IGMarquee) * pvt;
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
uint32 m_nRefs;
IShell *m_pIShell;
IDisplay *m_pIDisplay;
IModule *m_pIModule;
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
boolean m_isActive;
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
AEERect m_Rect;
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
uint16 lenText;
uint16 posText;
AECHAR *m_pText;
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
uint16 m_delay;
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
IImage *m_pImageBk;
RGBVAL m_color;
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
}
;
一个背景m_pImageBk,一个字体颜色m_color,然后就是文本内容了。m_delay、lenText和posText是用来让它跑起来的辅助变量。
要实现的方法也不多,如下:
AEEINTERFACE(IGMarquee)
{
DECLARE_IBASE(IGMarquee)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
DECLARE_ICONTROL(IGMarquee)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
void (*SetText) (IGMarquee * po, AECHAR * szText);
void (*SetDelay) (IGMarquee *po,uint16 delay);
void (*SetImageBk) (IGMarquee *po,IImage *img);
void (*SetColor) (IGMarquee *po,RGBVAL i);
}
;
看看它的函数实现吧,首先HandleEvent不需要做任何事了,直接return FALSE即可,主要是那个Redraw了。需要作的事情就是调用我们的绘制函数DrawText,还有一个定时器也不断地回调这个函数:
static
void
DrawText(IGMarquee
*
pMe)
{
AECHAR szText[128];
RGBVAL oldColor;
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
if(pMe->m_pImageBk)
{
IDISPLAY_EraseRect(pMe->m_pIDisplay,&pMe->m_Rect);
IIMAGE_SetDrawSize(pMe->m_pImageBk,pMe->m_Rect.dx,pMe->m_Rect.dy);
IIMAGE_Draw(pMe->m_pImageBk,pMe->m_Rect.x,pMe->m_Rect.y);
}
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
//if( pMe->m_pText && WSTRLEN(pMe->m_pText)>pMe->lenText)
if( pMe->m_pText && WSTRLEN(pMe->m_pText)>0 )
{
//显示滚动广告
MEMSET(szText,0,sizeof(szText));
WSTRLCPY(szText,pMe->m_pText+pMe->posText,sizeof(szText));
//if( WSTRLEN(szText)<pMe->lenText)
while(IDISPLAY_MeasureText(pMe->m_pIDisplay,AEE_FONT_NORMAL,szText)<pMe->m_Rect.dx)
{
WSTRLCAT(szText,L" ",sizeof(szText));
WSTRLCAT(szText,pMe->m_pText,sizeof(szText));
}
oldColor=IDISPLAY_SetColor(pMe->m_pIDisplay, CLR_USER_TEXT, pMe->m_color);
IDISPLAY_DrawText(pMe->m_pIDisplay,AEE_FONT_NORMAL,szText,-1,pMe->m_Rect.x,pMe->m_Rect.y+1,&pMe->m_Rect,IDF_TEXT_TRANSPARENT);
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
IDISPLAY_UpdateEx(pMe->m_pIDisplay,FALSE);
IDISPLAY_SetColor(pMe->m_pIDisplay, CLR_USER_TEXT, oldColor);
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
pMe->posText++;
if(pMe->posText>WSTRLEN(pMe->m_pText))
pMe->posText=0;
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
if(pMe->m_isActive)
ISHELL_SetTimer(pMe->m_pIShell,pMe->m_delay,(PFNNOTIFY)DrawText,pMe);
}
}
与菜单中让一个选中项文本左右滚动类似,我们也让这里的跑马灯文本左右滚动起来。靠得就是那两个变量lenText和posText。
跑马灯包括的数据结构如下:
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedBlockStart.gif)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedBlockEnd.gif)
一个背景m_pImageBk,一个字体颜色m_color,然后就是文本内容了。m_delay、lenText和posText是用来让它跑起来的辅助变量。
要实现的方法也不多,如下:
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedBlockStart.gif)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedBlockEnd.gif)
看看它的函数实现吧,首先HandleEvent不需要做任何事了,直接return FALSE即可,主要是那个Redraw了。需要作的事情就是调用我们的绘制函数DrawText,还有一个定时器也不断地回调这个函数:
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedBlockStart.gif)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedSubBlockStart.gif)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedSubBlockEnd.gif)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedSubBlockStart.gif)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedSubBlockStart.gif)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedSubBlockEnd.gif)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedSubBlockEnd.gif)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedBlockEnd.gif)
与菜单中让一个选中项文本左右滚动类似,我们也让这里的跑马灯文本左右滚动起来。靠得就是那两个变量lenText和posText。