2

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

将项目添加到我的表单系统菜单的任何其他指针或替代方法也将不胜感激!

4

1 回答 1

2

来自:Xtreme VB Talk:针对 vb4 的 AddressOf 工作

[Banjo] 如果不求助于用 C 编写的某种外部 DLL,我认为您无法做到。

[OnErr0r] Matt Curland 就写了这样一个 dll。允许您获取类函数的地址,甚至适用于 vb5/6。

callback.zip注册后即可从以上页面下载。作为后备,您可以在此处获取文件:callback.zip

编辑:直接下载链接已被删除,因为该源代码似乎是Matt Curland的一本书的一部分并受版权保护。

于 2012-07-15T11:00:15.863 回答