|
-
May 16th, 2003, 02:05 AM
#1
Thread Starter
New Member
DestroyMenu API
Ok, im not sure if this is the right API to use or not but, what I want to do is remove a menu from a another window when my application unloads.
I've tried: DestroyMenu, RemoveMenu and none of them work.
Or if it is possible, to hide the menu on the application if I cannot remove it entirely?
Thanks in advance.
-
May 16th, 2003, 11:41 PM
#2
What do you mean by it doesn't work? Do you get any errors? You must always call DrawMenuBar whenever you make changes to a menu.
Use DeleteMenu on menu's that are not attached to a Window, otherwise - memory leak. Menus attached to a Window are automatically deleted when the Window is destroyed.
Calling RemoveMenu on a menu that has a submenu does not free the memory but detaches it from the Window (so it can be used elsewhere). You must then use DeleteMenu for it to be completely destroyed.
-
May 17th, 2003, 08:58 AM
#3
Addicted Member
Why...
Why do you want to destroy a menu?
-
Mar 18th, 2004, 08:13 PM
#4
Member
Ok I was trying something in a similar manner, I was trying to remove the Minimize, Maximize, and Close buttons. However I was using MFC, but the APIs are the same, so what I'd try is using some of this stuff:
VB Code:
Private Declare Function GetSystemMenu Lib "user32" (ByVal hwnd As Long, ByVal bRevert As Long) As Long
Private Declare Function RemoveMenu Lib "user32" (ByVal hMenu As Long, ByVal nPosition As Long, ByVal wFlags As Long) As Long
Private Declare Function DrawMenuBar Lib "user32" (ByVal hwnd As Long) As Long
Private Declare Function GetMenuItemCount Lib "user32" (ByVal hMenu As Long) As Long
Private Const MF_BYPOSITION = &H400&
VB Code:
Dim my_menu As Long
Dim menu_count As Integer
Then:
VB Code:
my_menu = GetSystemMenu(Me.hwnd, False)
' or the hwnd of the other app
If my_menu Then ' if the menu was retrieved
menu_count = GetMenuItemCount(Mwin)
RemoveMenu my_menu, menu_count - 1, MF_BYPOSITION Or MF_REMOVE
DrawMenuBar (Me.hwnd) ' or the hwnd of the other app
End If
Using this approach, you would have to know the position of the menu item you want to delete. I put this code together from a number of sources, so it might not be what you need. But experiment a little bit.
Some links that deal with menus:
http://support.microsoft.com/default...b;en-us;818361
http://216.239.41.104/search?q=cache...ng_en&ie=UTF-8
I hope this contributes!
-
Apr 9th, 2004, 05:10 AM
#5
Hyperactive Member
I can't understand your problem so ... here is an example for APPEND MENU and DESTROY MENU , it works fine! Use it if it helpse you!
VB Code:
Const MF_CHECKED = &H8&
Const MF_APPEND = &H100&
Const TPM_LEFTALIGN = &H0&
Const MF_DISABLED = &H2&
Const MF_GRAYED = &H1&
Const MF_SEPARATOR = &H800&
Const MF_STRING = &H0&
Private Type POINTAPI
x As Long
y As Long
End Type
Private Declare Function CreatePopupMenu Lib "user32" () As Long
Private Declare Function TrackPopupMenu Lib "user32" (ByVal hMenu As Long, ByVal wFlags As Long, ByVal x As Long, ByVal y As Long, ByVal nReserved As Long, ByVal hwnd As Long, ByVal lprc As Any) As Long
Private Declare Function GetSystemMenu Lib "user32" (ByVal hwnd As Long, ByVal bRevert As Long) As Long
Private Declare Function AppendMenu Lib "user32" Alias "AppendMenuA" (ByVal hMenu As Long, ByVal wFlags As Long, ByVal wIDNewItem As Long, ByVal lpNewItem As Any) As Long
Private Declare Function DestroyMenu Lib "user32" (ByVal hMenu As Long) As Long
Private Declare Function GetCursorPos Lib "user32" (lpPoint As POINTAPI) As Long
Dim hMenu As Long
Private Sub Form_Load()
'KPD-Team 1998
'URL: [url]http://www.allapi.net/[/url]
'Create an empty popupmenu
hMenu = CreatePopupMenu()
'Append a few menu items
AppendMenu hMenu, MF_STRING, ByVal 0&, "Hello !"
AppendMenu hMenu, MF_GRAYED Or MF_DISABLED, ByVal 0&, "Testing ..."
AppendMenu hMenu, MF_SEPARATOR, ByVal 0&, ByVal 0&
AppendMenu hMenu, MF_CHECKED, ByVal 0&, "TrackPopupMenu"
End Sub
Private Sub Form_MouseUp(Button As Integer, Shift As Integer, x As Single, y As Single)
Dim Pt As POINTAPI
'Get the position of the mouse cursor
GetCursorPos Pt
If Button = 1 Then
'Show our popupmenu
TrackPopupMenu hMenu, TPM_LEFTALIGN, Pt.x, Pt.y, 0, Me.hwnd, ByVal 0&
Else
'Show our form's default popup menu
TrackPopupMenu GetSystemMenu(Me.hwnd, False), TPM_LEFTALIGN, Pt.x, Pt.y, 0, Me.hwnd, ByVal 0&
End If
End Sub
Private Sub Form_Unload(Cancel As Integer)
'Destroy our menu
DestroyMenu hMenu
End Sub
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|