2016-08-19 29 views
0

下面顯示的VBA代碼片段很好(感謝谷歌)通過Win32枚舉所有打開的窗口。爲簡潔起見,我省略了EnumCallBack()函數。當傳遞給Win32時VBA和函數操作符

我的問題是&運算符出現在EnumWindows調用中的數值常量之後。我知道EnumWindows需要一個指針作爲第二個參數,所以我推斷在常量之後的&運算符將該常量的地址傳遞給Win32。我在網上搜索了一下,找不到任何文檔。只是想驗證我的預感。我預計&會傳遞VBA自定義Type..End類型的地址?

Private Declare Function EnumWindows Lib "user32" (ByVal lpEnumFunc As Long, ByVal lParam As Long) As Boolean 
Private ProcWinHandle As Long 
Private ProcessHandle As Long 

Public Function GetProcessWindowHandle(ProcID As Long) As Long 
    ProcessHandle = ProcID 
    ProcWinHandle = 0 
    Dim retval As Long 
    retval = EnumWindows(AddressOf EnumCallBack, 0&) 
    GetProcessWindowHandle = ProcWinHandle 
End Function 
+0

對於地址有關的混亂閱讀:https://msdn.microsoft.com/en-us/library/ee478101(v=vs.84).aspx,在變量字符後綴閱讀:HTTPS ://msdn.microsoft.com/en-us/library/s9cz43ek.aspx – cyboashu

回答

0

&是用於Long類型短形式。 Dim Var as LongDim var&是等同的。您還可以看到EnumWindows函數以Long作爲其第二個參數。

下面是常見類型及其縮寫的列表。

Public Sub WhichType() 
    Dim VarInteger% 
    Dim VarLong& 
    Dim VarSingle! 
    Dim VarDouble# 
    Dim [email protected] 
    Dim VarString$ 

    'Show the type 
    Debug.Print TypeName(VarInteger) 
    Debug.Print TypeName(VarLong) 
    Debug.Print TypeName(VarSingle) 
    Debug.Print TypeName(VarDouble) 
    Debug.Print TypeName(VarCurrency) 
    Debug.Print TypeName(VarString) 
End Sub 
+0

謝謝!我走了......傑夫 – jdrago