在Visual Basic 4中是否有等效的AddressOf?
我试图获得一些Visual Basic 5/6代码,它将菜单项添加到我在VB4中使用的表单系统菜单中。以下是无法编译的代码片段:
'Add Custom Menu To System Menu
Call AppendMenu(GetSystemMenu(Me.hWnd, 0&), MF_SEPARATOR, 0&, vbNullString)
Call AppendMenu(GetSystemMenu(Me.hWnd, 0&), MF_STRING, IDM_SYSTEMTRAY, "Minimize To &System Tray")
Call AppendMenu(GetSystemMenu(Me.hWnd, 0&), MF_STRING, IDM_ABOUT, "&About...")
procOld = SetWindowLong(hWnd, GWL_WNDPROC, AddressOf WindowProc)
以下是该模块的API声明:
' Win32 API
Public Const MF_SEPARATOR = &H800&
Public Const MF_STRING = &H0&
Public Const GWL_WNDPROC = (-4)
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 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 Const WM_SYSCOMMAND = &H112
' User Created
Public procOld As Long
Public Const IDM_ABOUT As Long = 1010
Public Const IDM_SYSTEMTRAY As Long = 1011
最后,WindowProc的代码:
Public Function WindowProc(ByVal hWnd As Long, ByVal iMsg As Long, ByVal wParam As Long, ByVal lParam As Long) As Long
Select Case iMsg
Case WM_SYSCOMMAND
Select Case wParam
Case IDM_ABOUT
MsgBox "About goes here..."
Exit Function
Case IDM_SYSTEMTRAY
MsgBox "Send to system tray code goes here..."
Exit Function
End Select
End Select
' Pass all messages on to VB and then return the value to windows
WindowProc = CallWindowProc(procOld, hWnd, iMsg, wParam, lParam)
End Function
任何其他指针或将项添加到表单系统菜单的替代方法也将受到赞赏!
答案 0 :(得分:2)
来自:Xtreme VB Talk: AddressOf work around for vb4
[班卓琴] 我不认为你可以不诉诸某些外部 用C语言编写的DLL。
[OnErr0r] Matt Curland写了这么一个dll。允许您获取类函数的地址,甚至可以使用vb5 / 6。
注册后,您可以从上面的页面下载callback.zip
。 作为后备,您可以在此处获取文件:callback.zip
编辑:直接下载链接已被删除,因为此源代码似乎是Matt Curland版权所有并受版权保护的一部分。