2012-07-15 53 views
2

在Visual Basic 4中是否存在AddressOf的等效項?VB4 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 

任何其他指針或添加項目到我的表單的系統菜單的替代方法也將不勝感激!

回答

2

來源:Xtreme VB Talk: AddressOf work around for vb4

[番] 我不認爲你可以不訴諸somesort用C編寫外 DLL的

[OnErr0r] 馬特Curland寫下了這樣一個dll。允許您獲取類函數的地址,甚至可以與vb5/6一起使用。

您可以在註冊後從上述頁面下載callback.zip 作爲備用,你可以在這裏得到文件:callback.zip

編輯:直接下載鏈接已被刪除,因爲它看來,這個源代碼是Matt Curland和受版權保護的書籍的一部分。

+0

謝謝 - 這足以讓我開始解決問題! – Peter 2012-07-16 06:31:13

相關問題