Jump to content
Sign in to follow this  
sandman

_MessageTerminal UDF :: Send messages between seperate scripts

Recommended Posts

sandman

Posted ImagePosted ImagePosted Image

NOTE: Thanks to PsaltyDS for the original idea in this post.

This is a very simple library, doing simple things, but hopefully increasing the usability of inter-script communication. This uses GUI labels (visible or invisible) as its main structure. Anyway, I'll just show the code.

#cs
_MessageTerminal Function Library

Function List:
    _MessageTerminalCreate()
    _MessageTerminalDelete()
    _MessageTerminalSend()
    _MessageTerminalGet()
#ce

#include <GUIConstants.au3>

#region _MessageTerminalCreate()
#cs
===============================================================================

Description:        Creates a message terminal.
Parameter(s):       $vControl: The variable (which a control will be created with).
                        $iVisible: 0 = Not visible. (Recommended)
                            1 = Visible. If for some reason, you want to show the user the message, choose this. It will be positioned at 0,0. You're better off just linking it with another label so you can position it, though.
                        $sText: Initial text.
Requirement(s):     None
Return Value(s):    On Success: Returns the handle to the message terminal.
                    On Failure: Returns 0.
Author(s):          sandman
Note(s):            

===============================================================================
#ce
Func _MessageTerminalCreate(ByRef $vControl, $iVisible = 0, $sText = "")
    If $iVisible = 1 Then
        $vControl = GUICtrlCreateLabel($sText, 0, 0)
        GUICtrlSetState($vControl, $GUI_SHOW)
    ElseIf $iVisible = 0 Then
        $vControl = GUICtrlCreateLabel($sText, 0, 0)
        GUICtrlSetState($vControl, $GUI_HIDE)
    EndIf
    Return $vControl
EndFunc
#endregion

#region _MessageTerminalDelete()
#cs
===============================================================================

Description:        Deletes a message terminal.
Parameter(s):       $hControl: The handle to the control.
Requirement(s):     None
Return Value(s):    On Success: Returns 1.
                    On Failure: Returns 0.
Author(s):          sandman
Note(s):            

===============================================================================
#ce
Func _MessageTerminalDelete(ByRef $hControl)
    GUICtrlDelete($hControl)
    If @error Then Return 0
    Return 1
EndFunc
#endregion

#region _MessageTerminalSend()
#cs
===============================================================================

Description:        Send a message to a message terminal.
Parameter(s):       $hControl: The handle to the control.
                        $sMessage: The message to send.
Requirement(s):     None
Return Value(s):    On Success:
                    On Failure:
Author(s):          sandman
Note(s):            

===============================================================================
#ce
Func _MessageTerminalSend(ByRef $hControl, $sMessage)
    GUICtrlSetData($hControl, $sMessage)
EndFunc
#endregion

#region _MessageTerminalGet()
#cs
===============================================================================

Description:        Receive data from a message terminal.
Parameter(s):       $sWinTitle: The title of the window containing the message terminal.
                        $sControlID: The ID of the control (you can get this by MsgBox'ing the handle, it should return a number.)
Requirement(s):     None
Return Value(s):    On Success: Returns the data of the message terminal.
                    On Failure: Returns -1.
Author(s):          sandman
Note(s):            

===============================================================================
#ce
Func _MessageTerminalGet($sWinTitle, $sControlID)
    Local $text = ControlGetText($sWinTitle, "", "[ID:" & $sControlID & "]")
    If @error Then Return -1
    Return $text
EndFunc
#endregion

I have also created an example archive if you would like to see this for yourself. Download the file below, and run Example.au3 and Example2.au3 simultaneously. IT NEEDS TO BE EXTRACTED!!

Posted Image _MessageTerminal.zip (2K) Number of downloads: Posted Image

And finally, the UDF alone:

Posted Image _MessageTerminal.au3 (3.2K) Number of downloads: Posted Image


[center]"Yes, [our app] runs on Windows as well as Linux, but if you had a Picasso painting, would you put it in the bathroom?" -BitchX.com (IRC client)"I would change the world, but they won't give me the source code." -Unknownsite . blog . portfolio . claimidcode.is.poetry();[/center]

Share this post


Link to post
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
Sign in to follow this  

×

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.