Hi! I have to disable or hide minimize and restore buttons in excel system menu. But this code works correctly in excel 2003 but not in excel 2007. Excel 2007 hide only minimize button! ----------------------------------------------------------------------------------------------------------------------------------- Type MENUITEMINFO cbSize As Long fMask As Long fType As Long fState As Long wID As Long hSubMenu As Long hbmpChecked As Long hbmpUnchecked As Long dwItemData As Long dwTypeData As String cch As Long End Type
'Menu item constants. Const SC_SIZE As Long = &HF000& Const SC_MOVE As Long = &HF010& Const SC_MINIMIZE As Long = &HF020& Const SC_MAXIMIZE As Long = &HF030& Const SC_NEXTWINDOW As Long = &HF040& Const SC_PREVWINDOW As Long = &HF050& Const SC_CLOSE As Long = &HF060& Const SC_VSCROLL As Long = &HF070& Const SC_HSCROLL As Long = &HF080& Const SC_MOUSEMENU As Long = &HF090& Const SC_KEYMENU As Long = &HF100& Const SC_ARRANGE As Long = &HF110& Const SC_RESTORE As Long = &HF120& Const SC_TASKLIST As Long = &HF130& Const SC_SCREENSAVE As Long = &HF140& Const SC_HOTKEY As Long = &HF150& 'SetMenuItemInfo fState constants. Const MFS_GRAYED As Long = &H3& Const MFS_DEFAULT As Long = &H1000& 'SetMenuItemInfo fMask constants. Const MIIM_STATE As Long = &H1& Const MIIM_ID As Long = &H2& 'SendMessage constants. Const WM_NCACTIVATE As Long = &H86 'Window constants Const WS_CAPTION = &HC00000 Const WS_CHILD = &H40000000 Const WS_HSCROLL = &H100000 Const WS_VSCROLL = &H200000 Const WS_VISIBLE = &H10000000 Const WS_CLIPCHILDREN = &H2000000 Const WS_CLIPSIBLINGS = &H4000000 Const WS_BORDER = &H800000 Const WS_TABSTOP = &H10000 Const WS_POPUP = &H80000000 Const WS_SYSMENU = &H80000 Const WS_THICKFRAME = &H40000 Const WS_MINIMIZEBOX = &H20000 Const WS_MAXIMIZEBOX = &H10000 Const WS_DLGFRAME = &H400000 Private Const WS_EX_TOPMOST = &H8& Private Const WS_EX_CLIENTEDGE = &H200& Private Const WS_EX_TRANSPARENT = &H20& Const GWL_STYLE As Long = (-16) Const RDW_INVALIDATE = &H1 ' Window Styles Declare Function SetMenuItemInfo Lib "user32" Alias "SetMenuItemInfoA" (ByVal hMenu As Long, ByVal un As Long, ByVal bool As Boolean, lpcMenuItemInfo As MENUITEMINFO) As Long Declare Function GetDesktopWindow Lib "user32" () As Long 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 Declare Function GetCurrentProcessId Lib "kernel32" () As Long Declare Function GetWindowThreadProcessId Lib "user32" (ByVal hwnd As Long, ByRef lpdwProcessId As Long) As Long Declare Function GetSystemMenu Lib "user32.dll" (ByVal hwnd As Long, ByVal bRevert As Long) As Long Declare Function SendMessage Lib "user32" Alias "SendMessageA" (ByVal hwnd As Long, ByVal wMsg As Long, ByVal wParam As Long, lParam As Any) As Long Declare Function GetWindowLong Lib "user32" Alias "GetWindowLongA" (ByVal hwnd As Long, ByVal nIndex As Long) As Long Declare Function SetWindowLong Lib "user32" Alias "SetWindowLongA" (ByVal hwnd As Long, ByVal nIndex As Long, ByVal dwNewLong As Long) As Long Declare Function DrawMenuBar Lib "user32" (ByVal hwnd As Long) As Boolean Declare Function RedrawWindow Lib "user32" (ByVal hwnd As Long, lprcUpdate As RECT, ByVal hrgnUpdate As Long, ByVal fuRedraw As Long) As Long Declare Function GetWindowRect Lib "user32" (ByVal hwnd As Long, lpRect As RECT) As Long Declare Function DeleteMenu Lib "user32" (ByVal hMenu As Long, ByVal nPosition As Long, ByVal wFlags As Long) As Boolean Sub DisableAppMinimize() Dim hWndExcel As Long Dim hSysMenu As Long Dim retVal As Long Dim MI_Info As MENUITEMINFO hWndExcel = GetWindowHandle("XLMAIN", Application.Caption) hSysMenu = GetSystemMenu(hWndExcel, 0) retVal = GetWindowLong(hWndExcel, GWL_STYLE) retVal = retVal And Not (WS_MINIMIZEBOX) retVal = SetWindowLong(hWndExcel, GWL_STYLE, retVal) ' Delete context menu retVal = DeleteMenu(hSysMenu, SC_MAXIMIZE, 0) retVal = DeleteMenu(hSysMenu, SC_MINIMIZE, 0) retVal = DeleteMenu(hSysMenu, SC_RESTORE, 0) retVal = DeleteMenu(hSysMenu, SC_MOVE, 0) retVal = DeleteMenu(hSysMenu, SC_SIZE, 0) 'retVal = DeleteMenu(hSysMenu, SC_CLOSE, 0) retVal = DeleteMenu(hSysMenu, 0, &H400) DrawMenuBar (hWndExcel) retVal = SendMessage(hWndExcel, WM_NCACTIVATE, True, 0) End Sub --~--~---------~--~----~------------~-------~--~----~ ------------------------------------------------------------------------------------- Some important links for excel users: 1. Excel and VBA Tutorials(Video and Text), Free add-ins downloads at http://www.excelitems.com 2. Excel tutorials at http://www.excel-macros.blogspot.com 3. Learn VBA Macros at http://www.vbamacros.blogspot.com 4. Excel Tips and Tricks at http://exceldailytip.blogspot.com To post to this group, send email to excel-macros@googlegroups.com If you find any spam message in the group, please send an email to: Ayush Jain @ jainayus...@gmail.com or Ashish Jain @ 26may.1...@gmail.com ------------------------------------------------------------------------------------- -~----------~----~----~----~------~----~------~--~---