VBGood网站全文搜索 Google

搜索VBGood全站网页(全文搜索)

VB爱好者乐园(VBGood)

 找回密码
 立即注册
搜索
查看: 641|回复: 2

SetWindowLongPtr

[复制链接]
发表于 2020-1-21 17:01:15 | 显示全部楼层 |阅读模式
怎么声明 怎么用? 谢谢
 楼主| 发表于 2020-1-21 18:51:06 | 显示全部楼层
Option Explicit

Private Declare Function RegisterShellHookWindow Lib "user32" (ByVal hwnd As Long) As Long  ''use in NT5
Private Declare Function RegisterWindowMessage Lib "user32" Alias "RegisterWindowMessageA" (ByVal lpString As String) As Long
Private Declare Function DeregisterShellHookWindow Lib "user32" (ByVal hwnd As Long) As Long
Private Declare Function SetWindowLong Lib "user32" Alias "SetWindowLongA" (ByVal hwnd As Long, ByVal nIndex As Long, ByVal dwNewLong As Long) As Long
Private 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
Private Declare Function GetWindowText Lib "user32" Alias "GetWindowTextA" (ByVal hwnd As Long, ByVal lpString As String, ByVal cch As Long) As Long
Private Declare Function GetWindowTextLength Lib "user32" Alias "GetWindowTextLengthW" (ByVal hwnd As Long) As Long

Dim WM_SHELLHOOK As Long
Dim mWndProc As Long

Public Sub Main()
    Form1.Show
    WM_SHELLHOOK = SetHook(Form1.hwnd)
    mWndProc = SetWindowLong(Form1.hwnd, -4&, AddressOf WndProc)
End Sub

Private Function SetHook(wHwnd) As Long
    If 0 <> RegisterShellHookWindow(wHwnd) Then
        Dim id As Long: id = RegisterWindowMessage("HookTaiwan")
    End If: SetHook = id
End Function

Private Function UnHook(wHwnd) As Long
    SetWindowLong wHwnd, -4&, mWndProc
    DeregisterShellHookWindow wHwnd
End Function

Private Function WndProc(ByVal wHwnd As Long, ByVal wMsg As Long, ByVal wParam As Long, ByVal lParam As Long) As Long
    Select Case wMsg
        Case WM_SHELLHOOK
            If wParam = 1& Then  'HSHELL_WINDOWCREATED=1 (顶级窗体被创建)
                Dim szTmp As String
                szTmp = String(260, 0)
                Call GetWindowText(lParam, szTmp, 260)
                Form1.Text1.Text = "HSHELL_WINDOWCREATED:" & Left(szTmp, GetWindowTextLength(lParam))
            End If
        Case 2  'WM_DESTROY
            Call UnHook(Form1.hwnd)
    End Select
    WndProc = CallWindowProc(mWndProc, wHwnd, wMsg, wParam, lParam)
End Function

这个代码什么问题 帮忙看看 ? 截不到啊
回复 支持 反对

使用道具 举报

发表于 2020-1-22 11:45:15 | 显示全部楼层
Private Declare Function SetWindowLong Lib "user32" Alias "SetWindowLongA" (ByVal hwnd As Long, ByVal nIndex As Long, ByVal dwNewLong As Long) As Long
回复 支持 反对

使用道具 举报

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

文字版|手机版|小黑屋|VBGood  

GMT+8, 2020-4-7 09:10

VB爱好者乐园(VBGood)
快速回复 返回顶部 返回列表