问题描述
- vs2012 热键无法正常注册
-
Public Declare Function SetWindowLong Lib "user32" Alias "SetWindowLongA" (ByVal hWnd As Long, ByVal nIndex As Long, ByVal dwNewLong As DelegateWindowProc) 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 Delegate Function DelegateWndProc(ByVal hwnd As Long, ByVal iMsg As Long, ByVal wParam As Long, ByVal lParam As Long) As Long Public Function wndproc(ByVal hWnd As Long, ByVal Msg As Long, ByVal wParam As Long, ByVal lParam As Long) As Long If Msg = WM_HOTKEY Then If wParam = 1 Then .. msgbox(“已注册”) End If End If '与form_load中的ADDRESSOF WNDPROC对应 wndproc = CallWindowProc(preWinProc, hWnd, Msg, wParam, lParam) End Function
SetWindowLong(Me.Handle, GWL_WNDPROC, AddressOf WndProc)
Public Declare Function SetWindowLong Lib "user32" Alias "SetWindowLongA" (ByVal hWnd As Long, ByVal nIndex As Long, ByVal dwNewLong As DelegateWindowProc) As Long工具:vs2012
语言:vb
一直无法正常注册热键
1. dwNewLong 的数据类型改为Long出现以下错误,网上很多代码都是这样,不能正常编译
error:“AddressOf”表达式不能转换为“Long”,因为“Long”不是委托类型。2.修改为ByVal dwNewLong As DelegateWindowProc后 则出现以下错误:
error::Module1::SetWindowLong”的调用导致堆栈不对称。原因可能是托管的 PInvoke 签名与非托管的目标签名不匹配。请检查 PInvoke 签名的调用约定和参数与非托管的目标签名是否匹配3.function“wndproc”隐藏基 class“Form”中的可重写方法。若要重写基方法,必须将此方法声明为“Overrides”。
4.修改为 Public Overrides sub wndproc
error:sub“wndproc”不能声明为“Overrides”,因为它不重写基 class 中的 sub。求修正错误,或可正确编译运行代码
时间: 2024-10-27 16:57:45