SetWindowLong GetDesktopWindow(),GWL_WNDPROC,AddressOf WndProc
本意是想获取桌面窗体的句柄,做个简单的钩子,没想到没效果。。。这是为什么???
[此贴子已经被作者于2007-8-25 9:31:59编辑过]
昨天打字的时候没太注意,今早一起来看才发现打错了,马上改了过来
这只是一个试验代码:
form1中:
Private Sub Command1_Click()
oldProc = SetWindowLong(GetDesktopWindow(), GWL_WNDPROC, AddressOf WinProc)
End Sub
Private Sub Command2_Click()
SetWindowLong GetDesktopWindow(), GWL_WNDPROC, oldProc
End Sub
Private Sub Command3_Click()
Text1.Text = Flag
End Sub
Private Sub Form_Load()
Flag = True
End Sub
模块中:
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 Declare Function SetWindowLong Lib "user32" Alias "SetWindowLongA" (ByVal hWnd As Long, ByVal nIndex As Long, ByVal dwNewLong As Long) As Long
Public Declare Function GetDesktopWindow Lib "user32" () As Long
Public Const GWL_WNDPROC = (-4)
Public Flag As Boolean
Public oldProc As Long
Public Function WinProc(ByVal hWnd As Long, ByVal Msg As Long, ByVal wParam As Long, ByVal lParam As Long) As Long
Flag = False
WinProc = CallWindowProc(oldProc, hWnd, Msg, wParam, lParam)
End Function
本意是向桌面发出信息后,改变Flag的取值,没想到Flag的值都没变!