Jump to content

Messages UDF


Yashied
 Share

Recommended Posts

LAST VERSION - 1.1

06-Apr-09

Deprecated.

This library based on MessageHandler UDF.

Available functions

_MsgReceiverList

_MsgRegister

_MsgRelease

_MsgSend

_MsgTimerInterval

_MsgWindowHandle

_IsReceiver

Messages UDF Library v1.1

Previous downloads: 446

Messages.au3

Example

#Include <EditConstants.au3>
#Include <GUIConstantsEx.au3>
#Include <GUIEdit.au3>
#Include <GUISlider.au3>
#Include <StaticConstants.au3>
#Include <WindowsConstants.au3>
#Include <Messages.au3>

#NoTrayIcon

If Not @Compiled Then
    MsgBox(64, 'Messages UDF Library Demonstration', 'To run this script, you must first compile it and then run the (.exe) file.')
    Exit
EndIf

Opt('MustDeclareVars', 1)

If $CmdLine[0] = 0 Then
    ShellExecute(@ScriptFullPath, '1')
    ShellExecute(@ScriptFullPath, '2')
    ShellExecute(@ScriptFullPath, '3')
    Exit
EndIf

Global $Form, $Input1, $Input2, $Radio1, $Radio2, $Radio3, $ButtonSend, $Edit, $Slider, $Check

Switch $CmdLine[1]
    Case '1', '2', '3'
        _Main(Int($CmdLine[1]))
    Case Else

EndSwitch

Func _Main($Index)

    Local $GUIMsg, $nScript, $Data, $Timer = _MsgTimerInterval(0)

    $Form = GUICreate('Script' & $Index, 324, 384, (@DesktopWidth - 1018) / 2 + ($Index - 1) * 344, (@DesktopHeight - 440) / 2, BitOR($WS_CAPTION, $WS_SYSMENU), $WS_EX_TOPMOST)

    GUISetFont(8.5, 400, 0, 'Tahoma', $Form)

    GUICtrlCreateLabel('Message:', 14, 22, 48, 14)
    $Input1 = GUICtrlCreateInput('', 64, 19, 246, 20)
    GUICtrlCreateLabel('Send to:', 14, 56, 48, 14)

    GUIStartGroup()

    $Radio1 = GUICtrlCreateRadio('Script1', 64, 56, 56, 14)
    GUICtrlSetState(-1, $GUI_CHECKED)
    $Radio2 = GUICtrlCreateRadio('Script2', 130, 56, 56, 14)
    $Radio3 = GUICtrlCreateRadio('Script3', 196, 56, 56, 14)

    $ButtonSend = GUICtrlCreateButton('Send', 236, 88, 75, 23)
    GUICtrlSetState(-1, $GUI_DEFBUTTON)
    GUICtrlCreateLabel('', 14, 128, 299, 2, $SS_ETCHEDHORZ)
    GUICtrlCreateLabel('Received message:', 14, 142, 98, 14)
    $Edit = GUICtrlCreateEdit('', 14, 160, 296, 129, BitOR($ES_READONLY, $WS_VSCROLL, $WS_HSCROLL))
    GUICtrlSetBkColor(-1, 0xFFFFFF)
    GUICtrlCreateLabel('Timer interval (ms):', 14, 316, 98, 14)
    $Slider = GUICtrlCreateSlider(110, 312, 162, 26, BitOR($TBS_AUTOTICKS, $WS_TABSTOP))
    GUICtrlSetLimit(-1, 20, 1)
    GUICtrlSetData(-1, $Timer / 50)
    _GUICtrlSlider_SetTicFreq(-1, 1)
    $Input2 = GUICtrlCreateInput($Timer, 274, 313, 36, 20, $ES_READONLY)
    GUICtrlSetBkColor(-1, 0xFFFFFF)
    $Check = GUICtrlCreateCheckbox('Enable receiver', 14, 354, 96, 19)
    GUICtrlSetState(-1, $GUI_CHECKED)

    Opt('GUICloseOnESC', 0)

    GUISetState()

    _MsgRegister('Script' & $Index, '_Receiver')

    While 1
        $GUIMsg = GUIGetMsg()
        Select
            Case $GUIMsg = $GUI_EVENT_CLOSE
                Exit
            Case $GUIMsg = $ButtonSend
                For $i = $Radio1 To $Radio3
                    If GUICtrlRead($i) = $GUI_CHECKED Then
                        $nScript = 1 + $i - $Radio1
                        ExitLoop
                    EndIf
                Next
                $Data = GUICtrlRead($Input1)
                If StringStripWS($Data, 3) = '' Then
                    $Data = '(empty)'
                EndIf
                If _IsReceiver('Script' & $nScript) Then
                    _MsgSend('Script' & $nScript, 'From Script' & $Index & ':  ' & $Data)
                EndIf
            Case $GUIMsg = $Slider
                _MsgTimerInterval($Timer)
            Case $GUIMsg = $Check
                If GUICtrlRead($Check) = $GUI_CHECKED Then
                    _MsgRegister('Script' & $Index, '_Receiver')
                    GUICtrlSetState($Edit, $GUI_ENABLE)
                    GUICtrlSetBkColor($Edit, 0xFFFFFF)
                    GUICtrlSetState($Slider, $GUI_ENABLE)
                    GUICtrlSetState($Input2, $GUI_ENABLE)
                Else
                    _MsgRegister('Script' & $Index, '')
                    GUICtrlSetState($Edit, $GUI_DISABLE)
                    GUICtrlSetBkColor($Edit, $GUI_BKCOLOR_TRANSPARENT)
                    GUICtrlSetState($Slider, $GUI_DISABLE)
                    GUICtrlSetState($Input2, $GUI_DISABLE)
                EndIf
        EndSelect
        $Data = GUICtrlRead($Slider) * 50
        If BitXOR($Data, $Timer) Then
            GUICtrlSetData($Input2, $Timer)
            $Timer = $Data
        EndIf
    WEnd
EndFunc   ;==>_Main

Func _Receiver($sMessage)
    _GUICtrlEdit_AppendText($Edit, $sMessage & @CRLF)
    Return 0
EndFunc   ;==>_Receiver
Edited by Yashied
Link to comment
Share on other sites

Link to comment
Share on other sites

  • 3 weeks later...

Concept looks great!!

However, This makes no sense to me...

func _MsgWindowHandle($controlID)
    
    if not IsInt($controlID) then
        return 0
    endif
    
    for $i = 1 to $msgId[0][0]
        if $msgId[$i][0] = $MsgID then
            return $msgId[$i][3]
        endif
    next
    return 0
endfunc; _MsgWindowHandle

According to that function, the $ControlID is not utilized except that it is tested as an Int()

Also, you really should use "tidy" from Scite Tools

Thanks for sharing!!

8)

NEWHeader1.png

Link to comment
Share on other sites

Concept looks great!!

Thanks.

According to that function, the $ControlID is not utilized except that it is tested as an Int()

You're right in that there was no need. Also here there is an error ($MsgID, instead of $controlID).

:D

func _MsgWindowHandle($controlID)
    for $i = 1 to $msgId[0][0]
        if $msgId[$i][0] = $controlID then
            return $msgId[$i][3]
        endif
    next
    return 0
endfunc; _MsgWindowHandle

Also, you really should use "tidy" from Scite Tools

??? Edited by Yashied
Link to comment
Share on other sites

If you don't have SciTe editor get it here...

SciTe Editor

In SciTe Press> Tools > Tidy Autoit Source

This will clean, capitalize, tab and line-up the source code

8)

Thanks. I use SciTE editor. If you mean like "func" instead of "Func", etc, then is comfortable for me.

:D

Link to comment
Share on other sites

  • 9 months later...

Awesome tool.

Have to switch to something else though. Seems I can't send data as fast as I want. If it tries to send too fast, the queue system you put in place takes effect (awesome idea! but bad for fast script2script communication). Looking for alternatives.

Link to comment
Share on other sites

  • 3 months later...

Thanks a lot. With this, passing a message to script B and returning it to script A depends on how long each script pauses. Such a round trip can take as little as 0.5ms on my CPU, but then eats up all cycles of the CPU core it's running on.

Utilizing the messages.au3 library from this here thread, a round trip usually takes 140ms, but the script can pretty much do what it wants.

I also checked out Kip's TCP client/server "inter-script communication" approach, and it seems to be the best of both worlds. A round trip usually takes 31.5ms, but passing around messages between scripts may be done even if they're busy.

Link to comment
Share on other sites

  • 3 months later...

Shouldn't "dword;dword;ptr" be changed to "ulong_ptr;dword;ptr" as you suggested? Plus forgot to mention thanks for providing this example.

Edited by guinness

UDF List:

 
_AdapterConnections() • _AlwaysRun() • _AppMon() • _AppMonEx() • _ArrayFilter/_ArrayReduce • _BinaryBin() • _CheckMsgBox() • _CmdLineRaw() • _ContextMenu() • _ConvertLHWebColor()/_ConvertSHWebColor() • _DesktopDimensions() • _DisplayPassword() • _DotNet_Load()/_DotNet_Unload() • _Fibonacci() • _FileCompare() • _FileCompareContents() • _FileNameByHandle() • _FilePrefix/SRE() • _FindInFile() • _GetBackgroundColor()/_SetBackgroundColor() • _GetConrolID() • _GetCtrlClass() • _GetDirectoryFormat() • _GetDriveMediaType() • _GetFilename()/_GetFilenameExt() • _GetHardwareID() • _GetIP() • _GetIP_Country() • _GetOSLanguage() • _GetSavedSource() • _GetStringSize() • _GetSystemPaths() • _GetURLImage() • _GIFImage() • _GoogleWeather() • _GUICtrlCreateGroup() • _GUICtrlListBox_CreateArray() • _GUICtrlListView_CreateArray() • _GUICtrlListView_SaveCSV() • _GUICtrlListView_SaveHTML() • _GUICtrlListView_SaveTxt() • _GUICtrlListView_SaveXML() • _GUICtrlMenu_Recent() • _GUICtrlMenu_SetItemImage() • _GUICtrlTreeView_CreateArray() • _GUIDisable() • _GUIImageList_SetIconFromHandle() • _GUIRegisterMsg() • _GUISetIcon() • _Icon_Clear()/_Icon_Set() • _IdleTime() • _InetGet() • _InetGetGUI() • _InetGetProgress() • _IPDetails() • _IsFileOlder() • _IsGUID() • _IsHex() • _IsPalindrome() • _IsRegKey() • _IsStringRegExp() • _IsSystemDrive() • _IsUPX() • _IsValidType() • _IsWebColor() • _Language() • _Log() • _MicrosoftInternetConnectivity() • _MSDNDataType() • _PathFull/GetRelative/Split() • _PathSplitEx() • _PrintFromArray() • _ProgressSetMarquee() • _ReDim() • _RockPaperScissors()/_RockPaperScissorsLizardSpock() • _ScrollingCredits • _SelfDelete() • _SelfRename() • _SelfUpdate() • _SendTo() • _ShellAll() • _ShellFile() • _ShellFolder() • _SingletonHWID() • _SingletonPID() • _Startup() • _StringCompact() • _StringIsValid() • _StringRegExpMetaCharacters() • _StringReplaceWholeWord() • _StringStripChars() • _Temperature() • _TrialPeriod() • _UKToUSDate()/_USToUKDate() • _WinAPI_Create_CTL_CODE() • _WinAPI_CreateGUID() • _WMIDateStringToDate()/_DateToWMIDateString() • Au3 script parsing • AutoIt Search • AutoIt3 Portable • AutoIt3WrapperToPragma • AutoItWinGetTitle()/AutoItWinSetTitle() • Coding • DirToHTML5 • FileInstallr • FileReadLastChars() • GeoIP database • GUI - Only Close Button • GUI Examples • GUICtrlDeleteImage() • GUICtrlGetBkColor() • GUICtrlGetStyle() • GUIEvents • GUIGetBkColor() • Int_Parse() & Int_TryParse() • IsISBN() • LockFile() • Mapping CtrlIDs • OOP in AutoIt • ParseHeadersToSciTE() • PasswordValid • PasteBin • Posts Per Day • PreExpand • Protect Globals • Queue() • Resource Update • ResourcesEx • SciTE Jump • Settings INI • SHELLHOOK • Shunting-Yard • Signature Creator • Stack() • Stopwatch() • StringAddLF()/StringStripLF() • StringEOLToCRLF() • VSCROLL • WM_COPYDATA • More Examples...

Updated: 22/04/2018

Link to comment
Share on other sites

  • 6 months later...

I am trying to get the GUI to start the receiver function automatically. but it seems if i do that the _MsgSend doesn't work anymore. The only way I can get it working is if I manually startup the Receiver first then the GUI.

Any Ideas on how I should do this differently to accomplish both?

Thanks in Advance,

GUI Script (not a GUI yet)

#include <Messages.au3>

Opt("TrayOnEventMode", 1)
Opt("TrayMenuMode", 1)
$exititem = TrayCreateItem("Exit")
TrayItemSetOnEvent(-1, "_Exit")

TraySetState(1)

RunWait(@ScriptDir & "\IsProcessing.exe " & @AutoItPID)

_MsgRegister('IsProcessing', '_MyReceiver2')

_MsgSend('GUI', "msg from GUI")

While 1
    Sleep(10)
WEnd

Func _MyReceiver2($sMessage)
    MsgBox(0, 'IsProcessing', $sMessage, 1)
EndFunc   ;==>_MyReceiver2

Func _Exit()
    Exit
EndFunc   ;==>_Exit

IsProcessing (Receiver Function)

#include <Messages.au3>

Opt("TrayOnEventMode", 1)
Opt("TrayMenuMode", 1)
$exititem = TrayCreateItem("Exit")
TrayItemSetOnEvent(-1, "_Exit")

TraySetState(1)

Global $gui_pid

_MsgRegister('GUI', '_MyReceiver1')

If $CmdLine[0] > 0 Then
    For $i = 1 To $CmdLine[0]
        Select
            Case $CmdLine[$i] <> ""
                $gui_pid = $CmdLine[$i]
        EndSelect
    Next
EndIf

While 1
    Sleep(10)
    If Not ProcessExists($gui_pid) Then
        _Exit()
    EndIf
WEnd

Func _MyReceiver1($sMessage)
    MsgBox(0, '', $sMessage, 1)
    _MsgSend('IsProcessing', "msg from Receiver")
EndFunc   ;==>_MyReceiver1

Func _Exit()
    Exit
EndFunc   ;==>_Exit
Link to comment
Share on other sites

What about RunWait()?

#include <Messages.au3>

Opt("TrayOnEventMode", 1)
Opt("TrayMenuMode", 1)
$exititem = TrayCreateItem("Exit")
TrayItemSetOnEvent(-1, "_Exit")

TraySetState(1)

Run(@ScriptDir & "\IsProcessing.exe " & @AutoItPID)

Do
    Sleep(100)
Until _IsReceiver('GUI')

_MsgRegister('IsProcessing', '_MyReceiver2')

_MsgSend('GUI', "msg from GUI")

While 1
    Sleep(10)
WEnd

Func _MyReceiver2($sMessage)
    MsgBox(0, 'IsProcessing', $sMessage, 1)
EndFunc   ;==>_MyReceiver2

Func _Exit()
    Exit
EndFunc   ;==>_Exit
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...