Results 1 to 5 of 5

Thread: DestroyMenu API

  1. #1

    Thread Starter
    New Member
    Join Date
    Nov 2002
    Posts
    8

    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.
    The Itch :]

  2. #2
    PowerPoster
    Join Date
    Oct 2002
    Location
    British Columbia
    Posts
    9,758
    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.

  3. #3
    Addicted Member CodeRonin's Avatar
    Join Date
    Jul 2002
    Location
    Vienna, Austria
    Posts
    233

    Why...

    Why do you want to destroy a menu?
    Code Ronin

  4. #4
    Member
    Join Date
    Mar 2004
    Location
    Texas
    Posts
    53
    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:
    1. Private Declare Function GetSystemMenu Lib "user32" (ByVal hwnd As Long, ByVal bRevert As Long) As Long
    2. Private Declare Function RemoveMenu Lib "user32" (ByVal hMenu As Long, ByVal nPosition As Long, ByVal wFlags As Long) As Long
    3. Private Declare Function DrawMenuBar Lib "user32" (ByVal hwnd As Long) As Long
    4. Private Declare Function GetMenuItemCount Lib "user32" (ByVal hMenu As Long) As Long
    5. Private Const MF_BYPOSITION = &H400&

    VB Code:
    1. Dim my_menu As Long
    2. Dim menu_count As Integer

    Then:

    VB Code:
    1. my_menu = GetSystemMenu(Me.hwnd, False)
    2. ' or the hwnd of the other app
    3.  
    4. If my_menu Then ' if the menu was retrieved
    5.     menu_count = GetMenuItemCount(Mwin)
    6.         RemoveMenu my_menu, menu_count - 1, MF_BYPOSITION Or MF_REMOVE
    7.     DrawMenuBar (Me.hwnd) ' or the hwnd of the other app
    8. 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!

  5. #5
    Hyperactive Member DarkX_Greece's Avatar
    Join Date
    Jan 2004
    Location
    Athens (Greece)
    Posts
    315
    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:
    1. Const MF_CHECKED = &H8&
    2. Const MF_APPEND = &H100&
    3. Const TPM_LEFTALIGN = &H0&
    4. Const MF_DISABLED = &H2&
    5. Const MF_GRAYED = &H1&
    6. Const MF_SEPARATOR = &H800&
    7. Const MF_STRING = &H0&
    8. Private Type POINTAPI
    9.     x As Long
    10.     y As Long
    11. End Type
    12. Private Declare Function CreatePopupMenu Lib "user32" () As Long
    13. 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
    14. Private Declare Function GetSystemMenu Lib "user32" (ByVal hwnd As Long, ByVal bRevert As Long) As Long
    15. 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
    16. Private Declare Function DestroyMenu Lib "user32" (ByVal hMenu As Long) As Long
    17. Private Declare Function GetCursorPos Lib "user32" (lpPoint As POINTAPI) As Long
    18. Dim hMenu As Long
    19. Private Sub Form_Load()
    20.     'KPD-Team 1998
    21.     'URL: [url]http://www.allapi.net/[/url]
    22.     'E-Mail: [email][email protected][/email]
    23.     'Create an empty popupmenu
    24.     hMenu = CreatePopupMenu()
    25.     'Append a few menu items
    26.     AppendMenu hMenu, MF_STRING, ByVal 0&, "Hello !"
    27.     AppendMenu hMenu, MF_GRAYED Or MF_DISABLED, ByVal 0&, "Testing ..."
    28.     AppendMenu hMenu, MF_SEPARATOR, ByVal 0&, ByVal 0&
    29.     AppendMenu hMenu, MF_CHECKED, ByVal 0&, "TrackPopupMenu"
    30. End Sub
    31. Private Sub Form_MouseUp(Button As Integer, Shift As Integer, x As Single, y As Single)
    32.     Dim Pt As POINTAPI
    33.     'Get the position of the mouse cursor
    34.     GetCursorPos Pt
    35.     If Button = 1 Then
    36.         'Show our popupmenu
    37.         TrackPopupMenu hMenu, TPM_LEFTALIGN, Pt.x, Pt.y, 0, Me.hwnd, ByVal 0&
    38.     Else
    39.         'Show our form's default popup menu
    40.         TrackPopupMenu GetSystemMenu(Me.hwnd, False), TPM_LEFTALIGN, Pt.x, Pt.y, 0, Me.hwnd, ByVal 0&
    41.     End If
    42. End Sub
    43. Private Sub Form_Unload(Cancel As Integer)
    44.     'Destroy our menu
    45.     DestroyMenu hMenu
    46. End Sub
    Short CV:
    1. Visual Basic 6 Programmer
    2. Web Expert


    Botonakis Web Services

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