DevMSN+

酷酷的MSN插件,随心所欲MSN

Messenger Plus! Live - Scripting Documentation

Working with Scripts

Windows for your Script

Depending on what your script is doing, user input may be required at some point. For that reason, a very special feature was added to the Messenger Plus! Live scripting system called Interface Windows. If you take a look at the various windows of Messenger Plus! Live itself, you'll notice that they tend to blend nicely into Windows Live Messenger, have similar looking controls, use the same background color etc... a brand new User Interface system was created during the conception of Messenger Plus! Live to achieve what you can see in the software, one that's not based on resource files but specially crafted XML files.

根据什么你的脚本是这样做,用户输入,可能需要在
一些点。出于这个原因,一个很特别的功能被添加到
Messenger Plus! Live脚本系统所谓的界面Windows 。如果你
看看在各种Windows的Messenger Plus! Live本身,您会发现
他们往往共混物好,到Windows Live Messenger的,也有类似的
展望管制,使用相同的背景颜色等..一个崭新的用户
界面系统创建期间,观Messenger Plus! Live
要达到什么你可以看到在软件之一,这并非基于
资源文件,但特制的XML文件。

The user interface system mentioned above can be accessed through scripting so your scripts can painlessly benefit from the whole interface engine. However, to use the system, you will need to get used to the way XML interface files are constructed and this may require a little bit of time. Interface files are not particularly complicated to understand, however, they contain a lot of different kinds of elements and attributes, some of them may not even be of any use to your scripts. The end result will be worth the trouble though as you won't need to create external DLLs to display your windows and you'll benefit from the current look of Windows Live Messenger as well as possible future updates. Your script will be guaranteed to appear just like any other Messenger Plus! window.

用户界面系统,上述可通过脚本,使您的
脚本可以painlessly受益于整个介面引擎。不过,使用
该系统,您将需要得到用来方式XML界面文件
兴建和这可能需要一点点的时间。接口文件是不是
尤其是复杂的理解,但是,它们包含了许多不同的
种元素和属性,他们中的一些人甚至有可能不会被任何使用
您的脚本。最终结果将是值得的麻烦,虽然您将不必
创造外部的DLL ,以显示您的Windows和您的利益,从
目前看Windows Live Messenger的以及未来可能的更新。你的
脚本将得到保证出现,就像任何其他Messenger Plus!窗口。

Interface Windows are created and displayed with a single call to MsgPlus.CreateWnd. The only parameters required for this function to succeed are the name of your XML interface file and the identifier of the window you want to create (each interface file can define more than one window). To demonstrate the feature, here is the XML definition of a simple window displaying "Hello World!". For now, don't try to understand the content of the text, just copy paste it to a plain text file called "InterfaceTest.xml" and save it in your script's directory.

界面Windows创建并显示一个单一的电话
msgplus.createwnd 。唯一的参数,需要履行这一职能的成功
是的名称,您的XML接口文件和身份标识的窗口您想要
创造(每个接口文件可以定义一个以上的窗口) 。以展示
功能,这里是XML定义一个简单的窗口,展示“世界您好! ” 。
现在,不尝试了解案文的内容,只要复制粘贴到一个
纯文本
文件中所谓的“ interfacetest.xml ” ,并储存在您的脚本的目录。

<Interfaces xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">

<
Window Id="WndTest" Version="1">
        <
Attributes>
            <
Caption>Test Window</Caption>         </Attributes>
        <
TitleBar>             <Title><Text>Hello!</Text></Title>         </TitleBar>
        <
Position ClientWidth="170" ClientHeight="45"/>         <DialogTmpl/>
        <
Controls>             <Control xsi:type="StaticControl" Id="LblTop">                 <Position Left="10" Top="10" Width="150"/>                 <Caption>Hello world!</Caption>             </Control>
            <
Control xsi:type="ButtonControl" Id="BtnClose">                 <Position Left="115" Top="25" Width="50"/>
                <
Caption>Close</Caption>             </Control>         </Controls>     </Window>
</
Interfaces>

Now, create a new script called "Window Test" and replace the Initialize event by the following code:

现在,创建一个新的脚本所谓的“窗口测试” ,并取代Initialize事件由以下
代码:

function OnEvent_Initialize(MessengerStart)
{
	var Wnd = MsgPlus.CreateWnd("InterfaceTest.xml", "WndTest");
}

Save the script. If you did alright, you'll see a window titled "Test Window" in your task bar (it may have been displayed below the script editor). This window's title show "Window Test - Hello!", with a "Hello world!" message and a "Close" button. Note that because every window created by Messenger Plus! is modeless, your script continues to run as soon as the window gets created. Now let's take a closer look to the XML file.

保存该脚本。如果您确实好吧,您会看到一个窗口,名为“测试窗口”
在您的任务栏(它可能已被显示以下的脚本编辑器) 。这个
窗口的标题显示“窗口测试-你好” ,与“世界您好! ”信息和
“关闭”按钮。请注意,因为每一个窗口所造成的信使
加!是模态,您的脚本继续运行,尽快窗口得到
创建。现在让我们采取细看,以XML文件。

First, a <Window> element is declared with two attributes: Id (used in your call to MsgPlus.CreateWnd to identify which window to show) and Version (just set it to "1" for now, this parameter will be used by future versions of Messenger Plus!).  Inside the <Window> element are a couple of interesting sub elements:

首先,
<window>内容是宣布与两个属性:
编号(用于在您的号召msgplus.createwnd
确定哪些窗口显示)和版本(刚才
将它设置为“ 1 ”现在,这个参数将用于未来版本的
Messenger Plus! )内<window>元
是一对夫妇有趣的小组要素:

  • <Attributes>. You'll often see this element in various other places. In a <Window> element it is used to define optional attributes for the window such as <Caption> (which is the caption of the window displayed in the task bar), <TopMost> (to make the window appear above every other), ...
  • <TitleBar>. Most Messenger Plus! windows display a title bar baring a Messenger Plus! logo, the name of the window and system buttons to minimize, maximum or close the window. Everything related to the title bar is defined in this element. If not specified otherwise, the name of the script will automatically be inserted in the title.
  • <Position>. Used to define the default width and height of the client area, this element can also be used to specify that the window can be resized. You may want to notice that the size is specified in Dialog Units, not Pixels. Every positions and sizes defined in interface files uses Dialog Units by default which allows the windows to adapt on various dpi settings (if this does not make any sense to you, forget about it).
  • <DialogTmpl>. This empty element is very important as it defines one of possible three choices for each window: dialog, window or child window. Most of your windows will probably be based on the dialog template which defines a double border and allows different kinds of extra settings such as a bottom bar.
  • <Controls>. This is where you'll define all the controls displayed in the window like static controls (text labels), buttons, checkboxes, lists, ...

Let's take a look at the controls defined in this window:

下面我们来看一看在管制的定义,在此窗口中:

  • Each control has the same basic structure. A control is always defined with a <Control> element and two mandatory attributes: xsi:type and Id. xsi::type specifies the kind of control that's being defined, like a a static control or a button. Id is the unique identifier of the control in the window. No control can have the same Id in a given window or the creation of the window will fail (remember that as it can easily be the cause of copy/paste frustrations). The Id can be anything you want but cannot contain any space character. Although it is considered to be a good practice to prefix your identifiers with the kind of control you're defining (like "Btn" for buttons), it is not mandatory.
  • Next comes <Position>. This element is required for any kind of control. The Left and Top attributes are always mandatory, Width is generally required too, however, Height can be optional for controls that don't need it. For example, in the case of a single line static control and a button, the Height parameter is automatically computed by Messenger Plus! to prevent inconsistencies through out the windows. You can always specify your own value though.
  • Elements that come after <Position> are generally type dependant, meaning that each kind of control has its own set of possible elements and attributes. Here, we see <Caption> being used in both controls, however, we could also have used <BackgroundColor> for the static control and <Image> for the button which are elements reserved for each type of control respectively.

Now, you may be wondering "how am I supposed to know and remember all these elements and attributes names?"... the good news is that you don't have to, as long as you're using a good XML editor such as XMLSpy from Altova. Every XML file can be paired with its corresponding schema file which defines every possible element and attribute that can be inserted in the XML. Schema files also come with various comments to help you understand the purpose of some elements and attributes, when deemed necessary. In the case of XMLSpy, the editor also provides contextual help so you'll get lists of choices while you type your XML. These are all good reasons NOT to code your windows inside notepad so please, do yourself a favor and use a specialized XML editor to do the job :). The Interface Windows schema file and its documentation can be found in the schema reference section of this documentation.

现在,您可能想知道“我怎样知道并记住所有这些
元素和属性的名字?"...好消息是,你不
有,只要您使用了良好的XML编辑器,如

xmlspy从altova 。每一个XML文件可以搭配其相应的
架构文件,该文件确定了一切可能的元素和属性可以
在插入的XML 。架构文件,也与各种意见,以帮助您
了解的目的,一些元素和属性,在认为必要时。
在该案件xmlspy ,编辑
还提供了内容相关的说明,让您得到的名单选择,而您输入
XML的。这些都是很好的理由不守则您的Windows记事本内,以便
请,做自己的一种恩赐,并使用一个专门的XML编辑器做的工作: ) 。
界面的Windows架构文件和文件可以发现,在
架构参考一节的
文件。

Of course, the windows would be useless if you had no way to hear back from them. A special set of events was created for that occasion prefixed "OnWindowidEvent_". Notice how "WindowId" is written in italic: to avoid mixing the events coming from different windows, Messenger Plus! fires events named after the corresponding window's Id. In the case of our test window, all events will be prefixed "OnWndTestEvent_". A list of available events can be found in the events' reference but let's test this simply with a common purpose event: "CtrlClicked". This event is fired every time a control such as a button is clicked. You may already have noticed that clicking on "Close" in the test window currently does nothing, that's because the current code does not catch the "clicked" event for the button. Let's fix this by adding the following function at the end of the script:

当然,在Windows ,将无用的,如果你没有办法听到回
他们。一套特别的活动,已创建为当时的前缀“ onwindowidevent_ ” 。
通知如何“ windowid ”是写在斜体:为了避免混合
事件从不同的Windows ,Messenger Plus!火灾事件后,命名
相应的窗口的ID 。在该案件我们的测试窗口,所有活动将
前缀“ onwndtestevent_ ” 。名单提供的事件可以发现,在
事件的参考,但让的测试,这只是一个共同目的一起事件: “ ctrlclicked ” 。
此事件是每一个发射时间控制,如一个按钮,按下。您可能
已经注意到,点击“关闭”在测试窗口,目前并
从无到有,这是因为目前的守则并没有赶上“点击”事件
按钮。让我们解决此问题加入以下功能在去年底的
脚本:

function OnWndTestEvent_CtrlClicked(Wnd, ControlId)
{
	if(ControlId == "BtnClose")
		Wnd.Close(1);
}

The first parameter of the event is a PlusWnd object (the object representing your window) and the second one is the Id of the control that fired the clicked event. The function above checks if the event comes from the "Close" button (which has an Id equal to "BtnClose") and if so, calls the Close function of the PlusWnd object. The numeric parameter sent in Close is of no consequence and is just passed to the Destroyed event in case you would want to handle different types of close scenarios.

第一个参数的事件是一个pluswnd对象(对象代表
您的窗口)和第二个,一个是控制项的ID说,发射点击
事件。功能上述检查,如果事件是来自“关闭”按钮(已
一个ID等于“ btnclose ” )和若有,调用
关闭功能的pluswnd
对象。数字参数发送密切的是没有后果,是
刚刚通过了向被炸毁的事件在情况下,您将要处理的不同
类型的密切情景。

You can now experiment working with different kinds of controls and calling various functions from the PlusWnd object. A lot of possibilities are offered by this system and it is now up to you to discover them. Because this subject is an important and complex one, you should not hesitate to seek help in the official Messenger Plus! forum. Remember to spend time in the Interface Windows Reference too and practice! And finally, a special tool is also available to help you test your windows out of the Messenger environment, for more information, check out Testing your Windows.

See Also

Testing your Windows, Interface Windows Reference, PlusWnd Object, Interface Windows Events Reference.

  Sponsor

  Links

Scripts文档目录 脚本库 FAQ
copyright devmsn.com