Wednesday, April 29, 2009

Change Clipboard

'Change Clipboard

'need 1 TextBox and 1 module




'In the form

Private Sub Form_Load()

Me.Caption = "Please CTRL+V to text box"

'Subclass this form

HookForm Me

'Register this form as a Clipboardviewer

SetClipboardViewer Me.hwnd

Clipboard.Clear

Clipboard.SetText "RockessAlpha.blogspot.com"

End Sub

Private Sub Form_Unload(Cancel
As Integer)

'Unhook the form

UnHookForm Me

End Sub



'In a module

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 ...", vbOKOnly, "RockessAlpha.blogspot.com"

End If

End Function


 

No comments:

Post a Comment