Results 1 to 7 of 7

Thread: How can you disable the system menu?

  1. #1

    Thread Starter
    Frenzied Member
    Join Date
    Dec 2000
    Posts
    1,195

    How can you disable the system menu?

    from showing up, or editing it? anyone know?

  2. #2
    Frenzied Member CyberCarsten's Avatar
    Join Date
    Sep 1999
    Location
    Aalborg Ø, Denmark
    Posts
    1,544
    What do you mean by System Menu??
    razor
    Software Engineer Student, Aalborg University, Denmark
    http://www.cs.auc.dk

    My email at AUC: will get a new email soon
    My website: http://www.razorsoftware.net


    Windows XP Pro/ Gentoo Linux (Laptop)
    Windows XP Pro (Home PC)

  3. #3
    AIS_DK
    Guest
    You need to subclass your form, and detect the message WM_SYSCOMMAND.

  4. #4
    Frenzied Member CyberCarsten's Avatar
    Join Date
    Sep 1999
    Location
    Aalborg Ø, Denmark
    Posts
    1,544
    To subclass the system menu, look here http://www.vbsquare.com/articles/sysmenu/
    razor
    Software Engineer Student, Aalborg University, Denmark
    http://www.cs.auc.dk

    My email at AUC: will get a new email soon
    My website: http://www.razorsoftware.net


    Windows XP Pro/ Gentoo Linux (Laptop)
    Windows XP Pro (Home PC)

  5. #5
    Junior Member
    Join Date
    May 2001
    Posts
    18
    please try the following:

    'in form
    Private Sub Form_Load()
    OldWindowProc = GetWindowLong(Form1.hwnd, GWL_WNDPROC)
    ' get the function address of the main window
    Call SetWindowLong(Form1.hwnd, GWL_WNDPROC, AddressOf SubClass1_WndMessage)
    SysMenuHwnd = GetSystemMenu(Form1.hwnd, False)
    Call AppendMenu(SysMenuHwnd, MF_SEPARATOR, 2000, vbNullString)
    Call AppendMenu(SysMenuHwnd, MF_STRING, 2001, "About(&A)")
    Call AppendMenu(SysMenuHwnd, MF_SEPARATOR, 2002, vbNullString)
    Call AppendMenu(SysMenuHwnd, MF_STRING, 2003, "restore(&R)")
    End Sub
    Private Sub Form_Unload(Cancel As Integer)
    If OldWindowProc <> GetWindowLong(Form1.hwnd, GWL_WNDPROC) Then
    Call SetWindowLong(Form1.hwnd, GWL_WNDPROC, OldWindowProc)
    End If
    End Sub
    Private Sub Label3_Click()
    Call ShellExecute(Form1.hwnd, "open", "http://www.iCodeRepository.com", vbNullString, vbNullString, &H0)
    End Sub
    'in bas
    ' Public Declare Function GetWindowLong Lib "user32" Alias "GetWindowLongA" (ByVal hwnd As Long, ByVal nIndex As Long) As Long
    Public Declare Function SetWindowLong Lib "user32" Alias "SetWindowLongA" (ByVal hwnd As Long, ByVal nIndex As Long, ByVal dwNewLong As Long) As Long
    Public Declare Function CallWindowProc Lib "user32" Alias "CallWindowProcA" (ByVal lpPrevWndFunc As Long, ByVal hwnd As Long, ByVal Msg As Long, ByVal wParam As Long, ByVal lParam As Long) As Long
    Public Declare Function GetSystemMenu Lib "user32" (ByVal hwnd As Long, ByVal bRevert As Long) As Long
    Public 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
    Public Declare Function ShellExecute Lib "shell32.dll" Alias "ShellExecuteA" (ByVal hwnd As Long, ByVal lpOperation As String, ByVal lpFile As String, ByVal lpParameters As String, ByVal lpDirectory As String, ByVal nShowCmd As Long) As Long

    Public Const WM_SYSCOMMAND = &H112
    Public Const MF_SEPARATOR = &H800&
    Public Const MF_STRING = &H0&
    Public Const GWL_WNDPROC = (-4)
    Public OldWindowProc As Long
    Public SysMenuHwnd As Long
    Public Function SubClass1_WndMessage(ByVal hwnd As Long, ByVal Msg As Long, ByVal wp As Long, ByVal lp As Long) As Long
    If Msg <> WM_SYSCOMMAND Then
    SubClass1_WndMessage = CallWindowProc(OldWindowProc, hwnd, Msg, wp, lp)
    Exit Function
    End If
    Select Case wp
    Case 2001
    Call MsgBox("modify ", vbOKOnly + vbInformation)
    Case 2003
    Call GetSystemMenu(Form1.hwnd, True)
    Call SetWindowLong(Form1.hwnd, GWL_WNDPROC, OldWindowProc)
    Call MsgBox("restore the sys menu ", vbOKOnly + vbInformation)
    Case Else
    SubClass1_WndMessage = CallWindowProc(OldWindowProc, hwnd, Msg, wp, lp)
    Exit Function
    End Select
    SubClass1_WndMessage = True
    End Function


    for a good tool to programmers,
    please visit: http://www.iCodeRepository.com

  6. #6
    Megatron
    Guest
    Add to a Module.
    Code:
    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)
    Declare Function CallWindowProc Lib "user32" Alias "CallWindowProcA" (ByVal lpPrevWndFunc As Long, ByVal hwnd As Long, ByVal msg As Long, ByVal wParam As Long, ByVal lParam As Long) As Long
    Const GWL_WNDPROC = (-4)
    Private Const WM_SYSCOMMAND = &H112
    
    Global WndProcOld As Long
    
    Public Function WindProc(ByVal hwnd As Long, ByVal wMsg As Long, ByVal wParam As Long, ByVal lParam As Long) As Long
        If wMsg = WM_SYSCOMMAND Then Exit Function
        WindProc = CallWindowProc(WndProcOld&, hwnd&, wMsg&, wParam&, lParam&)
    End Function
    
    Sub SubClassWnd(hwnd As Long)
        WndProcOld& = SetWindowLong(hwnd, GWL_WNDPROC, AddressOf WindProc)
    End Sub
    
    Sub UnSubclassWnd(hwnd As Long)
        SetWindowLong hwnd, GWL_WNDPROC, WndProcOld&
        WndProcOld& = 0
    End Sub
    Add to a Form with a CommandButton call cmdQuit.
    Code:
    Private Sub cmdQuit_Click()
        Unload Me
    End Sub
    
    Private Sub Form_Load()
        SubClassWnd hwnd
    End Sub
    
    Private Sub Form_Unload(Cancel As Integer)
        UnSubclassWnd hwnd
    End Sub
    The reason we have a button for quitting is because since we disabled the System Menu commands, the X in the corner will no longer work.

  7. #7

    Thread Starter
    Frenzied Member
    Join Date
    Dec 2000
    Posts
    1,195
    thanks, so its not possible to just remove the system menu? I need the X on the form

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