有没有高手可以帮我读下这段代码,解释一下?中间有些函数,为什么在api 或者vb函数参考中查不到呢?

解决方案 »

  1.   

    Option ExplicitPrivate Const WM_NCDESTROY = &H82Private Declare Function GetProp Lib "user32" Alias "GetPropA" (ByVal hwnd As Long, ByVal lpString As String) As Long
    Private Declare Function SetProp Lib "user32" Alias "SetPropA" (ByVal hwnd As Long, ByVal lpString As String, ByVal hData As Long) As Long
    Private Declare Function RemoveProp Lib "user32" Alias "RemovePropA" (ByVal hwnd As Long, ByVal lpString As String) As LongPrivate Declare Function SetWindowLong Lib "user32" Alias "SetWindowLongA" (ByVal hwnd As Long, ByVal nIndex As Long, ByVal dwNewLong As Long) As Long
    Private Const GWL_WNDPROC = (-4)Private Declare Function CallWindowProc Lib "user32" Alias "CallWindowProcA" (ByVal lpPrevWndFunc As Long, ByVal hwnd As Long, ByVal uMsg As Long, ByVal wParam As Long, ByVal lParam As Long) As LongPrivate Const OLDWNDPROC = "OldWndProc"
    Public Function SubClass(hwnd As Long) As Boolean
      Dim lpfnOld As Long
      Dim fSuccess As Boolean
      
      If (GetProp(hwnd, OLDWNDPROC) = 0) Then
        lpfnOld = SetWindowLong(hwnd, GWL_WNDPROC, AddressOf WndProc)
        If lpfnOld Then
          fSuccess = SetProp(hwnd, OLDWNDPROC, lpfnOld)
        End If
      End If
      
      If fSuccess Then
        SubClass = True
      Else
        If lpfnOld Then Call UnSubClass (hwnd)
      End If
      
    End FunctionPublic Function UnSubClass(hwnd As Long) As Boolean
      Dim lpfnOld As Long
      
      lpfnOld = GetProp (hwnd, OLDWNDPROC)
      If lpfnOld Then
        If RemoveProp(hwnd, OLDWNDPROC) Then
          UnSubClass = SetWindowLong (hwnd, GWL_WNDPROC, lpfnOld)
        End If
      End IfEnd FunctionPublic Function WndProc(ByVal hwnd As Long, ByVal uMsg As Long, ByVal wParam As Long, ByVal lParam As Long) As Long
      
      Select Case uMsg
        Case WM_SHNOTIFY
          Call Form1.NotificationReceipt (wParam, lParam)
          
        Case WM_NCDESTROY
          Call UnSubClass(hwnd)
       
      End Select
        WndProc = CallWindowProc(GetProp(hwnd, OLDWNDPROC), hwnd, uMsg, wParam, lParam)
      End Function
      

  2.   

    子类化的一个例子。
    很多方式都能进行,这里主要是想说明GetProp和SetProp,RemoveProp。