|
-
May 5th, 2001, 08:34 PM
#1
Thread Starter
Frenzied Member
How can you disable the system menu?
from showing up, or editing it? anyone know?
-
May 6th, 2001, 08:11 AM
#2
Frenzied Member
What do you mean by System Menu??
-
May 6th, 2001, 08:14 AM
#3
You need to subclass your form, and detect the message WM_SYSCOMMAND.
-
May 6th, 2001, 08:20 AM
#4
Frenzied Member
-
May 6th, 2001, 10:56 AM
#5
Junior Member
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
-
May 6th, 2001, 11:11 AM
#6
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.
-
May 6th, 2001, 12:01 PM
#7
Thread Starter
Frenzied Member
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
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|