Jump to content

GUIRegisterMsg


Recommended Posts

i thought i understood GUIRegisterMsg but obviously not, im trying to trigger a func when i copy anything "ctr c" or right click copy, but i dont seem be able to get this right.

#include <GUIConstantsEx.au3>
#include <WindowsConstants.au3>

#Region ### START Koda GUI section ### Form=Form1.kxf
$Form1 = GUICreate("Form1", 633, 452, 193, 125)
$Edit1 = GUICtrlCreateEdit("", 88, 24, 353, 369)
GUICtrlSetData(-1, "Edit1")
GUISetState(@SW_SHOW)
#EndRegion ### END Koda GUI section ###

;####### Register the windows message ############
GUIRegisterMsg($WM_COPY, "Win_message")

While 1
    $nMsg = GUIGetMsg()
    Switch $nMsg
        Case $GUI_EVENT_CLOSE
            Exit

    EndSwitch
WEnd

func Win_message()
MsgBox(0,"","Copy Captured")    
EndFunc

i also tried to use $WM_LBUTTONDOWN just to c if it was a problem with $WM_COPY but it says undefined constant ?

and also where do i find a proper list of what all the windows messages do ?

basically im trying to trigger a func if the clipboard changes (cut or copy)

i just seem to go 3 steps forward and 4 steps backward ^_^

thx for any help.

Edited by JackDinn

Thx all,Jack Dinn.

 

JD's Auto Internet Speed Tester

JD's Clip Catch (With Screen Shot Helper)

Projects :- AutoIt - My projects

My software never has bugs. It just develops random features. :-D

Link to comment
Share on other sites

#include <GUIConstantsEx.au3>
#include <WindowsConstants.au3>
#include <ClipBoard.au3>

$Form1 = GUICreate("Form1", 633, 452, 193, 125)
$Edit1 = GUICtrlCreateEdit("", 88, 24, 353, 369)
GUICtrlSetData(-1, "Edit1")
GUISetState(@SW_SHOW)

;####### Register the windows message ############
_ClipBoard_SetViewer ($Form1)
GUIRegisterMsg($WM_DRAWCLIPBOARD, "Copy_command")

While 1
    $nMsg = GUIGetMsg()
    Switch $nMsg
        Case $GUI_EVENT_CLOSE
            Exit

    EndSwitch
WEnd

func Copy_command()
    Local $iFormat
    _ClipBoard_Open ($Form1)
    Do
        $iFormat = _ClipBoard_EnumFormats ($iFormat)
        If $iFormat <> 0 Then
            if _ClipBoard_FormatStr ($iFormat) = "Unicode Text" Then
                Local $new_clip = ClipGet()
                GUICtrlSetData($Edit1, $new_clip)
                ConsoleWrite(">New COPY:" & @CRLF & ">" & $new_clip & @CRLF & "----------" & @CRLF)
            else
                ConsoleWrite(">New COPY:" & @CRLF & ">" & _ClipBoard_FormatStr ($iFormat) & @CRLF & "----------" & @CRLF)
            EndIf
        EndIf
    Until $iFormat = 0
    _ClipBoard_Close ()
EndFunc

Edited by sandin
Link to comment
Share on other sites

Actually, I'm pretty pleased with this one ^_^

You need to set your window as being a clipboard viewer then you'll get a notification (WM_DRAWCLIPBOARD) whenever the contents of the clipboard change.

Global Const $WM_DRAWCLIPBOARD = 0x0308

Global $hEdit

_Main()

Exit

Func _Main()
    Local $hGUI = GUICreate("Clipboard Monitor", 272, 272)
    $hEdit = GUICtrlCreateEdit("", 8, 8, 256, 256)
    GUISetState()
    GUIRegisterMsg($WM_DRAWCLIPBOARD, "_DrawClipboard")
    Local $hNext = DllCall("user32.dll", "hwnd", "SetClipboardViewer", "hwnd", $hGUI)
    Do
    Until GUIGetMsg() = -3
    DllCall("user32.dll", "long", "ChangeClipboardChain", "hwnd", $hGUI, "hwnd", $hNext)
    GUIDelete()
EndFunc

Func _DrawClipboard($hWnd, $iMsg, $wParam, $lParam)
    GUICtrlSetData($hEdit, ClipGet())
EndFunc

EDIT: Curse you Sandin!! ;)

Edited by WideBoyDixon
Link to comment
Share on other sites

Actually, I wasn't aware of Clipboard.au3 so now I'm feeling a bit foolish. I'm sure I'll get over it.

Best idea would be to take a look at this : http://www.autoitscript.com/autoit3/docs/l...d_SetViewer.htm

WBD

Link to comment
Share on other sites

well thx , both of you ;), darn odd things i did not know i couldn't receive a clipboard msg without having set a window as being a clipboard viewer !! odd cos surly the msg is still getting sent, but what do i know ^_^

a lot of the Constants are not defined in <WindowsConstants.au3> like $WM_LBUTTONDOWN & a good few others, not a prob though just use the raw value.

and also where do i find a proper list of what all the windows messages do ? MSDN ?

ok thx both of you i'll tinker a little more.

Thx all,Jack Dinn.

 

JD's Auto Internet Speed Tester

JD's Clip Catch (With Screen Shot Helper)

Projects :- AutoIt - My projects

My software never has bugs. It just develops random features. :-D

Link to comment
Share on other sites

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 account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...