Click to See Complete Forum and Search --> : Menus
wasiq
Jul 28th, 2000, 05:12 AM
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.
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.
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
wasiq
Aug 3rd, 2000, 12:45 AM
I know how to do that. But the colours of the picture get inverted when the mouse is over it. How to correct that?
V(ery) Basic
Aug 3rd, 2000, 08:27 AM
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. :) ;) :p
wasiq
Aug 3rd, 2000, 12:57 PM
thanx, ;)
ck_y
Jul 23rd, 2008, 06:15 PM
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
vbforums.com
Copyright Internet.com Inc., All Rights Reserved.