VBGood網站全文搜索 Google

搜索VBGood全站網頁(全文搜索)

VB愛好者樂園(VBGood)

 找回密碼
 立即注冊
搜索
查看: 200|回復: 2
打印 上一主題 下一主題

SetWindowLongPtr

[復制鏈接]
跳轉到指定樓層
1
發表于 2020-1-21 17:01:15 | 只看該作者 回帖獎勵 |倒序瀏覽 |閱讀模式
怎么聲明 怎么用? 謝謝
2
 樓主| 發表于 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

這個代碼什么問題 幫忙看看 ? 截不到啊
回復 支持 反對

使用道具 舉報

3
發表于 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-2-5 20:00

VB愛好者樂園(VBGood)
快速回復 返回頂部 返回列表
广西快3开奖结果直播 辽宁35选7好运4 北京赛车pk10开奖ds *股票最新消息 湖南亲友官网下载 在家做手工兼职 技术型十一运夺金 甘肃11选5平台 环岛赛儋州赛前报道 上海11选五开奖官网 幸运农场官方