本文主要是介绍VB6监视剪贴板图片,希望对大家解决编程问题提供一定的参考价值,需要的开发者们随着小编来一起学习吧!
最近玩云游戏需要按 PrintScreen 自动保存图片,突然发现色彩风暴剪贴板 CPU 占用高,可能使用了定时设计,立马想到了剪贴板变化信号。
参考:https://bbs.csdn.net/topics/487023,监视剪贴板文字。
改成图片,具体什么意思我也没看懂,Image控件没有hwnd,PictureBox控件有hwnd。
窗体
Private Sub Form_Load()SetClipboardViewer Picture1.hwndShowprevWndProc = GetWindowLong(Picture1.hwnd, GWL_WNDPROC)SetWindowLong Picture1.hwnd, GWL_WNDPROC, AddressOf WndProc
End SubPrivate Sub Form_Unload(Cancel As Integer)SetWindowLong Picture1.hwnd, GWL_WNDPROC, prevWndProc
End Sub
模块
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 LongPublic Const WM_DRAWCLIPBOARD = &H308
Public Const GWL_WNDPROC = (-4)Public prevWndProc As LongFunction WndProc(ByVal hwnd As Long, ByVal Msg As Long, ByVal wParam As Long, ByVal lParam As Long) As LongOn Error Resume NextIf Msg = WM_DRAWCLIPBOARD Thenfilepath = "C:\Users\Administrator\Desktop\" & Format(Now, "yyyymmddhhmmss") & ".bmp"SavePicture Clipboard.GetData, filepathEnd IfWndProc = CallWindowProc(prevWndProc, hwnd, Msg, wParam, lParam)
End Function
优点:基本没有CPU占用。
缺点:有窗口,图片只能保存bmp格式。
这篇关于VB6监视剪贴板图片的文章就介绍到这儿,希望我们推荐的文章对编程师们有所帮助!