'定义常数 Public Const IDM_ABOUT = &H2000 Public Const IDM_UNITS = &H2001 Public Const IDM_RESET = &H2002 Public Const IDM_EXIT = &H2003 Public Const IDM_TEST = &H2005 '添加菜单 Dim hSysMenu As Long ' Get handle of system menu hSysMenu = GetSystemMenu(Me.hwnd, 0) ' Append separator and menu item with ID IDM_ABOUT Call AppendMenu(hSysMenu, MF_SEPARATOR, 0&, 0&) Call AppendMenu(hSysMenu, MF_STRING, IDM_ABOUT, "About...") Call AppendMenu(hSysMenu, MF_STRING, IDM_UNITS, "Units...") Call AppendMenu(hSysMenu, MF_STRING, IDM_RESET, "Reset...") Call AppendMenu(hSysMenu, MF_STRING, IDM_EXIT, "Exit") '改变窗体的处理函数 hwnd = Me.hwnd ' Install system menu window procedure procOld = SetWindowLong(ByVal hwnd, GWL_WNDPROC, AddressOf WindowsProc) '获取消息 Public Function WindowsProc(ByVal hwnd As Long, ByVal uMsg As Long, _ ByVal wParam As Long, ByVal lParam As Long) As Long ' Ignore everything but system commands If uMsg = WM_SYSCOMMAND Then ' ' Check for one special menu item ' WindowsProc = CallWindowProc(procOld, hwnd, uMsg, wParam, lParam) Debug.Print uMsg, wParam, lParam Select Case wParam Case IDM_ABOUT ' FrmAbout.Show ' Exit Function Case IDM_UNITS ' FrmUnits.Show ' Exit Function Case IDM_RESET ' FrmMain.TmrSys.Enabled = False ' Dim Response ' Response = MsgBox("Do you want to reset your Mouse Tracker to zero? " & Chr(13) & "Your current mileage reading will lost forever.", vbOKCancel + vbExclamation, "Reset Mouse Tracker") If Response = vbOK Then Distance = 0 'reset to zero GetCursorPos Pnt OldX = Pnt.x * Screen.TwipsPerPixelX OldY = Pnt.y * Screen.TwipsPerPixelY FrmMain.Caption = Format(Distance / UnitValue, FormatStr) & UnitName FrmMain.TmrSys.Enabled = True Else: FrmMain.TmrSys.Enabled = True End If Exit Function Case IDM_EXIT Unload FrmMain Exit Function Case IDM_TEST MsgBox "你好,现在已经受到你的消息!" End Select End If ' Let old window procedure handle other messages WindowsProc = CallWindowProc(procOld, hwnd, uMsg, wParam, lParam)
Public Const IDM_ABOUT = &H2000
Public Const IDM_UNITS = &H2001
Public Const IDM_RESET = &H2002
Public Const IDM_EXIT = &H2003
Public Const IDM_TEST = &H2005
'添加菜单
Dim hSysMenu As Long
' Get handle of system menu
hSysMenu = GetSystemMenu(Me.hwnd, 0)
' Append separator and menu item with ID IDM_ABOUT
Call AppendMenu(hSysMenu, MF_SEPARATOR, 0&, 0&)
Call AppendMenu(hSysMenu, MF_STRING, IDM_ABOUT, "About...")
Call AppendMenu(hSysMenu, MF_STRING, IDM_UNITS, "Units...")
Call AppendMenu(hSysMenu, MF_STRING, IDM_RESET, "Reset...")
Call AppendMenu(hSysMenu, MF_STRING, IDM_EXIT, "Exit")
'改变窗体的处理函数
hwnd = Me.hwnd
' Install system menu window procedure
procOld = SetWindowLong(ByVal hwnd, GWL_WNDPROC, AddressOf WindowsProc)
'获取消息
Public Function WindowsProc(ByVal hwnd As Long, ByVal uMsg As Long, _
ByVal wParam As Long, ByVal lParam As Long) As Long
' Ignore everything but system commands
If uMsg = WM_SYSCOMMAND Then
' ' Check for one special menu item
' WindowsProc = CallWindowProc(procOld, hwnd, uMsg, wParam, lParam)
Debug.Print uMsg, wParam, lParam
Select Case wParam
Case IDM_ABOUT
' FrmAbout.Show
' Exit Function
Case IDM_UNITS
' FrmUnits.Show
' Exit Function
Case IDM_RESET
' FrmMain.TmrSys.Enabled = False
' Dim Response
' Response = MsgBox("Do you want to reset your Mouse Tracker to zero? " & Chr(13) & "Your current mileage reading will lost forever.", vbOKCancel + vbExclamation, "Reset Mouse Tracker")
If Response = vbOK Then
Distance = 0 'reset to zero
GetCursorPos Pnt
OldX = Pnt.x * Screen.TwipsPerPixelX
OldY = Pnt.y * Screen.TwipsPerPixelY
FrmMain.Caption = Format(Distance / UnitValue, FormatStr) & UnitName
FrmMain.TmrSys.Enabled = True
Else: FrmMain.TmrSys.Enabled = True
End If
Exit Function
Case IDM_EXIT
Unload FrmMain
Exit Function
Case IDM_TEST
MsgBox "你好,现在已经受到你的消息!"
End Select End If ' Let old window procedure handle other messages
WindowsProc = CallWindowProc(procOld, hwnd, uMsg, wParam, lParam)
End Function我又具体的源代码,你要我可以发给你!