Shoutbox

Download file - 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: Download file (/showthread.php?tid=78566)

Download file by SnuZZer on 10-31-2007 at 06:54 PM

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
RE: Download file by Dempsey on 10-31-2007 at 06:57 PM

It could be because you've spelt success wrong:

if(Succes)   --->    if(Success)


RE: Download file by SnuZZer on 10-31-2007 at 07:01 PM

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>

RE: Download file by markee on 10-31-2007 at 11:04 PM

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
RE: Download file by SnuZZer on 11-01-2007 at 05:46 AM

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.


RE: Download file by Matti on 11-01-2007 at 08:38 AM

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).
RE: Download file by SnuZZer on 11-01-2007 at 01:36 PM

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?