eltorro Posted July 25, 2006 Share Posted July 25, 2006 Here's a udf for use with apps that need to watch the clipboard. expandcollapse popup;Clipboard.au3 ;Steve Podhajecki [eltorro] steve@ocotillo.sytes.net ;Clipboard notification udf ;Allows you app to recieve clipboard change notifications. #Include <GuiConstants.au3> #Include <Constants.au3> #include-once Global Const $WM_CHANGECBCHAIN = 0x030D Global Const $WM_COPYDATA = 0x4A Global Const $WM_DRAWCLIPBOARD = 0x0308 Global $hWnd_NEXT_IN_CLIP_CHAIN Global $bInChain ;Flag to indicate app is in the notification chain. Global $EVENT = 0 ; Then event to pass to msgloop Local $DEBUG = True ;show debug messages. To console ;=============================================================================== ; Function Name: _InitAsClipViewer ; Description: Places the application in the Clipboard notification chain. ; Parameter(s): $hWndA The $handle to the application gui ; Requirement(s): Beta ; Return Value(s): Returns 1 on success or 0 on failure ; User CallTip: ; Author(s): Stephen Podhajecki [eltorro] steve@ocotillo.sytes.net ; Note(s): This must be called before the application can recieve ; Clipboard notifications. ;=============================================================================== Func _InitAsClipViewer($hWndA) Local $LOCAL_ERR _StopAsClipViewer($hWndA) If ($hWndA <> 0) Then ; Register Clipboard 'viewer' notification messages If Not (GUIRegisterMsg($WM_DRAWCLIPBOARD, "MyClipBoardProc")) Then $LOCAL_ERR = $LOCAL_ERR + 1 If Not (GUIRegisterMsg($WM_CHANGECBCHAIN, "MyClipBoardProc")) Then $LOCAL_ERR = $LOCAL_ERR + 1 ;Not Necessary ;If Not (GUIRegisterMsg($WM_COPYDATA,"MyClipBoardProc")) Then $LOCAL_ERR = $LOCAL_ERR +1 If $LOCAL_ERR Then Return 0 ; Add this app to clipboard viewer notification chain Local $v_ret = DllCall("user32", "int", "SetClipboardViewer", "hwnd", $hWndA) If @error Or Not (IsArray($v_ret)) Then Return 0 Else $hWnd_NEXT_IN_CLIP_CHAIN = $v_ret[0] $bInChain = True Return 1 EndIf EndIf If $DEBUG Then ConsoleWrite("$bInChain = " & $bInChain & @LF) Return 0 EndFunc ;==>_InitAsClipViewer ;=============================================================================== ; Function Name: _StopAsClipViewer ; Description: Removes this application from the Clipboard notification chain ; Parameter(s): $hWndA The handle to the application ; Requirement(s): Beta ; Return Value(s): 1 on success or 0 on error (error could be hook not initiated) ; User CallTip: ; Author(s): Stephen Podhajecki [eltorro] steve@ocotillo.sytes.net ; Note(s): ;=============================================================================== Func _StopAsClipViewer($hWndA) Local $LOCAL_ERR If ($bInChain) Then If ($hWndA <> 0) Then ;Release handle from chain $ret = DllCall("user32.dll", "int", "ChangeClipboardChain", "hwnd", $hWndA, "hwnd", $hWnd_NEXT_IN_CLIP_CHAIN) ; UnRegister clipboard messages: If Not (GUIRegisterMsg($WM_CHANGECBCHAIN, "")) Then $LOCAL_ERR = $LOCAL_ERR + 1 If Not (GUIRegisterMsg($WM_DRAWCLIPBOARD, "")) Then $LOCAL_ERR = $LOCAL_ERR + 1 ;Not necessary ;If Not(GUIRegisterMsg($WM_COPYDATA,"MyClipBoardProc")) Then $LOCAL_ERR = $LOCAL_ERR +1 EndIf $bInChain = False If Not ($LOCAL_ERR) Then Return 1 EndIf Return 0 EndFunc ;==>_StopAsClipViewer ;=============================================================================== ; Function Name: MyClipBoardProc ; Description: Recieves messages from AutoIt3's message loop hook. ; Parameter(s): $hWndGUI The handle of the process that sent the message ; $MsgID The message id from the process ; $wParam The wParams sent by the process (hex) ; $lParam The lParams sent by the process (hex) ; Requirement(s): Beta ; Return Value(s): Sets then global Variable $EVENT to the msg id and allows ; the main msg loop to handle the event. ; User CallTip: ; Author(s): ; Note(s): ;Not sure if it is bad mojo for AutoIt to use same function ; for more than one message but in this case it seems to work fine. ;=============================================================================== Func MyClipBoardProc($hWndGUI, $MsgID, $wParam, $lParam) #forceref $hWndGUI, $MsgID, $wParam, $lParam If $DEBUG Then ConsoleWrite("MyClipBoardProc>MsgId>" & $MsgID & @LF) Switch $MsgID Case $WM_DRAWCLIPBOARD ;pass message on to next in chain. DllCall("user32.dll", "int", "SendMessage", "hWnd", $hWnd_NEXT_IN_CLIP_CHAIN, "int", $WM_DRAWCLIPBOARD, "int", $wParam, "int", $lParam) ;Raise the event and let main message loop handle the call. $EVENT = $WM_DRAWCLIPBOARD Case $WM_CHANGECBCHAIN If $wParam = $hWnd_NEXT_IN_CLIP_CHAIN Then $hWnd_NEXT_IN_CLIP_CHAIN = $lParam Else ;The chain has changed, pass it along. DllCall("user32.dll", "int", "SendMessage", "hWnd", $hWnd_NEXT_IN_CLIP_CHAIN, "int", $WM_CHANGECBCHAIN, "hwnd", $wParam, "hwnd", $lParam) EndIf ;Raise the event and let main message loop handle the call. $EVENT = $WM_CHANGECBCHAIN Case $WM_COPYDATA If $DEBUG Then ConsoleWrite("MyClipBoardProc>$WM_COPYDATA>MsgId>" & $MsgID & @LF) Case Else ;No events. $EVENT = 0 EndSwitch Return $GUI_RUNDEFMSG EndFunc ;==>MyClipBoardProc oÝ÷ Øw«{ljw±jjezjëh×6 ;Clipboard notifier UDF example ;Steve Podhajecki [eltorro] steve@ocotillo.sytes.net ; #Include <Clipboard.au3> $hWnd_ME =GUICreate("Clipboard UDF Example.", 340, 260, (@DesktopWidth - 340) / 2, (@DesktopHeight - 260) / 2, -1) GUICtrlCreateLabel("Copy something to the clipboard",8,8,200,25) GUISetState(@SW_SHOW) ;---------------------------------------------------------- ;Application ;---------------------------------------------------------- _InitAsClipViewer ($hWnd_ME) ; add this app as cliboard viewer Main(1) ; Main msg/event handler _StopAsClipViewer ($hWnd_ME) ; Remove this app as viewer, unhook msg Exit ;---------------------------------------------------------- ;Main msg/event loop ;---------------------------------------------------------- Func Main($bStartUp = 0) While 1 $nMsg = GUIGetMsg() Select Case $nMsg = $GUI_EVENT_CLOSE ExitLoop Case $EVENT = $WM_DRAWCLIPBOARD ;supress Startup msgbox. If Not ($bStartUp) Then MsgBox($MB_OK + $MB_SYSTEMMODAL + $MB_TOPMOST,"Clipboard UDF","The Clipboard has changed.") EndIf Case $EVENT =$WM_CHANGECBCHAIN MsgBox($MB_OK + $MB_SYSTEMMODAL + $MB_TOPMOST,"Clipboard UDF","The Clipboard chain has changed.") Case Else ;; EndSelect $EVENT = 0 If $bStartUp then $bStartUp = 0 Sleep(10) WEnd EndFunc ;==>Main So Long, eltorro Clipboard.au3 ClipBoardExample.au3 Regards, [indent]ElTorro[/indent][font="Book"] Decide, Commit, Achieve[/font]_ConfigIO.au3Language Translation --uses Google(tm) MsgBox Move XML wrapper UDF XML2TreeView Zip functionality Split your GUI Save Print ScreenZipPluginEdit In Place listviewSome of my scripts on Google code Link to comment Share on other sites More sharing options...
GaryFrost Posted July 25, 2006 Share Posted July 25, 2006 (edited) Looks good. Have had this in the Snippet Holder for a while (4/9/06). Gary Edited July 25, 2006 by gafrost SciTE for AutoItDirections for Submitting Standard UDFs Don't argue with an idiot; people watching may not be able to tell the difference. Link to comment Share on other sites More sharing options...
eltorro Posted July 25, 2006 Author Share Posted July 25, 2006 Looks good.Have had this in the Snippet Holder for a while (4/9/06).GaryThanks! Snippet Holder was part of the inspiration for the udf. That and being tired of the cut paste dance with forum code. Regards, [indent]ElTorro[/indent][font="Book"] Decide, Commit, Achieve[/font]_ConfigIO.au3Language Translation --uses Google(tm) MsgBox Move XML wrapper UDF XML2TreeView Zip functionality Split your GUI Save Print ScreenZipPluginEdit In Place listviewSome of my scripts on Google code Link to comment Share on other sites More sharing options...
Sunaj Posted March 5, 2007 Share Posted March 5, 2007 Just wanted to say: "Thank you!" to eltorro for this UDF.. really, really useful gear - I think it should be included in autoit distribution! [list=1][*]Generic way to detect full path to default browser, List/ListView Events Using GuiRegisterMsg (detect doubleclick and much more)[*]Using dllcall for full control over fileopendialog, Make DirMove act somewhat normally (by circumventing it...)[*]Avoid problems with "&" (chr(38)) in code, Change desktop maximized area/workspace (fx to make deskbar type app)[*]Change focus behavior when buttons are clicked to work closer to 'standard windows' app[*](Context) Menus With Timed Tooltips, Fast Loops & Operators in AU3[*]Clipboard UDF, A clipboard change notification udf[/list] Link to comment Share on other sites More sharing options...
Zedna Posted April 4, 2007 Share Posted April 4, 2007 (edited) Here is my example for hooking clipboard, ot's not UDF just code snippet example.You may look at it for comparision. Edited April 4, 2007 by Zedna Resources UDF ResourcesEx UDF AutoIt Forum Search Link to comment Share on other sites More sharing options...
FuryCell Posted April 4, 2007 Share Posted April 4, 2007 Nice! I just might have some uses for this. Thanks for sharing. HKTunes:Softpedia | GoogleCodeLyricToy:Softpedia | GoogleCodeRCTunes:Softpedia | GoogleCodeMichtaToolsProgrammer n. - An ingenious device that turns caffeine into code. Link to comment Share on other sites More sharing options...
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now