Shoutbox

HELP - Window control to Script Variable! - Printable Version

-Shoutbox (https://shoutbox.menthix.net)
+-- Forum: MsgHelp Archive (/forumdisplay.php?fid=58)
+--- Forum: Messenger Plus! for Live Messenger (/forumdisplay.php?fid=4)
+---- Forum: Scripting (/forumdisplay.php?fid=39)
+----- Thread: HELP - Window control to Script Variable! (/showthread.php?tid=89233)

HELP - Window control to Script Variable! by whiz on 02-17-2009 at 12:30 PM

How can I set a variable to collect its contents from a window control?

Example: A user types in "test" in a text area, called "EdtMessage", within a script window.  When they click Save, it is stored in a variable called "message", and a toast appears with the "test" message inside.


RE: HELP - Window ontrol to Script Variable! by mynetx on 02-17-2009 at 12:41 PM

jscript code:
var message;

function OnYourWindowIdEvent_CtrlClicked(objWnd, strControlId) {
    switch(strControlId) {
        case "BtnSave":
            message = objWnd.GetControlText("EdtMessage");
            MsgPlus.DisplayToast("Your script", message);
            // want to close the window? uncomment the following line
            // objWnd.Close(1);
            break;
    }
}

RE: HELP - Window control to Script Variable! by whiz on 02-17-2009 at 01:46 PM

Works great, thanks!  :D

Another question.  Well, three linked questions.  How can you create a window resizable in width but not height?  Can you set a default, maximum and minimum size for it?  And can you set a control (like a text box) width to 100%, so that it stretches across the whole window all the time?


RE: HELP - Window control to Script Variable! by matty on 02-17-2009 at 01:57 PM

You are going to need to use the following

xml code:

<Window>
    <Position>
        <Resizable Allowed="Verticle">
            <MinWidth>50</MinWidth>
            <MinHeight>50</MinHeight>
        </Resizable>
    </Position>
</Window>

Obviously some fields are left out but you get the idea... note that all the above information is avabile in the scripting documentation you can download...

As for the other question yes you can you just need to initially set the width to stretch then use an anchor on the left and right and bottom.
RE: HELP - Window control to Script Variable! by whiz on 02-18-2009 at 10:54 AM

Okay, thanks.

And another thing...  going back to the original question, I have a window for my Instant Response script so that you can change the message/timer.  Is it possible for it to show the current message/timer, set by the user, in the text box by default?


RE: HELP - Window control to Script Variable! by mynetx on 02-18-2009 at 11:00 AM

jscript code:
objWnd.SetControlText("EdtTimer", strYourTextToSet);

RE: HELP - Window control to Script Variable! by whiz on 02-18-2009 at 11:18 AM

Okay, but...

1) What function would that be?  Would it be like "function OnWndTimerEvent_Created(objWnd, strControlId)", or does it go in the "function OnWndTimerEvent_CtrlClicked(objWnd, strControlId)"?
2) Do I replace "YourTextToSet" with the script variable?


RE: HELP - Window control to Script Variable! by matty on 02-18-2009 at 12:19 PM

Well you would want to set the text after the widow loads right...

And yes the the second question...


RE: HELP - Window control to Script Variable! by whiz on 02-18-2009 at 04:02 PM

Argh...  nothing's happening!  :(

I've looked in the Scripting Documentation, and there isn't a function for "on the opening of a window", so how do I do it?


RE: HELP - Window control to Script Variable! by matty on 02-18-2009 at 04:12 PM

You are correct there is no event for a window created... but when you create a Window you can assign the Windows object to a variable...

js code:
var s = 'this is some text';
var oMyWindow = MsgPlus.CreateWnd('...', '...');
oMyWindow.SetControlText('NameOfTheControl', s);

Reading the documentation fully will help make a lot of sense of things...
RE: HELP - Window control to Script Variable! by whiz on 02-18-2009 at 04:47 PM

Finally, it works!  :D

Although, how do you use this on a check box?  Can it be applied to a true/false variable, because I have tried that, and that doesn't seem to do anything, in terms of what it's supposed to.

Perhaps the code below will help to explain.  This is the bit where it does commands based on what button you press.  The highlighted bit refers to a checkbox in a window.

js code:
var settingEnable = false;
var settingMessage = "/nudge";
var settingTimer = "1000";
var setnoteMesCmd = true;
var setMsgPlusAM = true;
var setSignInAlert = true;

function OnWndControlEvent_CtrlClicked(objWnd, strControlId)
{
    switch(strControlId)
    {
        case "BtnEnable":
            if (settingEnable)
            {
            }
            else
            {
                settingEnable = true;
                var Message = "Activation: enabled";
                Message = MsgPlus.RemoveFormatCodes(Message);
                MsgPlus.DisplayToast("Instant Response", Message);
                Debug.Trace("Instant Response  |  Activation: enabled");
            }
            break;
        case "BtnDisable":
            if (settingEnable)
            {
                settingEnable = false;
                var Message = "Activation: disabled";
                Message = MsgPlus.RemoveFormatCodes(Message);
                MsgPlus.DisplayToast("Instant Response", Message);
                Debug.Trace("Instant Response  |  Activation: disabled");
            }
            else
            {
            }
            break;
        case "BtnSave":
            if (settingMessage==objWnd.GetControlText("EditMessage"))
            {
            }
            else if (objWnd.GetControlText("EditMessage") == "")
            {
                var Message = "New message was not set:\n message was left blank!";
                Message = MsgPlus.RemoveFormatCodes(Message);
                MsgPlus.DisplayToast("Instant Response", Message);
                Debug.Trace("Instant Response  |  New message was not set: message was left blank!");
            }
            else
            {
                settingMessage = objWnd.GetControlText("EditMessage");
                var Message = "New message: " + settingMessage;
                Message = MsgPlus.RemoveFormatCodes(Message);
                MsgPlus.DisplayToast("Instant Response", Message);
                Debug.Trace("Instant Response  |  New message: " + settingMessage);
                setnoteMesCmd = (/^\/[^\s\/]+\s*[\s\S]*$/.test(settingMessage));
                objWnd.Close(1);
                break;
            }
            if (settingTimer==objWnd.GetControlText("EditTimer"))
            {
                var Message = "New timer was not set:\n timer was left blank!";
                Message = MsgPlus.RemoveFormatCodes(Message);
                MsgPlus.DisplayToast("Instant Response", Message);
                Debug.Trace("Instant Response  |  New timer was not set: timer was left blank!");
            }
            else if (objWnd.GetControlText("EditTimer")=="")
            {
                var Message = "New timer was not set:\n timer was left blank!";
                Message = MsgPlus.RemoveFormatCodes(Message);
                MsgPlus.DisplayToast("Instant Response", Message);
                Debug.Trace("Instant Response  |  New timer was not set: timer was left blank!");
            }
            else if (objWnd.GetControlText("EditTimer")<100)
            {
                var Message = "New timer was not set:\ntimer was under 100ms!";
                Message = MsgPlus.RemoveFormatCodes(Message);
                MsgPlus.DisplayToast("Instant Response", Message);
                Debug.Trace("Instant Response  |  New timer was not set: timer was under 100ms!");
            }
            else if (typeof parseInt(objWnd.GetControlText("EditTimer")) === 'number' ? parseInt(objWnd.GetControlText("EditTimer")) : 0)
            {
                settingTimer = objWnd.GetControlText("EditTimer");
                var Message = "New timer: " + settingTimer + "ms";
                Message = MsgPlus.RemoveFormatCodes(Message);
                MsgPlus.DisplayToast("Instant Response", Message);
                Debug.Trace("Instant Response  |  New timer: " + settingTimer + " milliseconds");
                objWnd.Close(1);
                break;
            }
            else
            {
                var Message = "New timer was not set:\ntimer used invalid characters!";
                Message = MsgPlus.RemoveFormatCodes(Message);
                MsgPlus.DisplayToast("Instant Response", Message);
                Debug.Trace("Instant Response  |  New timer was not set: timer used invalid characters!");   
            }
>>>            if (setMsgPlusAM==objWnd.GetControlText("ChkPlusAMStyle"))<<<
>>>            { <<<
>>>            } <<<
>>>            else <<<
>>>            { <<<
>>>                setMsgPlusAM = objWnd.GetControlText("ChkPlusAMStyle"); <<<
>>>                var Message = "Plus! style: " + setMsgPlusAM; <<<
>>>                Message = MsgPlus.RemoveFormatCodes(Message); <<<
>>>                MsgPlus.DisplayToast("Instant Response", Message); <<<
>>>                Debug.Trace("Instant Response  |  Plus! style: " + setMsgPlusAM); <<<
>>>            } <<<
            objWnd.Close(1);
        case "BtnCancel":
            objWnd.Close(1);
            break;
    }
}

RE: HELP - Window control to Script Variable! by matty on 02-18-2009 at 05:26 PM

No offense but you need to read the documentation...

Button_SetCheckedState
Button_IsChecked


RE: HELP - Window control to Script Variable! by whiz on 02-18-2009 at 05:51 PM

Ok, I get it now.  Thanks...

And I will check through the Documentation first, next time...  :)