Results 1 to 7 of 7

Thread: Problem With Menu Bitmaps

  1. #1
    assbeef
    Guest

    Problem With Menu Bitmaps

    I used the following code to put bitmaps in my popupmenu:

    Declare Function GetMenu Lib "user32" _
    (ByVal hwnd As Long) As Long

    Declare Function GetSubMenu Lib "user32" _
    (ByVal hMenu As Long, ByVal nPos As Long) As Long

    Declare Function GetMenuItemID Lib "user32" _
    (ByVal hMenu As Long, ByVal nPos As Long) As Long

    Declare Function SetMenuItemBitmaps Lib "user32" _
    (ByVal hMenu As Long, ByVal nPosition As Long, _
    ByVal wFlags As Long, ByVal hBitmapUnchecked As Long, _
    ByVal hBitmapChecked As Long) As Long

    Public Const MF_BITMAP = &H4&

    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 String
    cch As Long
    End Type

    Declare Function GetMenuItemCount Lib "user32" _
    (ByVal hMenu As Long) As Long

    Declare Function GetMenuItemInfo Lib "user32" _
    Alias "GetMenuItemInfoA" (ByVal hMenu As Long, _
    ByVal un As Long, ByVal b As Boolean, _
    lpMenuItemInfo As MENUITEMINFO) As Boolean

    Public Const MIIM_ID = &H2
    Public Const MIIM_TYPE = &H10
    Public Const MFT_STRING = &H0&

    Public Sub SetMenuIcon(frmForm As Form, mnuIndex As Integer, mnuPos As Integer, picChecked As PictureBox, picUnchecked As PictureBox)
    Dim hMenu As Long
    Dim hSubMenu As Long
    Dim hID As Long

    'Get the menuhandle of your app
    hMenu& = GetMenu(frmForm.hWnd)

    'Get the handle of the first submenu (Hello)
    hSubMenu& = GetSubMenu(hMenu&, mnuIndex)

    'Get the menuId of the first entry (Bitmap)
    hID& = GetMenuItemID(hSubMenu&, mnuPos)

    'Add the bitmap

    SetMenuItemBitmaps hMenu&, hID&, MF_BITMAP, _
    picUnchecked.Picture, _
    picChecked.Picture
    'You can add two bitmaps to a menuentry
    'One for the checked and one for the unchecked
    'state.
    End Sub

    frmForm is the form to edit, mnuIndex is what menu to edit, mnuIndex is the index of that menu you want to add the bitmap to. It works great, except when it gets to an index where there is a sub menu. It seems to stop working all together when it tries to add a bitmap to a submenu index. Is there a way to fix this?


  2. #2
    assbeef
    Guest
    Ok, this is getting me nowhere fast... Can someone please suggest another method of adding Icons to a menu that will actually work properly? Someone?

  3. #3
    New Member
    Join Date
    Sep 2001
    Posts
    8

    Re: Problem With Menu Bitmaps

    I'm not sure you can add bitmaps to a menu index that has a submenu. I've tried the subclassing method on the menu, but it still doesn't work.
    "I wanna stay likkle and eat pudden all day"

  4. #4
    DaoK
    Guest
    You can add image to a sub in a menu this is the prove:


    Attached Images Attached Images  

  5. #5
    DaoK
    Guest
    Have you found the code ? Maybe in planetsourcecode.com they have some snipplet.

  6. #6
    New Member
    Join Date
    Sep 2001
    Posts
    8
    Uh DaoK,
    In your example, I think assbeef would want to put a bitmap on the "Image" menu, not the Image menu's submenu items.
    "I wanna stay likkle and eat pudden all day"

  7. #7
    DaoK
    Guest
    I dont think is possible.

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