如何在c ++ win32 API中向菜单项添加图标

时间:2012-09-30 18:11:32

标签: c++ api winapi menu icons

  

可能重复:
  InsertMenu/AppendMenu - How to add Icons to menu and submenus using C++ and win32

你好我在c ++中有一个菜单,这里是它的代码

HMENU hMenu = CreateMenu();
HMENU hFileMenu = CreatePopupMenu;
HMENU HFileOpen = CreateMenu;

AppendMenu(hFileMenu, MF_STRING, (UINT)hFileOpen, "Open");
AppendMenu(hMenu, MF_STRING | MF_POPUP, (UINT)hFileMenu, "File");

SetMenu(hwnd,hMenu);

我一直在寻找互联网,我看不到有关如何为菜单项制作位图的教程。 我想为hFileOpen添加一个位图。 我该怎么做?

2 个答案:

答案 0 :(得分:3)

答案 1 :(得分:1)

首先,您应从资源加载位图。您可以使用LoadImageLoadBitmap Win32 API函数来加载位图。

它将返回一个新的图像句柄。 然后,您可以使用此句柄通过SetMenuItemInfo函数将位图分配给菜单项。

另请参阅有关using bitmaps with menus的MSDN主题,该主题逐步描述。

相关问题