CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 7 of 7
  1. #1
    Join Date
    Apr 2001
    Posts
    25

    Puting Bitmap in MenuItem

    HI All,
    Please help in puting bitmap in the MenuItem, although I tried using the API ModifyMenu but it doesn't work in VB 6.0 .


  2. #2
    Join Date
    Mar 1999
    Location
    Nepal
    Posts
    540

    Re: Puting Bitmap in MenuItem

    Try using SetMenuItemBitmaps() API


    public Function AddMenuImage(pForm as Form, byval pMenuNum as Long, byval pMenuItemNum as Long, byval pImageHandle as Long) as Boolean
    Dim lngMenuHandle as Long
    Dim lngSubMenuHandle as Long
    Dim lngRet as Long

    AddMenuImage = false

    'get a handle to the form's menu
    lngMenuHandle = GetMenu(pForm.hwnd)
    If lngMenuHandle = 0 then Exit Function

    'get a handle to the top level menu using its position
    lngSubMenuHandle = GetSubMenu(lngMenuHandle, pMenuNum)
    If lngSubMenuHandle = 0 then Exit Function

    'Place the Bitmap on the menu
    lngRet = SetMenuItemBitmaps(lngSubMenuHandle, pMenuItemNum, MF_BITMAP Or MF_BYPOSITION, pImageHandle, pImageHandle)
    AddMenuImage = lngRet
    End Function






  3. #3
    Join Date
    Apr 2001
    Posts
    25

    Re: Puting Bitmap in MenuItem

    Hi Shree,
    Actually I had tried but again it is not working. Will you please describe all the parameters being passed to the function AddMenuImage. So that it will be easy for me to try it out at my end.
    Thanking you.


  4. #4
    Join Date
    Mar 1999
    Location
    Nepal
    Posts
    540

    Re: Puting Bitmap in MenuItem

    It is a working piece of code from one of my applications. Here's a particular example of my calling it:

    Call AddMenuImage(MDIMain, 0, 4, imgLMenuBmp.ListImages(3).Picture.Handle)

    In general, in

    Public Function AddMenuImage(pForm As Form, ByVal pMenuNum As Long, ByVal pMenuItemNum As Long, ByVal pImageHandle As Long) As Boolean

    the first parameter is the form containing the menu that you want to modify, pMenuNum is the top level menu number, for instance, you would have 0 for File and 1 for Edit and so on.
    The pMenuItemNum is the menu item number in the sub menu. For instance, New would have zero, and Open would have 1 and so on, in most cases.

    pImageHandle is the handle to the image you want to pue. In my application, I take the bitmap out of an ImageList. You could use Image1.Picture.Handle instead.


  5. #5
    Join Date
    Apr 2001
    Posts
    25

    Re: Puting Bitmap in MenuItem

    Hi Shree,
    "lngRet" I am geting value 0 which according to MSDN is failing the function. And also I tried to do as you directed. I think if you do not have problem then you just add me in your MSN so that we will be able to chat. my hotmail Id is [email protected]. Please help me.

    Thanking You.


  6. #6
    Join Date
    May 2000
    Location
    New York, NY, USA
    Posts
    2,878

    Re: Puting Bitmap in MenuItem

    ' API stuff for putting bitmaps in menus.
    Private Type MENUITEMINFO
    cbSize As Long
    fMask As Long
    fType As Long
    fState As Long
    wid As Long
    hSubMenu As Long
    hbmpChecked As Long
    hbmpUnchecked As Long
    dwItemData As Long
    dwTypeData As Long
    cch As Long
    End Type

    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 SetMenuItemInfo Lib "user32" Alias "SetMenuItemInfoA" (ByVal hMenu As Long, ByVal un As Long, ByVal bypos As Long, lpcMenuItemInfo As MENUITEMINFO) As Long

    Private Const MF_BITMAP = &H4&
    Private Const MFT_BITMAP = MF_BITMAP
    Private Const MIIM_TYPE = &H10

    Private Sub Form_Load()
    Dim main_menu As Long
    Dim sub_menu As Long
    Dim menu_info As MENUITEMINFO
    Dim i As Integer

    main_menu = GetMenu(hwnd)
    sub_menu = GetSubMenu(main_menu, 0)
    For i = 0 To 2
    With menu_info
    .cbSize = Len(menu_info)
    .fMask = MIIM_TYPE
    .fType = MFT_BITMAP
    .dwTypeData = picFace(i).Picture
    End With
    SetMenuItemInfo sub_menu, i, True, menu_info
    Next i
    End Sub




    Iouri Boutchkine
    [email protected]
    Iouri Boutchkine
    [email protected]

  7. #7
    Join Date
    Apr 2001
    Posts
    25

    Re: Puting Bitmap in MenuItem

    Although I am geting bitmaps in the menuitems but i am not geting caption along with it. I don't get where that caption is vanishing.

    Thanking you.


Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured