vb.net错误:AddressOf表达式不能转换为Long,因为Long不是委托类型,怎么解决啊?
我想改变msgbox的显示位置,从网上找了一段代码,但提示出错
Public Declare Function SetWindowsHookEx Lib "user32" Alias "SetWindowsHookExA" (ByVal idHook As Long, ByVal lpfn As Long, ByVal hmod As Long, ByVal dwThreadId As Long) As Long
Public Declare Function UnhookWindowsHookEx Lib "user32" (ByVal hHook As Long) As Long
Public Declare Function GetWindowLong Lib "user32" Alias "GetWindowLongA" (ByVal hwnd As Long, ByVal nIndex As Long) As Long
Public Declare Function GetCurrentThreadId Lib "kernel32" () As Long
Public Declare Function SetWindowPos Lib "user32" (ByVal hwnd As Long, ByVal hWndInsertAfter As Long, ByVal x As Long, ByVal y As Long, ByVal cx As Long, ByVal cy As Long, ByVal wFlags As Long) As Long
Public Const GWL_HINSTANCE = (-6)
Public Const SWP_NOSIZE = &H1
Public Const SWP_NOZORDER = &H4
Public Const SWP_NOACTIVATE = &H10
Public Const HCBT_ACTIVATE = 5
Public Const WH_CBT = 5
Public hHook As Long
Private SetX As Long, SetY As Long
Private Function DlgPos(ByVal lMsg As Long, ByVal wParam As Long, ByVal lParam As Long) As Long
If lMsg = HCBT_ACTIVATE Then
SetWindowPos(wParam, 0, SetX, SetY, 0, 0, SWP_NOSIZE Or SWP_NOZORDER Or SWP_NOACTIVATE)
UnhookWindowsHookEx(hHook)
End If
End Function
Public Function SetMsgBoxPos(ByVal x As Long, ByVal y As Long)
SetX = x : SetY = y
Dim hInst As Long, Thread As Long
hInst = GetWindowLong(Me.Handle.ToInt64, GWL_HINSTANCE)
Thread = GetCurrentThreadId
hHook = SetWindowsHookEx(WH_CBT, AddressOf DlgPos, hInst, Thread) ‘提示AddressOf表达式不能转换为Long,因为Long不是委托类型
End Function
这怎么解决啊?谢谢先
要说委托的话太复杂了,可以参考msdn关于委托的范例。
另外,能不能不要 adressof阿? 直接让其返回一个long