Results 1 to 30 of 30

Thread: disable system menu

  1. #1

    Thread Starter
    Junior Member
    Join Date
    Oct 2002
    Posts
    18

    Wink disable system menu

    Hi Someone Can Help Me ???


    I want disable system menu in windows upper left corner without disable 3 controls in upper right corner

    I want click system menu and i want nothing append.
    I want continue to use close minimize and maximize control in upper right corner....

    Thanks in advance....

  2. #2

  3. #3

    Thread Starter
    Junior Member
    Join Date
    Oct 2002
    Posts
    18

    Re: disable system menu

    Hi

    Windows Menu System

    with this option :

    Restore
    Move
    Size
    Minimize
    Maximize
    Close

    Thanks

  4. #4
    Frenzied Member wiz126's Avatar
    Join Date
    Jul 2005
    Location
    Mars,Milky Way... Chit Chat Posts: 5,733
    Posts
    1,080

    Re: disable system menu

    well i am not sure if you can disable the menu form every app, or why do you wana to do this but you can remove it form your app by clicking:

    Form Properties --> BoarderStyle --> 0 - None
    4 - Fixed Toolwindow
    1) If your post has been adequately answered please click in your post on "Mark Thread Resolved".
    2) If someone has been useful to you please show your respect by rating their posts.
    3) Please use [highlight="VB"] 'your code goes in here [/highlight] tags when posting code.
    4) Before posting your question, make sure you checked this links:
    MICROSOFT MSDN -- VB FORUMS SEARCH

    5)Support Classic VB - A PETITION TO MICROSOFT

    ___________________________________________________________________________________
    THINGS TO KNOW ABOUT VB: || VB Examples/Demos
    What are Classes?
    || -
    Where to place a sub/function?(global) || Webbrowser control

  5. #5
    Fanatic Member
    Join Date
    Mar 2005
    Posts
    537

    Re: disable system menu

    If you want YOUR app to have that menu disabled then set the "ControlBox" property of your form to false.

  6. #6
    Former Admin/Moderator MartinLiss's Avatar
    Join Date
    Sep 1999
    Location
    San Jose, CA
    Posts
    33,431

    Re: disable system menu

    Quote Originally Posted by Sir Loin
    If you want YOUR app to have that menu disabled then set the "ControlBox" property of your form to false.
    But he wants to do it "without disable 3 controls in upper right corner".

  7. #7
    Frenzied Member wiz126's Avatar
    Join Date
    Jul 2005
    Location
    Mars,Milky Way... Chit Chat Posts: 5,733
    Posts
    1,080

    Re: disable system menu

    yep he wants to keep the 3 controls
    1) If your post has been adequately answered please click in your post on "Mark Thread Resolved".
    2) If someone has been useful to you please show your respect by rating their posts.
    3) Please use [highlight="VB"] 'your code goes in here [/highlight] tags when posting code.
    4) Before posting your question, make sure you checked this links:
    MICROSOFT MSDN -- VB FORUMS SEARCH

    5)Support Classic VB - A PETITION TO MICROSOFT

    ___________________________________________________________________________________
    THINGS TO KNOW ABOUT VB: || VB Examples/Demos
    What are Classes?
    || -
    Where to place a sub/function?(global) || Webbrowser control

  8. #8
    Frenzied Member wiz126's Avatar
    Join Date
    Jul 2005
    Location
    Mars,Milky Way... Chit Chat Posts: 5,733
    Posts
    1,080

    Re: disable system menu

    here is how to make your own item into the menu



    PUT THIS IN YOU APP:
    VB Code:
    1. Private Sub Command1_Click()
    2. AddToSystemMenu Me.hWnd
    3. End Sub





    PUT THIS CODE IN A MODULE:



    VB Code:
    1. Private OriginalWindowProc As Long
    2. Public Const MF_STRING = &H0&
    3. Public Const MF_ENABLED = &H0&
    4. Public Const IDM_MYMENUITEM = 2003
    5. Public Const WM_SYSCOMMAND = &H112
    6. Public Const GWL_WNDPROC = (-4)
    7.  
    8. Public Declare Function GetSystemMenu Lib "user32" (ByVal hWnd As Long, ByVal bRevert As Long) As Long
    9.  
    10. Public Declare Function AppendMenu Lib "user32" _
    11.    Alias "AppendMenuA" (ByVal hMenu As Long, _
    12.    ByVal wflags As Long, ByVal wIDNewItem As Long, _
    13.    ByVal lpNewItem As String) As Long
    14.  
    15. Public Declare Function SetWindowLong Lib "user32" _
    16.    Alias "SetWindowLongA" (ByVal hWnd As Long, _
    17.    ByVal nIndex As Long, ByVal dwNewLong As Long) As Long
    18.  
    19. Public Declare Function CallWindowProc Lib "user32" _
    20.    Alias "CallWindowProcA" (ByVal lpPrevWndFunc As Long, _
    21.    ByVal hWnd As Long, ByVal msg As Long, ByVal wParam As Long, _
    22.    ByVal lParam As Long) As Long
    23.  
    24.  
    25. Public Sub AddToSystemMenu(ByVal hWnd As Long)
    26.  
    27. Dim hSystemMenu As Long
    28.  
    29. ' Get the system menu's handle.
    30. hSystemMenu = GetSystemMenu(hWnd, False)
    31.  
    32. ' Append a custom command to the menu.
    33. AppendMenu hSystemMenu, MF_STRING + MF_ENABLED, _
    34.    IDM_MYMENUITEM, "My Menu Item"
    35.  
    36. ' Tell Windows to call MyMenuProc when a system
    37. ' menu command is selected.
    38. OriginalWindowProc = SetWindowLong(hWnd, GWL_WNDPROC, _
    39.    AddressOf MyMenuProc)
    40.  
    41. End Sub
    42.  
    43.  
    44. Public Function MyMenuProc(ByVal hWnd As Long, ByVal msg As Long, _
    45.    ByVal wParam As Long, ByVal lParam As Long) As Long
    46.  
    47. ' If the custom menu item was selected display a message.
    48. If msg = WM_SYSCOMMAND And wParam = IDM_MYMENUITEM Then
    49.    MsgBox "New menu item clicked!"
    50.    Exit Function
    51. End If
    52.  
    53. ' Otherwise pass the command on for normal processing.
    54. MyMenuProc = CallWindowProc(OriginalWindowProc, hWnd, msg, _
    55.    wParam, lParam)
    56.  
    57. End Function
    1) If your post has been adequately answered please click in your post on "Mark Thread Resolved".
    2) If someone has been useful to you please show your respect by rating their posts.
    3) Please use [highlight="VB"] 'your code goes in here [/highlight] tags when posting code.
    4) Before posting your question, make sure you checked this links:
    MICROSOFT MSDN -- VB FORUMS SEARCH

    5)Support Classic VB - A PETITION TO MICROSOFT

    ___________________________________________________________________________________
    THINGS TO KNOW ABOUT VB: || VB Examples/Demos
    What are Classes?
    || -
    Where to place a sub/function?(global) || Webbrowser control

  9. #9

    Thread Starter
    Junior Member
    Join Date
    Oct 2002
    Posts
    18

    Re: disable system menu

    is it possible to intercept mouse clic and shortcut for this menu ?????


    Thanks

  10. #10
    Frenzied Member wiz126's Avatar
    Join Date
    Jul 2005
    Location
    Mars,Milky Way... Chit Chat Posts: 5,733
    Posts
    1,080

    Re: disable system menu

    Quote Originally Posted by JP Labre
    is it possible to intercept mouse clic and shortcut for this menu ?????
    i showed you how to add another item into the menu.
    i don't understand what do you mean by "intercept mouse clic "?
    1) If your post has been adequately answered please click in your post on "Mark Thread Resolved".
    2) If someone has been useful to you please show your respect by rating their posts.
    3) Please use [highlight="VB"] 'your code goes in here [/highlight] tags when posting code.
    4) Before posting your question, make sure you checked this links:
    MICROSOFT MSDN -- VB FORUMS SEARCH

    5)Support Classic VB - A PETITION TO MICROSOFT

    ___________________________________________________________________________________
    THINGS TO KNOW ABOUT VB: || VB Examples/Demos
    What are Classes?
    || -
    Where to place a sub/function?(global) || Webbrowser control

  11. #11

  12. #12
    Former Admin/Moderator MartinLiss's Avatar
    Join Date
    Sep 1999
    Location
    San Jose, CA
    Posts
    33,431

    Re: disable system menu

    This will remove everything but Close from the system menu. If you uncomment the line for menu 6 it also disables the X. You could put an exit button on the form and exit that way.

    VB Code:
    1. Private Declare Function RemoveMenu Lib "user32" (ByVal hMenu As Long, ByVal nPosition As Long, ByVal wFlags As Long) As Long
    2. Private Const MF_BYPOSITION = &H400&
    3. Private Const MF_REMOVE = &H1000&
    4.  
    5. Private Sub Form_Load()
    6.     Dim hSysMenu As Long, nCnt As Long
    7.     ' Get handle to our form's system menu
    8.     ' (Restore, Maximize, Move, close etc.)
    9.     hSysMenu = GetSystemMenu(Me.hwnd, False)
    10.  
    11.     If hSysMenu Then
    12.         ' Get System menu's menu count
    13.         nCnt = GetMenuItemCount(hSysMenu)
    14.         If nCnt Then
    15.             RemoveMenu hSysMenu, 7, MF_BYPOSITION Or MF_REMOVE
    16.             'RemoveMenu hSysMenu, 6, MF_BYPOSITION Or MF_REMOVE
    17.             RemoveMenu hSysMenu, 5, MF_BYPOSITION Or MF_REMOVE
    18.             RemoveMenu hSysMenu, 4, MF_BYPOSITION Or MF_REMOVE
    19.             RemoveMenu hSysMenu, 3, MF_BYPOSITION Or MF_REMOVE
    20.             RemoveMenu hSysMenu, 2, MF_BYPOSITION Or MF_REMOVE
    21.             RemoveMenu hSysMenu, 1, MF_BYPOSITION Or MF_REMOVE
    22.             RemoveMenu hSysMenu, 0, MF_BYPOSITION Or MF_REMOVE
    23.  
    24.             DrawMenuBar Me.hwnd
    25.         End If
    26.     End If
    27. End Sub

  13. #13

    Thread Starter
    Junior Member
    Join Date
    Oct 2002
    Posts
    18

    Re: disable system menu

    I want if user click system menu, nothing append....

  14. #14
    Frenzied Member wiz126's Avatar
    Join Date
    Jul 2005
    Location
    Mars,Milky Way... Chit Chat Posts: 5,733
    Posts
    1,080

    Re: disable system menu

    Quote Originally Posted by JP Labre
    I want if user click system menu, nothing append....

    you wana to complitly remove the system defult mune for the app without removing the 3 command buttons? is it even posible?
    1) If your post has been adequately answered please click in your post on "Mark Thread Resolved".
    2) If someone has been useful to you please show your respect by rating their posts.
    3) Please use [highlight="VB"] 'your code goes in here [/highlight] tags when posting code.
    4) Before posting your question, make sure you checked this links:
    MICROSOFT MSDN -- VB FORUMS SEARCH

    5)Support Classic VB - A PETITION TO MICROSOFT

    ___________________________________________________________________________________
    THINGS TO KNOW ABOUT VB: || VB Examples/Demos
    What are Classes?
    || -
    Where to place a sub/function?(global) || Webbrowser control

  15. #15
    Super Moderator manavo11's Avatar
    Join Date
    Nov 2002
    Location
    Around the corner from si_the_geek
    Posts
    7,171

    Re: disable system menu

    Quote Originally Posted by wiz126
    is it even posible?
    Kind of

    If you subclass you can catch these messages like this :

    VB Code:
    1. Case WM_CONTEXTMENU
    2.             Exit Function
    3.         Case WM_SYSCOMMAND
    4.             If (wParam) = 61587 Then
    5.                 Exit Function
    6.             End If

    and the menu won't appear if you left or right click on the image in the top left. However, if you click on the taskbar on the app, you will get the system menu...

    Full code :

    VB Code:
    1. 'form code
    2.  
    3. Option Explicit
    4.  
    5. Private Sub Form_Load()
    6.     Hook Me.hWnd
    7. End Sub
    8.  
    9. Private Sub Form_Unload(Cancel As Integer)
    10.     UnHook
    11. End Sub


    VB Code:
    1. 'Module code
    2.  
    3. Declare Function CallWindowProc Lib "user32" Alias "CallWindowProcA" _
    4.                                        (ByVal lpPrevWndFunc As Long, _
    5.                                                  ByVal hWnd As Long, _
    6.                                                   ByVal Msg As Long, _
    7.                                                ByVal wParam As Long, _
    8.                                          ByVal lParam As Long) As Long
    9.  
    10. Declare Function SetWindowLong Lib "user32" _
    11.                      Alias "SetWindowLongA" _
    12.                        (ByVal hWnd As Long, _
    13.                       ByVal nIndex As Long, _
    14.              ByVal dwNewLong As Long) As Long
    15.  
    16. Public Const GWL_WNDPROC = -4
    17. Public Const WM_CONTEXTMENU As Long = &H7B
    18. Const WM_SYSCOMMAND As Long = &H112
    19.  
    20. Public lpPrevWndProc As Long
    21. Private lnghWnd As Long
    22.  
    23. Public Sub Hook(hWnd As Long)
    24.     lnghWnd = hWnd
    25.     lpPrevWndProc = SetWindowLong(lnghWnd, GWL_WNDPROC, AddressOf WindowProc)
    26. End Sub
    27.  
    28. Public Sub UnHook()
    29.     Dim lngReturnValue As Long
    30.     lngReturnValue = SetWindowLong(lnghWnd, GWL_WNDPROC, lpPrevWndProc)
    31. End Sub
    32.  
    33. Function WindowProc(ByVal hw As Long, _
    34.                     ByVal uMsg As Long, _
    35.                     ByVal wParam As Long, _
    36.                     ByVal lParam As Long) As Long
    37.  
    38.     Select Case uMsg
    39.         Case WM_CONTEXTMENU
    40.             Exit Function
    41.         Case WM_SYSCOMMAND
    42.             If (wParam) = 61587 Then
    43.                 Exit Function
    44.             End If
    45.         Case WM_DESTROY
    46.             UnHook
    47.     End Select
    48.    
    49.     WindowProc = CallWindowProc(lpPrevWndProc, lnghWnd, uMsg, wParam, lParam)
    50. End Function


    Has someone helped you? Then you can Rate their helpful post.

  16. #16

    Thread Starter
    Junior Member
    Join Date
    Oct 2002
    Posts
    18

    Re: disable system menu

    Thanks manavo11



    Your response is 95% good the user can always double click system menu


    Thanks!

  17. #17
    Super Moderator manavo11's Avatar
    Join Date
    Nov 2002
    Location
    Around the corner from si_the_geek
    Posts
    7,171

    Re: disable system menu

    What do you mean by :

    the user can always double click system menu
    Double clicking the icon closes the window...


    Has someone helped you? Then you can Rate their helpful post.

  18. #18
    Frenzied Member wiz126's Avatar
    Join Date
    Jul 2005
    Location
    Mars,Milky Way... Chit Chat Posts: 5,733
    Posts
    1,080

    Re: disable system menu

    is it posible to complitly remove the menu?
    1) If your post has been adequately answered please click in your post on "Mark Thread Resolved".
    2) If someone has been useful to you please show your respect by rating their posts.
    3) Please use [highlight="VB"] 'your code goes in here [/highlight] tags when posting code.
    4) Before posting your question, make sure you checked this links:
    MICROSOFT MSDN -- VB FORUMS SEARCH

    5)Support Classic VB - A PETITION TO MICROSOFT

    ___________________________________________________________________________________
    THINGS TO KNOW ABOUT VB: || VB Examples/Demos
    What are Classes?
    || -
    Where to place a sub/function?(global) || Webbrowser control

  19. #19
    Super Moderator manavo11's Avatar
    Join Date
    Nov 2002
    Location
    Around the corner from si_the_geek
    Posts
    7,171

    Re: disable system menu

    And keep the control box? Probably not, at least not without more hooking so avoid the menu popping up with you right click in the taskbar area...


    Has someone helped you? Then you can Rate their helpful post.

  20. #20

    Thread Starter
    Junior Member
    Join Date
    Oct 2002
    Posts
    18

    Smile Re: disable system menu

    hi manavo11


    if I double click the system menu the window close and i don't want that



    Thanks

  21. #21
    Super Moderator manavo11's Avatar
    Join Date
    Nov 2002
    Location
    Around the corner from si_the_geek
    Posts
    7,171

    Re: disable system menu

    Add this in the declarations :

    VB Code:
    1. Const WM_NCLBUTTONDBLCLK As Long = &HA3

    and change the select case statement to this :

    VB Code:
    1. Select Case uMsg
    2.         Case WM_CONTEXTMENU
    3.             Exit Function
    4.         Case WM_NCLBUTTONDBLCLK
    5.             Exit Function
    6.         Case WM_SYSCOMMAND
    7.             If (wParam) = 61587 Then
    8.                 Exit Function
    9.             End If
    10.         Case WM_DESTROY
    11.             UnHook
    12.     End Select


    Has someone helped you? Then you can Rate their helpful post.

  22. #22

    Thread Starter
    Junior Member
    Join Date
    Oct 2002
    Posts
    18

    Re: disable system menu

    It's works great


    Thanks


    JP

  23. #23
    Super Moderator manavo11's Avatar
    Join Date
    Nov 2002
    Location
    Around the corner from si_the_geek
    Posts
    7,171

    Re: disable system menu

    You're welcome


    Has someone helped you? Then you can Rate their helpful post.

  24. #24

  25. #25
    Super Moderator manavo11's Avatar
    Join Date
    Nov 2002
    Location
    Around the corner from si_the_geek
    Posts
    7,171

    Re: disable system menu

    Thanks RhinoBull

    I would like to see that, see if it's less trouble then the subclassing... Does it look the same (exactly? kind of?)


    Has someone helped you? Then you can Rate their helpful post.

  26. #26
    PowerPoster RhinoBull's Avatar
    Join Date
    Mar 2004
    Location
    New Amsterdam
    Posts
    24,132

    Re: disable system menu

    OK, as promissed here is a sample project. You can customize as you wish but KIM that it's only a sample. Enjoy it.

    NOTE: couldn't find my original so this si a very "freshly made" copy (did it in the past hour).
    Attached Files Attached Files

  27. #27
    Super Moderator manavo11's Avatar
    Join Date
    Nov 2002
    Location
    Around the corner from si_the_geek
    Posts
    7,171

    Re: disable system menu

    That's pretty nice RB There are a few issues (maximizing/covering taskbar, double clicking titlebar) but it's still pretty cool Even got the gradient!


    Has someone helped you? Then you can Rate their helpful post.

  28. #28

  29. #29
    Super Moderator manavo11's Avatar
    Join Date
    Nov 2002
    Location
    Around the corner from si_the_geek
    Posts
    7,171

    Re: disable system menu

    For 1 hour that's pretty impressive 1 "problem" is that you lose the XP style visual style, not that it's that important


    Has someone helped you? Then you can Rate their helpful post.

  30. #30

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