What happened to the Messenger Plus! forums on msghelp.net?
Shoutbox » MsgHelp Archive » Messenger Plus! for Live Messenger » Scripting » Download file

Download file
Author: Message:
SnuZZer
Full Member
***

Avatar

Posts: 114
32 / Male / Flag
Joined: Jun 2006
O.P. Download file
Hi.

I'm trying to make a script, which display an image in a window. I have searched on the forum and it seems that the only way to do this is to download the file using MsgPlus.DownloadFile and OnEvent_DownloadFileComplete, but I can't figure out how to use those functions.

This is my script:
code:
DownloadComic = "http://www.explosm.net/db/files/Comics/Matt/ive-got-some-homemade-stuff-for-that-wound-of-yours-too.png";

function OnEvent_Initialize(MessengerStart)
{
    MsgPlus.DownloadFile(DownloadComic);

    ComicWnd = MsgPlus.CreateWnd("comic.xml", "TodaysComic");
}

function OnEvent_DownloadFileComplete(DownloadComic, OutFile, Success)
{
    if(Succes)
    {
        MsgPlus.DisplayToast("Todays Comic", "Succes!");
    }
    else
    {
        MsgPlus.DisplayToast("Todays Comic", "Sorry, it didn't work.");
    }
}

Anyone who can help me download the file, please?

Thanks in advance

This post was edited on 10-31-2007 at 06:56 PM by SnuZZer.
10-31-2007 06:54 PM
Profile E-Mail PM Web Find Quote Report
Dempsey
Scripting Contest Winner
*****

Avatar
http://AdamDempsey.net

Posts: 2395
Reputation: 53
38 / Male / Flag
Joined: Jul 2003
RE: Download file
It could be because you've spelt success wrong:

if(Succes)   --->    if(Success)
SoundPacks   -   Scripts   -   Skins

that's not a bug, thats an unexpected feature
10-31-2007 06:57 PM
Profile E-Mail PM Web Find Quote Report
SnuZZer
Full Member
***

Avatar

Posts: 114
32 / Male / Flag
Joined: Jun 2006
O.P. RE: Download file
Oh, yes.. Embarrassing. But I'm also wondering how to find the path and put it into my .xml file.

EDIT: Seems like the path is just OutFile in OnEvent_DownloadFileComplete()

I have looked on the forums, but I can't find out how to solve my problem. I have tried this:

This is my script:
code:
var DownloadComic = "http://www.explosm.net/db/files/Comics/Matt/ive-got-some-homemade-stuff-for-that-wound-of-yours-too.png";

function OnEvent_Initialize(MessengerStart)
{
    MsgPlus.DownloadFile(DownloadComic);
}

function OnEvent_DownloadFileComplete(DownloadComic, OutFile, Success)
{
    if(Success)
    {
        MsgPlus.DisplayToast("Todays Comic", "Succes:\n" + OutFile);
       
        ComicWnd = MsgPlus.CreateWnd("comic.xml", "TodaysComic");
       
        ComicWnd.ImgElmt_SetImageFile("DisplayComic", OutFile);
    }
    else
    {
        MsgPlus.DisplayToast("Todays Comic", "Failed.");
    }
}

And this is my XML file:
code:
<Interfaces xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
   <Window Id="TodaysComic" Version="1">
        <Attributes>
            <Caption>Todays Comic</Caption>
    </Attributes>
        <Position Width="212" Height="112"/>
    <Elements>
        <Element xsi:type="ImageElement" Id="DisplayComic">
            <Position Top="0" Left="0"/>
            <Image>
            <Name></Name>
            </Image>
        </Element>
    </Elements>
        <WindowTmpl>
        <Corners Shape="Round">
            <RoundSize>3</RoundSize>
        </Corners>
        <Borders Type="Dialog"/>
        </WindowTmpl>
        <Controls>

        </Controls>
    </Window>
</Interfaces>

This post was edited on 10-31-2007 at 07:35 PM by SnuZZer.
10-31-2007 07:01 PM
Profile E-Mail PM Web Find Quote Report
markee
Veteran Member
*****

Avatar

Posts: 1622
Reputation: 50
36 / Male / Flag
Joined: Jan 2006
RE: Download file
How I do this in the script I am currently working on is put a loading image in by default and then change the image using the script later.  Also when you use the MsgPlus.DownloadFile you have to put in another function for when it is complete.  Here is an example of what you should do:
code:
function OnEvent_DownloadFileComplete(URL,OutFile,Success){
    if(Success){//Check if the download worked properly
        if(URL == "http://domain.com/path/to/image.png"){//Check that it was the file you wanted
            Wnd.ImageElmt_SetImageFile("IdOfTheImageElement","\\"+OutFile);//Put the new image into the image element
    }else{
        if(URL == "http://domain.com/path/to/image.png"){
            MsgPlus.DownloadFile(URL,"X:\\path\\where\\you\\want\\the\\image\\to\\go.png");//Redownload the file
        }
    }
}

I hope this helps, if you need more information about something then just ask.  There are more complex ways of doing things but I think this is fairly nice code :P
[Image: markee.png]
10-31-2007 11:04 PM
Profile PM Find Quote Report
SnuZZer
Full Member
***

Avatar

Posts: 114
32 / Male / Flag
Joined: Jun 2006
O.P. RE: Download file
It works! Many thanks! :-)

I know it's a little off-topic, but I thought it's better to ask here than making a new thread. Is it possible to resize the window in a script? Because the image isn't the same size everytime so I need to resize the window dependent on the size of the image.
11-01-2007 05:46 AM
Profile E-Mail PM Web Find Quote Report
Matti
Elite Member
*****

Avatar
Script Developer and Helper

Posts: 1646
Reputation: 39
32 / Male / Flag
Joined: Apr 2004
RE: Download file
If you know that your image is static and will never change, you're better off with adding it to your script package rather than having to download it over and over again.

  1. Copy your image to your script's Images directory. If the Images folder doesn't exist yet, create it. E.g.:
    quote:
    C:\Program Files\Messenger Plus! Live\Scripts\My Script\Images
  2. In your Windows XML, place the following in the <Elements> block of your window:
    code:
    <Element xsi:type="ImageElement" Id="ImgThing">
       <Position Left="5" Top="5" Width="50" Height="50">
          <Units>SizePixels</Units> <!-- This makes that you can set the width and height in pixels. You can also change this to AllPixels so everything is in pixels -->
       </Position>
       <Image>
          <Name>Image001</Name> <!-- The file name of the image, without extension. In this case, Plus! will look for "Image001.png" in the Images folder. -->
       </Image>
    </Element>
  3. Open your window and see if it turns out right. :) You can change the image of the element using PlusWnd::ImageElmt_SetImageFile, as described in markee's reply to Download file.

/me looks at last post...
Crap, it isn't static at all. :P Blah.

To resize a window:
code:
var Result = Interop.Call("user32.dll", "SetWindowPos", PlusWnd.Handle, 0, 0, 0, Width, Height, 18);
where:
  • PlusWnd = a PlusWnd object
  • Width = a number specifying the new width
  • Height = a number specifying the new height
The return value "Result" will be zero (0) if the function fails, else it'll be non-zero (1).

This post was edited on 11-01-2007 at 09:13 AM by Matti.
Plus! Script Developer | Plus! Beta Tester | Creator of Countdown Live | Co-developer of Screenshot Sender 5

Found my post useful? Rate me!
11-01-2007 08:38 AM
Profile E-Mail PM Web Find Quote Report
SnuZZer
Full Member
***

Avatar

Posts: 114
32 / Male / Flag
Joined: Jun 2006
O.P. RE: Download file
It works perfect! Thanks, but I still have one problem and it's "off-topic" (again). Isn't there a way to find an images widht and height?
11-01-2007 01:36 PM
Profile E-Mail PM Web Find Quote Report
« Next Oldest Return to Top Next Newest »


Threaded Mode | Linear Mode
View a Printable Version
Send this Thread to a Friend
Subscribe | Add to Favorites
Rate This Thread:

Forum Jump:

Forum Rules:
You cannot post new threads
You cannot post replies
You cannot post attachments
You can edit your posts
HTML is Off
myCode is On
Smilies are On
[img] Code is On