Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Disable task bar right click menu.

Status
Not open for further replies.

DRH192

Programmer
Apr 25, 2005
96
GB
All,

I have an access db which I want to remove the right click menu, or at least disable the close option it provides, from the task bar.

I need to do this to stop users right clicking the app on the tasbar and selecting close as this will bypass a close event on my form.

Any help much appreciated,

Cheers
 
I had a similar problem with Excel but I needed to disable the app minimize button on the taskbar. Here is the code I found for the minimize button. It should give you a start in the right direction...

Code:
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_MINIMIZE As Long = &HF020&
Const xSC_MINIMIZE As Long = -10

'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_MINIMIZEBOX As Long = &H20000
Const WS_MAXIMIZEBOX As Long = &H10000
Const GWL_STYLE As Long = (-16)



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


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)
         
   With MI_Info
     .cbSize = Len(MI_Info)
     .fState = MFS_GRAYED
     .wID = xSC_MINIMIZE
     .fMask = MIIM_ID Or MIIM_STATE
   End With
   retVal = SetMenuItemInfo(hSysMenu, SC_MINIMIZE, False, MI_Info)

   retVal = GetWindowLong(hWndExcel, GWL_STYLE)
   retVal = retVal And Not (WS_MINIMIZEBOX)
   retVal = SetWindowLong(hWndExcel, GWL_STYLE, retVal)
   
   retVal = SendMessage(hWndExcel, WM_NCACTIVATE, True, 0)
   
End Sub


Sub EnableAppMinimize()
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)
         
   With MI_Info
     .cbSize = Len(MI_Info)
     .fState = MFS_DEFAULT
     .wID = SC_MINIMIZE
     .fMask = MIIM_ID Or MIIM_STATE
   End With
   retVal = SetMenuItemInfo(hSysMenu, xSC_MINIMIZE, False, MI_Info)

   retVal = GetWindowLong(hWndExcel, GWL_STYLE)
   retVal = SetWindowLong(hWndExcel, GWL_STYLE, WS_MINIMIZEBOX Or retVal)
      
   retVal = SendMessage(hWndExcel, WM_NCACTIVATE, True, 0)
      
End Sub


Function GetWindowHandle(Optional ByVal sClass As String = vbNullString, Optional ByVal sCaption As String = vbNullString)
Dim hWndDesktop As Long
Dim hwnd As Long
Dim hProcThisInstance As Long
Dim hProcWindow As Long

   hWndDesktop = GetDesktopWindow
   hProcThisInstance = GetCurrentProcessId
   Do
     hwnd = FindWindowEx(hWndDesktop, hwnd, sClass, sCaption)
     GetWindowThreadProcessId hwnd, hProcWindow
   Loop Until hProcWindow = hProcThisInstance Or hwnd = 0
   GetWindowHandle = hwnd

End Function
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top