vc++从入门到精通第七章
发表在C语言图书答疑
2014-10-21
是否精华
是
否
版块置顶:
是
否
设置时间:
非永久
永久
起始时间:
结束时间:
是否扣分:
是
否
图标菜单c:\program files\microsoft visual studio\myprojects\图标菜单\menuicon.h(31) : error C2065: 'MAX_MENUCOUNT' : undeclared identifier
c:\program files\microsoft visual studio\myprojects\图标菜单\menuicon.h(31) : error C2057: expected constant expression
c:\program files\microsoft visual studio\myprojects\图标菜单\menuicon.h(31) : warning C4200: nonstandard extension used : zero-sized array in struct/union
c:\program files\microsoft visual studio\myprojects\图标菜单\menuicon.h(32) : error C2229: class 'CMenuIcon' has an illegal zero-sized array出现以下错误该怎么解决
c:\program files\microsoft visual studio\myprojects\图标菜单\menuicon.h(31) : error C2057: expected constant expression
c:\program files\microsoft visual studio\myprojects\图标菜单\menuicon.h(31) : warning C4200: nonstandard extension used : zero-sized array in struct/union
c:\program files\microsoft visual studio\myprojects\图标菜单\menuicon.h(32) : error C2229: class 'CMenuIcon' has an illegal zero-sized array出现以下错误该怎么解决
精彩评论 11
2014-10-23
板凳
struct CMenuItem
{
CString m_ItemText;
int m_IconIndex;
int m_ItemID;
};
class CMenuIcon : public CMenu
{
// Construction
public:
CMenuIcon();
BOOL MenuItem(CMenu*pMenu);
BOOL AttatchMenu(UINT m_uID);
void DrawItemText(CDC*pDC,LPSTR Str,CRect Rect);
void DrawItemIcon(CDC*pDC,CRect Rect,int Icon);
void DrawSeparater(CDC*pDC,CRect Rect);
void DrawComMenu(CDC*pDC,CRect Rect,BOOL Selected);
void DrawTopMenu(CDC*pDC,CRect Rect,BOOL Selected);
virtual ~CMenuIcon();
CMenuItem m_ItemLists[MAX_MENUCOUNT];
int m_Index;
int m_IconIndex;
CImageList m_ImageList;
virtual void MeasureItem(LPMEASUREITEMSTRUCT lpStruct);
virtual void DrawItem(LPDRAWITEMSTRUCT lpStruct);
};
{
CString m_ItemText;
int m_IconIndex;
int m_ItemID;
};
class CMenuIcon : public CMenu
{
// Construction
public:
CMenuIcon();
BOOL MenuItem(CMenu*pMenu);
BOOL AttatchMenu(UINT m_uID);
void DrawItemText(CDC*pDC,LPSTR Str,CRect Rect);
void DrawItemIcon(CDC*pDC,CRect Rect,int Icon);
void DrawSeparater(CDC*pDC,CRect Rect);
void DrawComMenu(CDC*pDC,CRect Rect,BOOL Selected);
void DrawTopMenu(CDC*pDC,CRect Rect,BOOL Selected);
virtual ~CMenuIcon();
CMenuItem m_ItemLists[MAX_MENUCOUNT];
int m_Index;
int m_IconIndex;
CImageList m_ImageList;
virtual void MeasureItem(LPMEASUREITEMSTRUCT lpStruct);
virtual void DrawItem(LPDRAWITEMSTRUCT lpStruct);
};
2014-10-23
地板
CMenuIcon::CMenuIcon()
{
m_Index=0;
m_IconIndex=0;
m_ImageList.Create(16,16,ILC_COLOR24|ILC_MASK,0,0);
m_ImageList.Add(AfxGetApp()->LoadIcon(IDI_ICON1));
m_ImageList.Add(AfxGetApp()->LoadIcon(IDI_ICON2));
m_ImageList.Add(AfxGetApp()->LoadIcon(IDI_ICON3));
m_ImageList.Add(AfxGetApp()->LoadIcon(IDI_ICON4));
m_ImageList.Add(AfxGetApp()->LoadIcon(IDI_ICON5));
m_ImageList.Add(AfxGetApp()->LoadIcon(IDI_ICON6));
}
CMenuIcon::~CMenuIcon()
{
}
BOOL CMenuIcon::AttatchMenu(UINT m_uID)
{
LoadMenu(m_uID);
return TRUE;
}
BOOL CMenuIcon::MenuItem(CMenu*pMenu)
{
if(pMenu!=NULL)
{
int m_Count=pMenu->GetMenuItemCount();
for(int i=0;i<m_Count;i++)
{
//获得菜单文本
pMenu->GetMenuString(i,m_ItemLists[m_Index].m_ItemText,MF_BYPOSITION);
int m_itemID=pMenu->GetMenuItemID(i);
m_ItemLists[m_Index].m_ItemID=m_itemID;
if(m_itemID>0)
{
m_ItemLists[m_Index].m_IconIndex=m_IconIndex;
m_IconIndex+=1;
}
//修改菜单信息
pMenu->ModifyMenu(i,MF_OWNERDRAW|MF_BYPOSITION|MF_STRING,
m_ItemLists[m_Index].m_ItemID,(LPSTR)&(m_ItemLists[m_Index]));
m_Index+=1;
CMenu*m_SubMenu=pMenu->GetSubMenu(i);
if(m_SubMenu)
{
MenuItem(m_SubMenu);
}
}
}
return TRUE;
}
void CMenuIcon::MeasureItem(LPMEASUREITEMSTRUCT lpStruct)
{
if(lpStruct->CtlType==ODT_MENU)
{
lpStruct->itemHeight = ITEMHEIGHT;
lpStruct->itemWidth = ITEWIDTH;
CMenuItem*m_item;
m_item=(CMenuItem*)lpStruct->itemData;
//设置菜单项宽度
lpStruct->itemWidth=((CMenuItem*)lpStruct->itemData)->m_ItemText.GetLength()*10;
if(m_item->m_ItemID==0)
{
lpStruct->itemHeight=2;
}
}
}
void CMenuIcon::DrawItemText(CDC*pDC,LPSTR Str,CRect Rect)
{
pDC->DrawText(Str,Rect,DT_CENTER|DT_VCENTER|DT_SINGLELINE);
}
void CMenuIcon::DrawItemIcon(CDC*pDC,CRect Rect,int Icon)
{
m_ImageList.Draw(pDC,Icon,CPoint(Rect.left+2,Rect.top+4),ILD_TRANSPARENT);
}
void CMenuIcon::DrawSeparater(CDC*pDC,CRect Rect)
{
pDC->Draw3dRect(Rect,RGB(255,0,255),RGB(255,0,255));
}
void CMenuIcon::DrawTopMenu(CDC*pDC,CRect Rect,BOOL Selected)
{
if(Selected)
{
pDC->Rectangle(&Rect);
Rect.DeflateRect(1,1);
pDC->FillSolidRect(Rect,RGB(190,170,220));
}
else
{
pDC->FillSolidRect(&Rect,RGB(192,192,192));
}
}
void CMenuIcon::DrawComMenu(CDC*pDC,CRect Rect,BOOL Selected)
{
if(Selected)
{
pDC->Rectangle(Rect);
Rect.DeflateRect(1,1);
pDC->FillSolidRect(Rect,RGB(255,255,255));
}
}
void CMenuIcon::DrawItem(LPDRAWITEMSTRUCT lpStruct)
{
if(lpStruct->CtlType==ODT_MENU)
{
if(lpStruct->itemData==NULL)return;
unsigned int m_state=lpStruct->itemState;
CDC* pDC=CDC::FromHandle(lpStruct->hDC);
CString str=((CMenuItem*)(lpStruct->itemData))->m_ItemText;
LPSTR m_str=str.GetBuffer(str.GetLength());
int m_itemID=((CMenuItem*)(lpStruct->itemData))->m_ItemID;
int m_itemicon=((CMenuItem*)(lpStruct->itemData))->m_IconIndex;
CRect m_rect=lpStruct->rcItem;
pDC->SetBkMode(TRANSPARENT);
switch(m_itemID)
{
case -1:
{
//绘制顶层菜单
DrawTopMenu(pDC,m_rect,(m_state&ODS_SELECTED)||(m_state&0X0040));
DrawItemText(pDC,m_str,m_rect);
break;
}
case 0:
{
DrawSeparater(pDC,m_rect);
break;
}
default:
{
DrawComMenu(pDC,m_rect,m_state&ODS_SELECTED);
DrawItemText(pDC,m_str,m_rect);
DrawItemIcon(pDC,m_rect,m_itemicon);
break;
}
}
}
}
{
m_Index=0;
m_IconIndex=0;
m_ImageList.Create(16,16,ILC_COLOR24|ILC_MASK,0,0);
m_ImageList.Add(AfxGetApp()->LoadIcon(IDI_ICON1));
m_ImageList.Add(AfxGetApp()->LoadIcon(IDI_ICON2));
m_ImageList.Add(AfxGetApp()->LoadIcon(IDI_ICON3));
m_ImageList.Add(AfxGetApp()->LoadIcon(IDI_ICON4));
m_ImageList.Add(AfxGetApp()->LoadIcon(IDI_ICON5));
m_ImageList.Add(AfxGetApp()->LoadIcon(IDI_ICON6));
}
CMenuIcon::~CMenuIcon()
{
}
BOOL CMenuIcon::AttatchMenu(UINT m_uID)
{
LoadMenu(m_uID);
return TRUE;
}
BOOL CMenuIcon::MenuItem(CMenu*pMenu)
{
if(pMenu!=NULL)
{
int m_Count=pMenu->GetMenuItemCount();
for(int i=0;i<m_Count;i++)
{
//获得菜单文本
pMenu->GetMenuString(i,m_ItemLists[m_Index].m_ItemText,MF_BYPOSITION);
int m_itemID=pMenu->GetMenuItemID(i);
m_ItemLists[m_Index].m_ItemID=m_itemID;
if(m_itemID>0)
{
m_ItemLists[m_Index].m_IconIndex=m_IconIndex;
m_IconIndex+=1;
}
//修改菜单信息
pMenu->ModifyMenu(i,MF_OWNERDRAW|MF_BYPOSITION|MF_STRING,
m_ItemLists[m_Index].m_ItemID,(LPSTR)&(m_ItemLists[m_Index]));
m_Index+=1;
CMenu*m_SubMenu=pMenu->GetSubMenu(i);
if(m_SubMenu)
{
MenuItem(m_SubMenu);
}
}
}
return TRUE;
}
void CMenuIcon::MeasureItem(LPMEASUREITEMSTRUCT lpStruct)
{
if(lpStruct->CtlType==ODT_MENU)
{
lpStruct->itemHeight = ITEMHEIGHT;
lpStruct->itemWidth = ITEWIDTH;
CMenuItem*m_item;
m_item=(CMenuItem*)lpStruct->itemData;
//设置菜单项宽度
lpStruct->itemWidth=((CMenuItem*)lpStruct->itemData)->m_ItemText.GetLength()*10;
if(m_item->m_ItemID==0)
{
lpStruct->itemHeight=2;
}
}
}
void CMenuIcon::DrawItemText(CDC*pDC,LPSTR Str,CRect Rect)
{
pDC->DrawText(Str,Rect,DT_CENTER|DT_VCENTER|DT_SINGLELINE);
}
void CMenuIcon::DrawItemIcon(CDC*pDC,CRect Rect,int Icon)
{
m_ImageList.Draw(pDC,Icon,CPoint(Rect.left+2,Rect.top+4),ILD_TRANSPARENT);
}
void CMenuIcon::DrawSeparater(CDC*pDC,CRect Rect)
{
pDC->Draw3dRect(Rect,RGB(255,0,255),RGB(255,0,255));
}
void CMenuIcon::DrawTopMenu(CDC*pDC,CRect Rect,BOOL Selected)
{
if(Selected)
{
pDC->Rectangle(&Rect);
Rect.DeflateRect(1,1);
pDC->FillSolidRect(Rect,RGB(190,170,220));
}
else
{
pDC->FillSolidRect(&Rect,RGB(192,192,192));
}
}
void CMenuIcon::DrawComMenu(CDC*pDC,CRect Rect,BOOL Selected)
{
if(Selected)
{
pDC->Rectangle(Rect);
Rect.DeflateRect(1,1);
pDC->FillSolidRect(Rect,RGB(255,255,255));
}
}
void CMenuIcon::DrawItem(LPDRAWITEMSTRUCT lpStruct)
{
if(lpStruct->CtlType==ODT_MENU)
{
if(lpStruct->itemData==NULL)return;
unsigned int m_state=lpStruct->itemState;
CDC* pDC=CDC::FromHandle(lpStruct->hDC);
CString str=((CMenuItem*)(lpStruct->itemData))->m_ItemText;
LPSTR m_str=str.GetBuffer(str.GetLength());
int m_itemID=((CMenuItem*)(lpStruct->itemData))->m_ItemID;
int m_itemicon=((CMenuItem*)(lpStruct->itemData))->m_IconIndex;
CRect m_rect=lpStruct->rcItem;
pDC->SetBkMode(TRANSPARENT);
switch(m_itemID)
{
case -1:
{
//绘制顶层菜单
DrawTopMenu(pDC,m_rect,(m_state&ODS_SELECTED)||(m_state&0X0040));
DrawItemText(pDC,m_str,m_rect);
break;
}
case 0:
{
DrawSeparater(pDC,m_rect);
break;
}
default:
{
DrawComMenu(pDC,m_rect,m_state&ODS_SELECTED);
DrawItemText(pDC,m_str,m_rect);
DrawItemIcon(pDC,m_rect,m_itemicon);
break;
}
}
}
}
2014-10-24
7L
[FIELDSET][LEGEND]引自:2楼[/LEGEND]
struct CMenuItem
{
CString m_ItemText;
int m_IconIndex;
int m_ItemID;
};
class CMenuIcon : public CMenu
{
// Construction
public:
CMenuIcon();
BOOL MenuItem(CMenu*pMenu);
BOOL AttatchMenu(UINT m_uID);
void DrawItemText(CDC*pDC,LPSTR Str,CRect Rect);
void DrawItemIcon(CDC*pDC,CRect Rect,int Icon);
void DrawSeparater(CDC*pDC,CRect Rect);
void DrawComMenu(CDC*pDC,CRect Rect,BOOL Selected);
void DrawTopMenu(CDC*pDC,CRect Rect,BOOL Selected);
virtual ~CMenuIcon();
CMenuItem m_ItemLists[MAX_MENUCOUNT];
int m_Index;
int m_IconIndex;
CImageList m_ImageList;
virtual void MeasureItem(LPMEASUREITEMSTRUCT lpStruct);
virtual void DrawItem(LPDRAWITEMSTRUCT lpStruct);
};
[/FIELDSET]
回复:在上面定义:const int MAX_MENUCOUNT = 60,ITEMHEIGHT = 26,ITEMWIDTH = 120;定义菜单项数量
struct CMenuItem
{
CString m_ItemText;
int m_IconIndex;
int m_ItemID;
};
class CMenuIcon : public CMenu
{
// Construction
public:
CMenuIcon();
BOOL MenuItem(CMenu*pMenu);
BOOL AttatchMenu(UINT m_uID);
void DrawItemText(CDC*pDC,LPSTR Str,CRect Rect);
void DrawItemIcon(CDC*pDC,CRect Rect,int Icon);
void DrawSeparater(CDC*pDC,CRect Rect);
void DrawComMenu(CDC*pDC,CRect Rect,BOOL Selected);
void DrawTopMenu(CDC*pDC,CRect Rect,BOOL Selected);
virtual ~CMenuIcon();
CMenuItem m_ItemLists[MAX_MENUCOUNT];
int m_Index;
int m_IconIndex;
CImageList m_ImageList;
virtual void MeasureItem(LPMEASUREITEMSTRUCT lpStruct);
virtual void DrawItem(LPDRAWITEMSTRUCT lpStruct);
};
[/FIELDSET]
回复:在上面定义:const int MAX_MENUCOUNT = 60,ITEMHEIGHT = 26,ITEMWIDTH = 120;定义菜单项数量