# Re: Bitmap and word title in menu

Posted by JHB on June 02, 1998 at 06:10:00:

In Reply to: 用Bitmap取代Menu Item的文字项...还是要用到API posted by 彭明柳 on June 02, 1998 at 04:49:44:

Thank you for your answer.
However, I already know using modify menu. It only have the bitmap, no title.
I want the one with the title, just like the VB menu.

: : How do you add bitmaps/Icons to a menu in addition to the caption?
: : Thank you
: 您是说:
: 1.把整个menu变成bitmap?
: 2.将bitmap加到menu item旁边?(如vb的menu一样)
: 先介绍第一个好了...

: 1.在form的宣告区加入以下程式码:

: Option Explicit
: ' API函数的用途自个查哦!
: Private Declare Function GetMenu Lib "user32" (ByVal hWnd As Long) As Long
: Private Declare Function GetSubMenu Lib "user32" (ByVal hMenu As Long, ByVal nPos As Long) As Long
: Private Declare Function GetMenuItemID Lib "user32" (ByVal hMenu As Long, ByVal nPos As Long) As Long
: Private Declare Function ModifyMenu Lib "user32" Alias "ModifyMenuA" (ByVal hMenu As Long, ByVal nPosition As Long, ByVal wFlags As Long, ByVal wIDNewItem As Long, ByVal lpString As Any) As Long

: 2. 在Form上加入Menu,插入两个menu item. (第一层:mnuFile,第二层: mnuFileTest1, mnuFileTest2,随便啦!)
: 3. 在form上加入两个picturebox,Say "picBitmaps(0)"及"picBitmaps(1)",并把它的Picture属性设为您要的图案(别太大张...)
: 4. 在Form的Load Event中,加入以下程式码:

: Private Sub Form_Load()
: Dim hMenu As Long '宣告menu的handle
: Dim hSubMenu As Long 'sub menu的handle
: Dim lngID As Long
:
: hMenu = GetMenu(Me.hWnd)
: hSubMenu = GetSubMenu(hMenu, 0)

: ' 利用Image属性传回影像的代码
: picBitmaps(0).Picture = picBitmaps(0).Image
: lngID = GetMenuItemID(hSubMenu, 0)
: '瞒天过海的key point!!!
: Call ModifyMenu(hMenu, lngID, 4, lngID, CLng(picBitmaps(0).Picture))

: ' 利用Image属性传回影像的代码
: picBitmaps(1).Picture = picBitmaps(1).Image
: lngID = GetMenuItemID(hSubMenu, 1)
: Call ModifyMenu(hMenu, lngID, 4, lngID, CLng(picBitmaps(1).Picture))
: End Sub
: 5. 好啦,就是住样! Enjoy it!

Follow Ups:

- 差不多啦! 彭明柳 22:19:52 6/03/98 (0)