Dim hMenu As Long, Success As Long
hMenu = GetSystemMenu(Application.hWndAccessApp, 0)
'禁止還原按鈕
Success = DeleteMenu(hMenu, SC_RESTORE, MF_BYCOMMAND)
'禁止改變大小
Success = DeleteMenu(hMenu, SC_SIZE, MF_BYCOMMAND)
'禁止最大化
Success = DeleteMenu(hMenu, SC_MAXIMIZE, MF_BYCOMMAND)
'禁止最小化
Success = DeleteMenu(hMenu, SC_MINIMIZE, MF_BYCOMMAND)
'禁止關閉
Success = DeleteMenu(hMenu, SC_CLOSE, MF_BYCOMMAND)
'禁止移動
Success = DeleteMenu(hMenu, SC_MOVE, MF_BYCOMMAND)
Public Const WM_SYSCOMMAND = &H112
Public Const SC_CLOSE = &HF060& '關閉窗體
Public Const SC_MINIMIZE = &HF020& '最小化窗體
Public Const SC_MAXIMIZE = &HF030& '最大化窗體
Public Const SC_RESTORE = &HF120& '恢復窗體大小
Public Const WM_SETTEXT = &HC '設置窗體的Caption
Public Const WM_GETTEXT = &HD '取得窗體的caption
Declare Function SendMessage Lib "user32" Alias "SendMessageA" (ByVal hwnd As Long, _
ByVal wMsg As Long, ByVal wParam As Long, lParam As Any) As Long
'以上放入聲明段
Private Sub Command_Click(Index As Integer)
Dim S As String
S = String(80, Chr(0))
Select Case Index
Case 0
SendMessage Application.hWndAccessApp, WM_GETTEXT, Len(S), ByVal S '讀出窗體的Caption
'在用戶自己的窗體中加一個文本框,用於操作Access主窗體標題
Text1.Text = Left(S, InStr(S, Chr(0)) - 1)
Case 1
'因為Text1.text屬於Variant類型,所以一定先要用CStr把它轉換成字符串
SendMessage Application.hWndAccessApp, WM_SETTEXT, 0, ByVal CStr(Text1.Text) '設置窗體的Caption
Case 2
SendMessage Application.hWndAccessApp, WM_SYSCOMMAND, SC_MAXIMIZE, ByVal 0&'使窗體最大化
Case 3
SendMessage Application.hWndAccessApp, WM_SYSCOMMAND, SC_MINIMIZE, ByVal 0&'使窗體最小化
Case 4
SendMessage Application.hWndAccessApp, WM_SYSCOMMAND, SC_RESTORE, ByVal 0&'使窗體恢復原來的大小
Case 5
SendMessage Application.hWndAccessApp, WM_SYSCOMMAND, SC_CLOSE, ByVal 0&'關閉窗體
End Select
End Sub