《程序员》2001第4期上有文章(HOOK 剪贴版)不过那段代码在我这里出错,你可以再试试

解决方案 »

  1.   

    监视剪贴板  
    --------------------------------------------------------------------------------
    人气指数:174
     监视剪贴板的函数的介绍和例子。 (1千字)The SetClipboardViewer function adds the specified window to the chain of clipboard viewers. Clipboard viewer windows receive a WM_DRAWCLIPBOARD message whenever the content of the clipboard changes. 例子: 
    'Create a new project, add a module to it 
    'Add a command button to Form1 
    'In the form 
    Private Sub Form_Load() 
    'KPD-Team 1999 
    'URL: http://www.allapi.net/ 
    'E-Mail: [email protected] 
    'Subclass this form 
    HookForm Me 
    'Register this form as a Clipboardviewer 
    SetClipboardViewer Me.hwnd 
    End Sub 
    Private Sub Form_Unload(Cancel As Integer) 
    'Unhook the form 
    UnHookForm Me 
    End Sub 
    Private Sub Command1_Click() 
    'Change the clipboard 
    Clipboard.Clear 
    Clipboard.SetText "Hello !" 
    End Sub 'In a module 
    'These routines are explained in our subclassing tutorial. 
    'http://www.allapi.net/vbtutor/subclass.htm 
    Declare Function SetWindowLong Lib "user32" Alias "SetWindowLongA" (ByVal hwnd As Long, ByVal nIndex As Long, ByVal dwNewLong As Long) As Long 
    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 
    Declare Function SetClipboardViewer Lib "user32" (ByVal hwnd As Long) As Long 
    Public Const WM_DRAWCLIPBOARD = &H308 
    Public Const GWL_WNDPROC = (-4) 
    Dim PrevProc As Long 
    Public Sub HookForm(F As Form) 
    PrevProc = SetWindowLong(F.hwnd, GWL_WNDPROC, AddressOf WindowProc) 
    End Sub 
    Public Sub UnHookForm(F As Form) 
    SetWindowLong F.hwnd, GWL_WNDPROC, PrevProc 
    End Sub 
    Public Function WindowProc(ByVal hwnd As Long, ByVal uMsg As Long, ByVal wParam As Long, ByVal lParam As Long) As Long 
    WindowProc = CallWindowProc(PrevProc, hwnd, uMsg, wParam, lParam) 
    If uMsg = WM_DRAWCLIPBOARD Then 
    MsgBox "Clipboard changed ..." 
    End If 
    End Function 资料直接提供人:FD 主页: http://fd.chn.net
    论坛相关帖子