在BREW中打造自己的GUI(1)-图形化菜单的实现
2008-03-04 10:49
417 查看
在很多时间,我们并不满足于BREW API提供那个简单的IMenuCtl控件,其实自己做一个标准菜单是很方便的一件事情。今天我们就来讨论一下。
要实现的菜单比较简单,只支持列表视图,也就是IMenuCtl中的AEECLSID_MENUCTL 模式。
但是我们需要考虑两个要求:
1.菜单需要一个背景图,并且在每一个选中项的背景不仅仅是简单地填充色,而应该是一个图片(这样我们就可以方便地实现渐变、光晕、立体等效果了)。
2.它应该在调用接口方面与原有的IMenuCtl基本一致,这样便于我们移植原来的代码。
首先,在h文件中对菜单各个实体先做个定义如下:
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)
//自定义菜单项
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)
typedef struct
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedBlockStart.gif)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ContractedBlock.gif)
...{
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
const AECHAR * pText; // Text
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
IImage * pImage; // Image
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
const char * pszResImage;
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
const char * pszResText;
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
uint16 wText;
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
uint16 wImage;
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
uint16 wItemID;
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
uint32 dwData;
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedBlockEnd.gif)
} GMenuItem;
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)
typedef struct
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedBlockStart.gif)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ContractedBlock.gif)
...{
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
RGBVAL cText;
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
RGBVAL cSelText;
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedBlockEnd.gif)
} GMenuColors;
GMenuItem很好理解,明显是模仿着CtlAddItem来作的,只是省掉了一些东西罢了。
另外,关键的问题在于整个菜单结构的定义,如下:
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedBlockStart.gif)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ContractedBlock.gif)
struct _IGMenuCtl ...{
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
const AEEVTBL(IGMenuCtl) * pvt;
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
uint32 m_nRefs;
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
IShell *m_pIShell;
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
IDisplay *m_pIDisplay;
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
IModule *m_pIModule;
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
IImage *m_pImageBk;
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
IImage *m_pImageSe;
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
TQueueList *m_pDataList;
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
int m_Index;
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
int m_startIndex;
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
int m_pageSize;
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
int m_textPos;
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
boolean m_isActive;
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
AEERect m_Rect;
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
GMenuColors m_Colors;
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
uint32 m_Properties;
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedBlockEnd.gif)
};
前面的AEEVTBL就不说了,因为我们整个扩展GUI都是采用BREW的扩展类机制来实现的,具体方法可以参考相关资料。在这个菜单中,关键点是我们定义了一个背景图m_pImageBk和选中项的背景图m_pImageSe。其它几个字段象index/pagesize等等都是控制菜单行为的。用一个TQueueList来保存菜单项的链表(这个TQueueList也是自已实现的一个链表结构)。
好了,在实现中如何处理呢?先来看看看我们都需要些什么函数?
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)
AEEINTERFACE(IGMenuCtl)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedBlockStart.gif)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ContractedBlock.gif)
...{
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
DECLARE_IBASE(IGMenuCtl)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
DECLARE_ICONTROL(IGMenuCtl)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
boolean (*AddItem) (IGMenuCtl * po,const char * pszResFile,uint16 wResID,uint16 nItemID,AECHAR * pText,uint32 lData);
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
boolean (*AddItemEx) (IGMenuCtl * po, GMenuItem * pai);
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
boolean (*GetItemData) (IGMenuCtl * po, uint16 nItemID, uint32 * plData);
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
void (*SetSel) (IGMenuCtl * po, uint16 nItemID);
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
uint16 (*GetSel) (IGMenuCtl * po);
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
int (*CurrentIndex) (IGMenuCtl * po);
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
int (*GetItemCount) (IGMenuCtl * po);
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
uint16 (*GetItemID) (IGMenuCtl * po, int nIdx);
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
boolean (*GetItem) (IGMenuCtl * po, uint16 wID, GMenuItem * pai);
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
boolean (*SetItem) (IGMenuCtl * po, uint16 wID, uint16 wFlags,GMenuItem * pai);
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
void (*SetItemText) (IGMenuCtl * po, uint16 wID,const char * pszResFile,uint16 wResID,AECHAR * pText);
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
void (*SetImageBk) (IGMenuCtl * po,IImage * pImg);
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
void (*SetImageSe) (IGMenuCtl * po,IImage * pImg);
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
void (*SetColors) (IGMenuCtl * pIMenuCtl, GMenuColors * pc);
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedBlockEnd.gif)
};
大多数函数都是模仿着IMenuCtl来定义的,只有这样才可以方便地将原来的基于IMenuCtl的代码移植到我们的IGMenuCtl上来。
OK,剩下的事情就好办了。在HandleEvent中,处理几个键,用户按了上下方向键则修改m_Index来改变菜单的当前选中项索引,用户按了SELECT键则发送一个EVT_COMMAND事件即可,如:ISHELL_PostEvent(pMe->m_pIShell,0,EVT_COMMAND,0,0)。
而在Redraw中,就是我们实际的绘制过程了,步骤是先绘背景m_pImageBk,再循环m_pDataList绘制每一个项,如果是选中项则给他绘一个背景m_pImageSe。代码如下:
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)
static boolean IGMenuCtl_Redraw(IGMenuCtl * pMe)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedBlockStart.gif)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ContractedBlock.gif)
...{
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
int i,j,height,h,a,b;
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
AEEImageInfo infSe,infIc;
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
AEERect rec;
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
int xx,yy,dxx,dyy;
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
RGBVAL oldColor;
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
GMenuItem * pData=NULL;
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
TQueueList * p = pMe->m_pDataList;
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
ZEROAT(&infSe);
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
IDISPLAY_EraseRect(pMe->m_pIDisplay,&pMe->m_Rect);
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
h=IDISPLAY_GetFontMetrics(pMe->m_pIDisplay,AEE_FONT_NORMAL,&a,&b);
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
//绘制背景图
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
if(pMe->m_pImageBk)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedSubBlockStart.gif)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ContractedSubBlock.gif)
...{
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
IIMAGE_SetDrawSize(pMe->m_pImageBk,pMe->m_Rect.dx,pMe->m_Rect.dy);
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
IIMAGE_Draw(pMe->m_pImageBk,pMe->m_Rect.x,pMe->m_Rect.y);
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedSubBlockEnd.gif)
}
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
//确定菜单高度
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
if(pMe->m_pImageSe)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedSubBlockStart.gif)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ContractedSubBlock.gif)
...{
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
IIMAGE_GetInfo(pMe->m_pImageSe,&infSe);
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
IIMAGE_SetDrawSize(pMe->m_pImageSe,pMe->m_Rect.dx,infSe.cy);
![](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)
i=0;
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
j=0;
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
height=pMe->m_Rect.y;
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
while(p)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedSubBlockStart.gif)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ContractedSubBlock.gif)
...{
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
if(i<pMe->m_startIndex)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedSubBlockStart.gif)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ContractedSubBlock.gif)
...{
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
p=p->pNext;
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
i++;
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
continue;
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedSubBlockEnd.gif)
}
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
if(j>=pMe->m_pageSize)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedSubBlockStart.gif)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ContractedSubBlock.gif)
...{
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
break;
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedSubBlockEnd.gif)
}
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
pData=(GMenuItem*)p->pData;
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
if(i==pMe->m_Index)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedSubBlockStart.gif)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ContractedSubBlock.gif)
...{
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
IIMAGE_Draw(pMe->m_pImageSe,pMe->m_Rect.x,height);
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
ZEROAT(&infIc);
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
if(pData->pImage)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedSubBlockStart.gif)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ContractedSubBlock.gif)
...{
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
IIMAGE_GetInfo(pData->pImage,&infIc);
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
IIMAGE_Draw(pData->pImage,pMe->m_Rect.x,height+(infSe.cy-infIc.cy)/2);
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedSubBlockEnd.gif)
}
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
xx=pMe->m_Rect.x+infIc.cx;
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
yy=height+(infSe.cy-h)/2;
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
dxx=pMe->m_Rect.x+pMe->m_Rect.dx-xx;
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
dyy=h;
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
SETAEERECT(&rec,xx,yy,dxx,dyy);
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
oldColor = IDISPLAY_SetColor(pMe->m_pIDisplay,CLR_USER_TEXT,pMe->m_Colors.cSelText);
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
if(pMe->m_Properties&0x02)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
IDISPLAY_DrawText(pMe->m_pIDisplay,AEE_FONT_NORMAL,pData->pText+pMe->m_textPos,-1,xx+1,yy,&rec,IDF_TEXT_TRANSPARENT);
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
IDISPLAY_DrawText(pMe->m_pIDisplay,AEE_FONT_NORMAL,pData->pText+pMe->m_textPos,-1,xx,yy,&rec,IDF_TEXT_TRANSPARENT);
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
if(pMe->m_isActive)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedSubBlockStart.gif)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ContractedSubBlock.gif)
...{
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
if(IDISPLAY_MeasureText(pMe->m_pIDisplay,AEE_FONT_NORMAL,pData->pText)>dxx)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedSubBlockStart.gif)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ContractedSubBlock.gif)
...{
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
if(IDISPLAY_MeasureText(pMe->m_pIDisplay,AEE_FONT_NORMAL,pData->pText+pMe->m_textPos)>dxx)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedSubBlockStart.gif)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ContractedSubBlock.gif)
...{
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
pMe->m_textPos++;
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedSubBlockEnd.gif)
}
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
else
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
pMe->m_textPos=0;
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
ISHELL_SetTimer(pMe->m_pIShell,300,(PFNNOTIFY)IGMenuCtl_Redraw,(void*)pMe);
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedSubBlockEnd.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)
height+=infSe.cy;
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
IDISPLAY_SetColor(pMe->m_pIDisplay,CLR_USER_TEXT,oldColor);
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedSubBlockEnd.gif)
}
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
else
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedSubBlockStart.gif)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ContractedSubBlock.gif)
...{
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
ZEROAT(&infIc);
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
if(pData->pImage)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedSubBlockStart.gif)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ContractedSubBlock.gif)
...{
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
IIMAGE_GetInfo(pData->pImage,&infIc);
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
IIMAGE_Draw(pData->pImage,pMe->m_Rect.x,height+(infSe.cy-infIc.cy)/2);
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedSubBlockEnd.gif)
}
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
xx=pMe->m_Rect.x+infIc.cx;
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
yy=height+(infSe.cy-h)/2;
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
dxx=pMe->m_Rect.x+pMe->m_Rect.dx-xx;
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
dyy=h;
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
SETAEERECT(&rec,xx,yy,dxx,dyy);
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
oldColor = IDISPLAY_SetColor(pMe->m_pIDisplay,CLR_USER_TEXT,pMe->m_Colors.cText);
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
if(pMe->m_Properties&0x01)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
IDISPLAY_DrawText(pMe->m_pIDisplay,AEE_FONT_NORMAL,pData->pText,-1,xx+1,yy,&rec,IDF_TEXT_TRANSPARENT);
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
IDISPLAY_DrawText(pMe->m_pIDisplay,AEE_FONT_NORMAL,pData->pText,-1,xx,yy,&rec,IDF_TEXT_TRANSPARENT);
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
height+=infSe.cy;
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
IDISPLAY_SetColor(pMe->m_pIDisplay,CLR_USER_TEXT,oldColor);
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedSubBlockEnd.gif)
}
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
p=p->pNext;
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
i++;
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
j++;
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedSubBlockEnd.gif)
}
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
IDISPLAY_Update(pMe->m_pIDisplay);
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
return TRUE;
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedBlockEnd.gif)
}
上面代码中稍要注意的一点是,如果这个选中项的文字比较长,则需要提供滚动效果(IMenuCtl是提供了的)。一句话,加一个定时器ISHELL_SetTimer(pMe->m_pIShell,300,(PFNNOTIFY)IGMenuCtl_Redraw,(void*)pMe);即可。m_textPos就是用来控制当前字串显示的截取位置。
至此,主要的功能就搞定了,那些AddItem、AddItemEx、SetImageBk和SetImageSe都很简单。
要实现的菜单比较简单,只支持列表视图,也就是IMenuCtl中的AEECLSID_MENUCTL 模式。
但是我们需要考虑两个要求:
1.菜单需要一个背景图,并且在每一个选中项的背景不仅仅是简单地填充色,而应该是一个图片(这样我们就可以方便地实现渐变、光晕、立体等效果了)。
2.它应该在调用接口方面与原有的IMenuCtl基本一致,这样便于我们移植原来的代码。
首先,在h文件中对菜单各个实体先做个定义如下:
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)
//自定义菜单项
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)
typedef struct
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedBlockStart.gif)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ContractedBlock.gif)
...{
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
const AECHAR * pText; // Text
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
IImage * pImage; // Image
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
const char * pszResImage;
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
const char * pszResText;
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
uint16 wText;
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
uint16 wImage;
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
uint16 wItemID;
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
uint32 dwData;
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedBlockEnd.gif)
} GMenuItem;
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)
typedef struct
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedBlockStart.gif)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ContractedBlock.gif)
...{
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
RGBVAL cText;
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
RGBVAL cSelText;
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedBlockEnd.gif)
} GMenuColors;
GMenuItem很好理解,明显是模仿着CtlAddItem来作的,只是省掉了一些东西罢了。
另外,关键的问题在于整个菜单结构的定义,如下:
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedBlockStart.gif)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ContractedBlock.gif)
struct _IGMenuCtl ...{
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
const AEEVTBL(IGMenuCtl) * pvt;
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
uint32 m_nRefs;
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
IShell *m_pIShell;
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
IDisplay *m_pIDisplay;
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
IModule *m_pIModule;
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
IImage *m_pImageBk;
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
IImage *m_pImageSe;
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
TQueueList *m_pDataList;
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
int m_Index;
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
int m_startIndex;
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
int m_pageSize;
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
int m_textPos;
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
boolean m_isActive;
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
AEERect m_Rect;
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
GMenuColors m_Colors;
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
uint32 m_Properties;
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedBlockEnd.gif)
};
前面的AEEVTBL就不说了,因为我们整个扩展GUI都是采用BREW的扩展类机制来实现的,具体方法可以参考相关资料。在这个菜单中,关键点是我们定义了一个背景图m_pImageBk和选中项的背景图m_pImageSe。其它几个字段象index/pagesize等等都是控制菜单行为的。用一个TQueueList来保存菜单项的链表(这个TQueueList也是自已实现的一个链表结构)。
好了,在实现中如何处理呢?先来看看看我们都需要些什么函数?
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)
AEEINTERFACE(IGMenuCtl)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedBlockStart.gif)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ContractedBlock.gif)
...{
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
DECLARE_IBASE(IGMenuCtl)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
DECLARE_ICONTROL(IGMenuCtl)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
boolean (*AddItem) (IGMenuCtl * po,const char * pszResFile,uint16 wResID,uint16 nItemID,AECHAR * pText,uint32 lData);
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
boolean (*AddItemEx) (IGMenuCtl * po, GMenuItem * pai);
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
boolean (*GetItemData) (IGMenuCtl * po, uint16 nItemID, uint32 * plData);
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
void (*SetSel) (IGMenuCtl * po, uint16 nItemID);
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
uint16 (*GetSel) (IGMenuCtl * po);
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
int (*CurrentIndex) (IGMenuCtl * po);
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
int (*GetItemCount) (IGMenuCtl * po);
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
uint16 (*GetItemID) (IGMenuCtl * po, int nIdx);
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
boolean (*GetItem) (IGMenuCtl * po, uint16 wID, GMenuItem * pai);
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
boolean (*SetItem) (IGMenuCtl * po, uint16 wID, uint16 wFlags,GMenuItem * pai);
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
void (*SetItemText) (IGMenuCtl * po, uint16 wID,const char * pszResFile,uint16 wResID,AECHAR * pText);
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
void (*SetImageBk) (IGMenuCtl * po,IImage * pImg);
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
void (*SetImageSe) (IGMenuCtl * po,IImage * pImg);
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
void (*SetColors) (IGMenuCtl * pIMenuCtl, GMenuColors * pc);
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedBlockEnd.gif)
};
大多数函数都是模仿着IMenuCtl来定义的,只有这样才可以方便地将原来的基于IMenuCtl的代码移植到我们的IGMenuCtl上来。
OK,剩下的事情就好办了。在HandleEvent中,处理几个键,用户按了上下方向键则修改m_Index来改变菜单的当前选中项索引,用户按了SELECT键则发送一个EVT_COMMAND事件即可,如:ISHELL_PostEvent(pMe->m_pIShell,0,EVT_COMMAND,0,0)。
而在Redraw中,就是我们实际的绘制过程了,步骤是先绘背景m_pImageBk,再循环m_pDataList绘制每一个项,如果是选中项则给他绘一个背景m_pImageSe。代码如下:
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)
static boolean IGMenuCtl_Redraw(IGMenuCtl * pMe)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedBlockStart.gif)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ContractedBlock.gif)
...{
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
int i,j,height,h,a,b;
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
AEEImageInfo infSe,infIc;
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
AEERect rec;
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
int xx,yy,dxx,dyy;
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
RGBVAL oldColor;
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
GMenuItem * pData=NULL;
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
TQueueList * p = pMe->m_pDataList;
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
ZEROAT(&infSe);
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
IDISPLAY_EraseRect(pMe->m_pIDisplay,&pMe->m_Rect);
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
h=IDISPLAY_GetFontMetrics(pMe->m_pIDisplay,AEE_FONT_NORMAL,&a,&b);
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
//绘制背景图
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
if(pMe->m_pImageBk)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedSubBlockStart.gif)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ContractedSubBlock.gif)
...{
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
IIMAGE_SetDrawSize(pMe->m_pImageBk,pMe->m_Rect.dx,pMe->m_Rect.dy);
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
IIMAGE_Draw(pMe->m_pImageBk,pMe->m_Rect.x,pMe->m_Rect.y);
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedSubBlockEnd.gif)
}
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
//确定菜单高度
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
if(pMe->m_pImageSe)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedSubBlockStart.gif)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ContractedSubBlock.gif)
...{
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
IIMAGE_GetInfo(pMe->m_pImageSe,&infSe);
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
IIMAGE_SetDrawSize(pMe->m_pImageSe,pMe->m_Rect.dx,infSe.cy);
![](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)
i=0;
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
j=0;
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
height=pMe->m_Rect.y;
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
while(p)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedSubBlockStart.gif)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ContractedSubBlock.gif)
...{
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
if(i<pMe->m_startIndex)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedSubBlockStart.gif)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ContractedSubBlock.gif)
...{
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
p=p->pNext;
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
i++;
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
continue;
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedSubBlockEnd.gif)
}
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
if(j>=pMe->m_pageSize)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedSubBlockStart.gif)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ContractedSubBlock.gif)
...{
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
break;
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedSubBlockEnd.gif)
}
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
pData=(GMenuItem*)p->pData;
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
if(i==pMe->m_Index)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedSubBlockStart.gif)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ContractedSubBlock.gif)
...{
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
IIMAGE_Draw(pMe->m_pImageSe,pMe->m_Rect.x,height);
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
ZEROAT(&infIc);
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
if(pData->pImage)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedSubBlockStart.gif)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ContractedSubBlock.gif)
...{
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
IIMAGE_GetInfo(pData->pImage,&infIc);
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
IIMAGE_Draw(pData->pImage,pMe->m_Rect.x,height+(infSe.cy-infIc.cy)/2);
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedSubBlockEnd.gif)
}
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
xx=pMe->m_Rect.x+infIc.cx;
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
yy=height+(infSe.cy-h)/2;
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
dxx=pMe->m_Rect.x+pMe->m_Rect.dx-xx;
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
dyy=h;
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
SETAEERECT(&rec,xx,yy,dxx,dyy);
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
oldColor = IDISPLAY_SetColor(pMe->m_pIDisplay,CLR_USER_TEXT,pMe->m_Colors.cSelText);
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
if(pMe->m_Properties&0x02)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
IDISPLAY_DrawText(pMe->m_pIDisplay,AEE_FONT_NORMAL,pData->pText+pMe->m_textPos,-1,xx+1,yy,&rec,IDF_TEXT_TRANSPARENT);
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
IDISPLAY_DrawText(pMe->m_pIDisplay,AEE_FONT_NORMAL,pData->pText+pMe->m_textPos,-1,xx,yy,&rec,IDF_TEXT_TRANSPARENT);
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
if(pMe->m_isActive)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedSubBlockStart.gif)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ContractedSubBlock.gif)
...{
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
if(IDISPLAY_MeasureText(pMe->m_pIDisplay,AEE_FONT_NORMAL,pData->pText)>dxx)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedSubBlockStart.gif)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ContractedSubBlock.gif)
...{
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
if(IDISPLAY_MeasureText(pMe->m_pIDisplay,AEE_FONT_NORMAL,pData->pText+pMe->m_textPos)>dxx)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedSubBlockStart.gif)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ContractedSubBlock.gif)
...{
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
pMe->m_textPos++;
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedSubBlockEnd.gif)
}
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
else
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
pMe->m_textPos=0;
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
ISHELL_SetTimer(pMe->m_pIShell,300,(PFNNOTIFY)IGMenuCtl_Redraw,(void*)pMe);
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedSubBlockEnd.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)
height+=infSe.cy;
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
IDISPLAY_SetColor(pMe->m_pIDisplay,CLR_USER_TEXT,oldColor);
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedSubBlockEnd.gif)
}
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
else
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedSubBlockStart.gif)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ContractedSubBlock.gif)
...{
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
ZEROAT(&infIc);
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
if(pData->pImage)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedSubBlockStart.gif)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ContractedSubBlock.gif)
...{
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
IIMAGE_GetInfo(pData->pImage,&infIc);
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
IIMAGE_Draw(pData->pImage,pMe->m_Rect.x,height+(infSe.cy-infIc.cy)/2);
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedSubBlockEnd.gif)
}
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
xx=pMe->m_Rect.x+infIc.cx;
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
yy=height+(infSe.cy-h)/2;
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
dxx=pMe->m_Rect.x+pMe->m_Rect.dx-xx;
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
dyy=h;
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
SETAEERECT(&rec,xx,yy,dxx,dyy);
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
oldColor = IDISPLAY_SetColor(pMe->m_pIDisplay,CLR_USER_TEXT,pMe->m_Colors.cText);
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
if(pMe->m_Properties&0x01)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
IDISPLAY_DrawText(pMe->m_pIDisplay,AEE_FONT_NORMAL,pData->pText,-1,xx+1,yy,&rec,IDF_TEXT_TRANSPARENT);
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
IDISPLAY_DrawText(pMe->m_pIDisplay,AEE_FONT_NORMAL,pData->pText,-1,xx,yy,&rec,IDF_TEXT_TRANSPARENT);
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
height+=infSe.cy;
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
IDISPLAY_SetColor(pMe->m_pIDisplay,CLR_USER_TEXT,oldColor);
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedSubBlockEnd.gif)
}
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
p=p->pNext;
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
i++;
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
j++;
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedSubBlockEnd.gif)
}
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
IDISPLAY_Update(pMe->m_pIDisplay);
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
return TRUE;
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedBlockEnd.gif)
}
上面代码中稍要注意的一点是,如果这个选中项的文字比较长,则需要提供滚动效果(IMenuCtl是提供了的)。一句话,加一个定时器ISHELL_SetTimer(pMe->m_pIShell,300,(PFNNOTIFY)IGMenuCtl_Redraw,(void*)pMe);即可。m_textPos就是用来控制当前字串显示的截取位置。
至此,主要的功能就搞定了,那些AddItem、AddItemEx、SetImageBk和SetImageSe都很简单。
相关文章推荐
- 在BREW中打造自己的GUI(2)-TabPane的实现
- 在BREW中打造自己的GUI(4)-IGStatic的实现
- 在BREW中打造自己的GUI(7)-动态效果的实现
- 在BREW中打造自己的GUI(5)-滚动条的实现
- 在BREW中打造自己的GUI(5)-滚动条的实现
- 在BREW中打造自己的GUI(6)-单选框与复选框的实现
- 在BREW中打造自己的GUI(3)-做一个跑马灯的效果
- 在BREW中打造自己的GUI(8)-IWEB的封装
- android 自己实现qqminihd 左右滑动菜单效果
- Android自己定义TabActivity(实现仿新浪微博底部菜单更新UI)
- 打造自己的MFC:thunk技术实现窗口类的封装
- Android 打造自己的个性化应用(五):仿墨迹天气实现续--> 使用Ant实现zip/tar的压缩与解压
- 关于Scroller的使用以及自己实现一个侧滑菜单
- 打造自己的wave音频播放器-使用waveOutOpen与waveOutWrite实现
- C#之使用NotifyIcon实现任务栏托盘菜单,图标闪烁效果及气泡提示 很多程序是只需要后台运行的,甚至不需要自己的应用界面。NotifyIcon提供了程序在任务栏的显示功能 程序下载链接如下
- silverlight2自定义鼠标右键菜单,屏蔽原来右键菜单显示的内容,打造自己喜欢的菜单。
- 自己动手打造ORM(五) —实现
- 一个树控件类的实现---打造自己的树控件
- Matlab 不使用GUI,底层代码实现右键菜单