VB.NET作为一款功能比较强大的开发平台,我们可以通过这一编程语言实现许多功能需求。那么首先就先来从一个简单的实现范例来详细解读这款语言给我们带来的好处。编写VB.NET窗体钩子程序的几点启发:#t#
1.在vb.net中long 要该定义为Integer类型
2.在vb.net中Rect要改定义为Rectangle类型,并用byref来引用
3.如何使用委托,如下面这个例子
(1)定义委托函数
- Public Delegate Function HOOKPROC
(ByVal nCode As Integer, ByVal
wParam As Integer, ByVal lParam
As Integer) As Integer
(2)定义在API的函数原型中使用委托函数来作为一个变量类型
- Private Declare Function SetWindowLong
Lib "user32" Alias "SetWindowLongA"
(ByVal hwnd As Integer, ByVal nIndex
As Integer, ByVal dwNewLong As
HOOKPROCA) As Integer
(3)实现具体的函数功能
- Public Function myPROC(ByVal nCode As
Integer, ByVal wParam As Integer,
ByVal lParam As Integer) As Integer- `这中间是具体的实现代码
- `这中间是具体的实现代码
- `这中间是具体的实现代码
- `这中间是具体的实现代码
- end function
- ()`通过API函数来调用委托函数
- SetWindowLong(wParam, GWL_WNDPROC,
AddressOf myPROC)
4.启示API函数申明可以重载如下例:
- Private Declare Function SetWindowLong
Lib "user32" Alias "SetWindowLongA"
(ByVal hwnd As Integer, ByVal nIndex
As Integer, ByVal dwNewLong As
HOOKPROCA) As Integer- Public Declare Function SetWindowLong
Lib "user32" Alias "SetWindowLongA"
(ByVal hwnd As Integer, ByVal nIndex
As Integer, ByVal dwNewLong As Integer)
As Integer
以上是编写程序时要注意的几点