Results 1 to 6 of 6

Thread: Menus

  1. #1

    Thread Starter
    Hyperactive Member wasiq's Avatar
    Join Date
    Jan 2000
    Location
    Karachi, Sindh, Pakistan
    Posts
    274
    I am trying to make a menu which loads a directory listing into a menu and add their default icon to the menus. The problem is that i cant make it look like the menus in ms office or vb itself. Does anyone know how to make these kind of menus. Please help.

  2. #2
    Guest
    Do you mean adding bitmaps to them? Use the SetMenuItemBitmap API.

    Add a PictureBox with a bitmap loaded in it.
    Add a Menu with at least 1 SubMenu.

    Code:
    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 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
    Const MF_BITMAP = &H4&
    
    Private Sub Command1_Click()
    
        Dim hMenu As Long, hSub As Long, ItemID As Long
        hMenu = GetMenu(Me.hwnd)
        hSub = GetSubMenu(hMenu, 0)
        ItemID = GetMenuItemID(hSub, 0)
        SetMenuItemBitmaps hMenu, ItemID, MF_BITMAP, Picture1.Picture, Picture1.Picture
    
    End Sub

  3. #3

    Thread Starter
    Hyperactive Member wasiq's Avatar
    Join Date
    Jan 2000
    Location
    Karachi, Sindh, Pakistan
    Posts
    274
    I know how to do that. But the colours of the picture get inverted when the mouse is over it. How to correct that?

  4. #4
    Fanatic Member
    Join Date
    Apr 2000
    Location
    Whats a location?
    Posts
    516
    Muhahahaha.

    That's VB.

    If you want Office-like menus:

    a) Get cPopMenu (and SSubTmr.DLL) form http://www.vbaccelerator.com
    b) Make your own MF_OWNERDRAW menus (the route I took)
    c) Ask Me to send you my MF_OWNERDRAW menus stuff (might take a few days to perfect *cough*)

    The basic of MF_OWNERDRAW:

    Must used with GetMenuItem and then add this and use SetMenuitem

    Subclass WM_MEASUREITEM and CopyMemory lParam to a Variable MEASUREITEMSTRUCT. Pass this to a function which sets only itemWidth and itemHeight Parameters. Then CopyMemory the result of the function to lParam.

    Subclass WM_DRAWITEMSTRUCT and pass CopyMemory lParam to a variable DRAWITEMSTRUCT. Pass the DRAWITEMSTRUCT to a sub. This DRAWITEMSTRUCT gives you an hDC and a RECT (amongst other things) to play with.

    For Bitmaps use DrawIconEx and DrawEdge to draw the icon and the edge respectively. Add text yourself. Add Hightlight yourself. *Very satisfying*.

    Also: Do not add MF_OWNERDRAW to separators, unless you want to draw your own separators.

    Whatever you do: Menus are fun.
    Courgettes.

  5. #5

    Thread Starter
    Hyperactive Member wasiq's Avatar
    Join Date
    Jan 2000
    Location
    Karachi, Sindh, Pakistan
    Posts
    274
    thanx,

  6. #6
    New Member
    Join Date
    Feb 2006
    Posts
    9

    Re: Menus

    the setmenuitembitmap wont work on a popupmenu if the menu is not visable whats a work around for this and no i dont want to add a dll or ocx or even a user conrol to the project

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