• Vui lòng đọc nội qui diễn đàn để tránh bị xóa bài viết
  • Tìm kiếm trước khi đặt câu hỏi

Giám sát clipboard copy

Các thủ thuật về hệ thống, thư mục, tập tin và mạng
User avatar
truongphu
VIP
VIP
Posts: 4765
Joined: Sun 04/11/2007 10:57 am
Location: Cam Đức, Khánh hòa
Has thanked: 14 times
Been thanked: 519 times

Giám sát clipboard copy

Postby truongphu » Tue 08/06/2010 6:58 am

Thủ thuật: Giám sát clipboard copy
Tác giả: Sưu tầm
Mô tả: Giám sát clipboard copy



Form:
  1. Option Explicit
  2.  
  3. Private Sub Form_Load()
  4.  If clipboard_is_hooked = False Then
  5.   clipboard_is_hooked = hook_clipboard(Me.hWnd)
  6.  End If
  7. End Sub
  8.  
  9. Private Sub Form_Unload(Cancel As Integer)
  10.  If clipboard_is_hooked = True Then
  11.   clipboard_is_hooked = unhook_clipboard(Me.hWnd)
  12.  End If
  13. End Sub
  14.  
  15. Private Sub Form_Activate()
  16.  Text1.SetFocus
  17. End Sub
  18.  
  19. Private Sub btnExit_Click()
  20.  Unload Me
  21. End Sub
  22.  
  23. Private Sub btnClear_Click()
  24.  Text1.Text = ""
  25. End Sub
  26.  
  27. Private Sub Text1_Change()
  28.  'whenever text in the textbox is changed, move the cursor to the end of the text
  29. Text1.SelStart = Len(Text1.Text)
  30. End Sub
  31.  
  32. Private Sub Text1_GotFocus()
  33.  'whenever the textbox gains focus, move the cursor to the end of the text
  34. Text1.SelStart = Len(Text1.Text)
  35. End Sub
  36.  
  37. 'Copy above text into clipboard
  38. Private Sub btnCopy_Click()
  39.  If clipboard_is_hooked = True Then
  40.   clipboard_is_hooked = unhook_clipboard(Me.hWnd)
  41.  End If
  42.  Clipboard.Clear
  43.  Clipboard.SetText Text1.Text
  44.  If clipboard_is_hooked = False Then
  45.   Text1.Text = ""
  46.   clipboard_is_hooked = hook_clipboard(Me.hWnd)
  47.  End If
  48. End Sub
  49.  
  50. Private Sub Form_Resize()
  51. If Me.Width > Label1.Width Then
  52.  Label1.Left = (Me.Width - Label1.Width) / 2
  53. End If
  54. If Me.Width > 420 Then
  55.  Text1.Width = Me.Width - 420
  56. End If
  57. If Me.Width > Text1.Width Then
  58.  Text1.Left = (Me.Width - Text1.Width) / 2
  59. End If
  60. If Me.Height > 2040 Then
  61.  Text1.Height = Me.Height - 2040
  62.  Text1.Top = 720
  63. End If
  64. If Me.Height > 1165 Then
  65.  btnClear.Top = Me.Height - 1165
  66.  btnCopy.Top = Me.Height - 1165
  67.  btnExit.Top = Me.Height - 1165
  68. End If
  69. btnClear.Left = Text1.Left + 60
  70. If Me.Width > (250 + btnExit.Width) Then
  71.   btnExit.Left = Me.Width - 250 - btnExit.Width
  72. End If
  73. If Me.Width > btnCopy.Width Then
  74.  btnCopy.Left = ((Me.Width - btnCopy.Width) / 2) + (0.002 * Me.Width)
  75. End If
  76. End Sub
  77.  
  78.  


Module:
[vb]Option Explicit

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 SetClipboardViewer Lib "user32" (ByVal hWnd As Long) As Long
Public Declare Function ChangeClipboardChain Lib "user32" (ByVal hWnd As Long, ByVal hWndNext As Long) As Long
Public Declare Function SendMessage Lib "user32" Alias "SendMessageA" (ByVal hWnd As Long, ByVal wMsg As Long, ByVal wParam As Long, lParam As Long) As Long
Public Declare Function InitCommonControlsEx Lib "comctl32.dll" (iccex As tagInitCommonControlsEx) As Boolean

Public Type tagInitCommonControlsEx
lngSize As Long
lngICC As Long
End Type

Public Const GWL_WNDPROC = (-4&)
Public Const WM_SYSCOMMAND = &H112
Public Const WM_DRAWCLIPBOARD = &H308
Public Const WM_CHANGECBCHAIN = &H30D
Public Const ICC_USEREX_CLASSES = &H200

Public old_window_procedure As Long
Public next_clipboard_viewer As Long
Public clipboard_is_hooked As Boolean
Public frm1 As Form1

Public Sub Main()
On Error GoTo 0
Dim iccex As tagInitCommonControlsEx
iccex.lngSize = LenB(iccex)
iccex.lngICC = ICC_USEREX_CLASSES
InitCommonControlsEx iccex
Set frm1 = New Form1
Load frm1
frm1.Show
End Sub

Public Function hook_clipboard(ByVal window_handle As Long) As Boolean
old_window_procedure = SetWindowLong(window_handle, GWL_WNDPROC, AddressOf new_window_procedure)
next_clipboard_viewer = SetClipboardViewer(window_handle)
If (old_window_procedure <> 0) Then
hook_clipboard = True
Else
hook_clipboard = False
End If
End Function

Public Function unhook_clipboard(ByVal window_handle As Long) As Boolean
If (next_clipboard_viewer <> 0) Then
Call ChangeClipboardChain(window_handle, next_clipboard_viewer)
End If
If (old_window_procedure <> 0) Then
Call SetWindowLong(window_handle, GWL_WNDPROC, old_window_procedure)
End If
unhook_clipboard = False
End Function

Public Function new_window_procedure(ByVal hWnd As Long, ByVal Msg As Long, ByVal wParam As Long, ByVal lParam As Long) As Long
Select Case Msg
Case WM_CHANGECBCHAIN
If wParam = next_clipboard_viewer Then
next_clipboard_viewer = lParam
ElseIf (next_clipboard_viewer <> 0) Then
Call SendMessage(next_clipboard_viewer, Msg, wParam, lParam)
End If
Case WM_DRAWCLIPBOARD
If Clipboard.GetFormat(vbCFText) Then
frm1.Text1.Text = frm1.Text1.Text & Left$(Clipboard.GetText, 32767) & vbNewLine
End If
If (next_clipboard_viewer <> 0) Then
Call SendMessage(next_clipboard_viewer, Msg, wParam, lParam)
End If
End Select
new_window_procedure = CallWindowProc(old_window_procedure, hWnd, Msg, wParam, lParam)
End Function

[/vb]
Attachments
clipboard_monitor.zip
(200.53 KiB) Downloaded 699 times


o0o--truongphu--o0o

.........
Ghé thăm:
Chuyện Linh Tinh

nathu723
Thành viên chính thức
Thành viên chính thức
Posts: 38
Joined: Thu 17/02/2011 10:09 pm

Re: Giám sát clipboard copy

Postby nathu723 » Sun 10/04/2011 3:49 am

Anh cho em hỏi mình sữa chổ nào trong code clipboard_monitor trên để xuất được Unicode text vậy anh.Thanks!

User avatar
truongphu
VIP
VIP
Posts: 4765
Joined: Sun 04/11/2007 10:57 am
Location: Cam Đức, Khánh hòa
Has thanked: 14 times
Been thanked: 519 times

Re: Giám sát clipboard copy

Postby truongphu » Mon 11/04/2011 7:30 am

Bài nầy tôi sưu tầm nên cũng chưa nắm kỹ
Trong VBLib, có bài: Lấy text (mã Unicode) trong Clipboard
Bạn xem có thể kết hợp với bài trên được không?
o0o--truongphu--o0o

.........
Ghé thăm:
Chuyện Linh Tinh

User avatar
truongphu
VIP
VIP
Posts: 4765
Joined: Sun 04/11/2007 10:57 am
Location: Cam Đức, Khánh hòa
Has thanked: 14 times
Been thanked: 519 times

Re: Giám sát clipboard copy

Postby truongphu » Mon 11/04/2011 8:36 pm

Bạn dùng thử:
Phần mềm Unicode ClipBoard Monitor
viewtopic.php?f=41&p=100656#p100655
o0o--truongphu--o0o

.........
Ghé thăm:
Chuyện Linh Tinh


Return to “[VB] Hệ thống - Tập tin - Thư mục và Mạng”

Who is online

Users browsing this forum: No registered users and 1 guest