There's no HideMenu API or anything like that, but you can use RemoveItem API to remove it and then use InsertMenu API to put it back in.
In this example, I'm removing the first menu (File) from the Notepad with one button. Then with another button, I'm inserting it back again.
Good luckCode:Private Declare Function InsertMenu Lib "user32" Alias "InsertMenuA" (ByVal hMenu As Long, ByVal nPosition As Long, ByVal wFlags As Long, ByVal wIDNewItem As Long, ByVal lpNewItem As Any) 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 FindWindowEx Lib "user32" Alias "FindWindowExA" (ByVal hWnd1 As Long, ByVal hWnd2 As Long, ByVal lpsz1 As String, ByVal lpsz2 As String) As Long 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 Const MF_BYCOMMAND = &H0& Private Const MF_BYPOSITION = &H400& Private Const MF_POPUP = &H10& Private m_lSubMenu As Long Private m_lMenu As Long Private Sub cmdReInsertmenu_Click() Call InsertMenu(m_lMenu, 0, MF_BYPOSITION Or MF_POPUP, m_lSubMenu, "&File" ) End Sub Private Sub cmdRemoveMenu_Click() Dim lNotepad As Long Dim lRet As Long lNotepad = FindWindowEx(0, 0, "Notepad", vbNullString) m_lMenu = GetMenu(lNotepad) m_lSubMenu = GetSubMenu(m_lMenu, 0) lRet = RemoveMenu(m_lSubMenu, 0, MF_BYPOSITION Or MF_POPUP) lRet = RemoveMenu(m_lMenu, 0, MF_BYPOSITION) End Sub
Edited by Serge on 02-23-2000 at 07:13 PM




Reply With Quote