Quantcast
Channel: VBForums - CodeBank - Visual Basic 6 and earlier
Viewing all articles
Browse latest Browse all 1449

VB6 Monitoring/Manipulating clipboard example, clipboard viewer

$
0
0
Code:

Dim ClipSetCount  As Long

Private Sub Command1_Click()
    Clipboard.Clear
    Clipboard.SetText Text2.Text
End Sub

Private Sub Form_Load()
    SetClipboardViewer Me.hwnd
    Show
    prevWndProc = GetWindowLong(Me.hwnd, GWL_WNDPROC)
    SetWindowLong Me.hwnd, GWL_WNDPROC, AddressOf WndProc
End Sub
 
Private Sub Form_Unload(Cancel As Integer)
    SetWindowLong Me.hwnd, GWL_WNDPROC, prevWndProc
End Sub

Sub objSC_MsgCome(lng_hWnd As Long, uMsg As Long, wParam As Long, lParam As Long)
        Select Case uMsg
            Case WM_DRAWCLIPBOARD                              '剪贴板被改变
                ClipSetCount = ClipSetCount + 1
                Frame1.Caption = "变化次数:" & ClipSetCount
                Text1.Text = Clipboard.GetText
        End Select
End Sub

Code:

Public Declare Function SetClipboardViewer Lib "user32" (ByVal hwnd 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 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 GetWindowLong Lib "user32" Alias "GetWindowLongA" (ByVal hwnd As Long, ByVal nIndex As Long) As Long
 
Public Const WM_DRAWCLIPBOARD = &H308
Public Const GWL_WNDPROC = (-4)
 
Public prevWndProc As Long
 
Function WndProc(ByVal hwnd As Long, ByVal Msg As Long, ByVal wParam As Long, ByVal lParam As Long) As Long
    On Error Resume Next
'    If Msg = WM_DRAWCLIPBOARD Then
    Call Form1.objSC_MsgCome(hwnd, Msg, wParam, lParam)
    WndProc = CallWindowProc(prevWndProc, hwnd, Msg, wParam, lParam)
End Function


Viewing all articles
Browse latest Browse all 1449

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>