windows api 动态修改菜单项语言
上次的windows程序设计要求这么做了。搞了好久才搞定。
void setLanguage(HINSTANCE hInstance, HMENU hMenu,int langue)//简单的写了一个函数,传递实例句柄、菜单句柄(整个菜单句柄)、语言编号,对资源文件中的字符串资源id相对应,比如中文id是cnid,英文是cnid+1,日文是cnid+2,对应的langue值就是0/1/2 { int nMenuItemCnt=GetMenuItemCount(hMenu);//获取菜单项数量 WCHAR szBuffer[30]; int startMenuStringId=FileCN,startMenuID=EXIT; for (int i = 0; i < nMenuItemCnt; i++) { HMENU subMenu= GetSubMenu(hMenu,i); int subMenuSize=GetMenuItemCount(subMenu); LoadString(hInstance,startMenuStringId+langue,szBuffer,30);//根据语言读取字符串资源 ModifyMenu(hMenu,i,MF_BYPOSITION,i,szBuffer);//修改菜单 startMenuStringId+=2; for(int j=0;j<subMenuSize;j++)//修改子菜单 { LoadString(hInstance,startMenuStringId+langue,szBuffer,30); startMenuStringId+=2; ModifyMenu(subMenu,startMenuID,MF_BYCOMMAND,startMenuID,szBuffer); startMenuID++; } } }