Shoutbox

Loading a external image - 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: Loading a external image (/showthread.php?tid=72225)

Loading a external image by Yorick on 03-01-2007 at 05:00 PM

Hello,

While I was working on my Last.fm for Messenger Plus! Live I realized that I wasn't able to display an image from an internet location in a window. Maybe it's possible, but I don't know how... anyone?

Thanks in advance,
Yorick


RE: Loading a external image by Matti on 03-01-2007 at 05:24 PM

First you should download the file to a temporany location, which you can do with the new MsgPlus.DownloadFile function. Then, you can use PlusWnd.ImageElmt_SetImageFile to change the image displayed. Don't forget to delete your file afterwards! ;)


RE: Loading a external image by matty on 03-01-2007 at 06:03 PM

quote:
Originally posted by Mattike
First you should download the file to a temporany location, which you can do with the new MsgPlus.DownloadFile function. Then, you can use PlusWnd.ImageElmt_SetImageFile to change the image displayed. Don't forget to delete your file afterwards! ;)
However when you are setting the Image from a location that is not in your Scripts folder you need to prefix the path with a \.

For instance if you saved your image to C:\Temp and it was called myimage.jpg the code would be:
code:
pPlusWnd.ImgElmt_SetImageFile('myimage', '\\C:\\Temp\\myimage.jpg');

RE: Loading a external image by Yorick on 03-02-2007 at 06:53 PM

Thanks a lot guys!

Almost worked it out now, but I still have a bit of a problem.
I have the following code:

code:
WndProfileInformation = MsgPlus.CreateWnd('WndProfileInformation.xml', 'WndProfileInformation');

if(MsgPlus.DownloadFile(avatar))
{
    Debug.Trace('[Download] Started');
}
else
{
    Debug.Trace('[Download] Failed');
}


And then you have to use the OnEvent_DownloadFileComplete(), but how do I append the image to the above made window? How can I get the WndProfileInformation window in the  OnEvent_DownloadFileComplete function?

code:
function OnEvent_DownloadFileComplete(Url, OutFile, Success)
{
    if(Succes)
    {
        WndProfileInformation.ImgElmt_SetImageFile('ImgDisplayPic', OutFile);
        var File = new ActiveXObject("Scripting.FileSystemObject");
        File.DeleteFile(OutFile);
    }
}


RE: Loading a external image by CookieRevised on 03-02-2007 at 07:01 PM

Each and every variable in a script needs to be declared somewhere. This is done using the var statement.

eg:

code:
var MyVar = "Hello World";


If you declare a variable inside a function, it is a local variable. The variable will only exist as long as the function runs. When the function ends, the variable will not exist anymore.

eg:
code:
function DoSomething() {
    var MyLocalVar = "Hello World"
}

If you declare a variable in the main scope of the script, thus outside any functions, it is a global variable. The variable will exist as long as the script is running and thus can be used from anywhere in the script, including from inside funtcions...

eg:
code:
var MyGlobalVar = "Hello World"

function DoSomething() {
    //blahblah
}



Short answer: declare WndProfileInformation as a global variable.
RE: Loading a external image by Yorick on 03-02-2007 at 07:04 PM

At the top of the script I have

code:
var WndProfileInformation;

Is this not enough? So in the function I only use

code:
WndProfileInformation.ImgElmt_SetImageFile('ImgDisplayPic', OutFile);


But for some reason I can't use it in the download function...


EDIT: Made a mistake in the function name...

It works quit good now, but I use the following code now:
code:
function OnEvent_DownloadFileComplete(Url, OutFile, Success)
{
    if(Success)
    {
        Debug.Trace('File: ' + OutFile);
        WndProfileInformation.ImageElmt_SetImageFile('ImgDisplayPic', OutFile);
    }
}


But It doesn't show it in the element, but there does change something. The default image is removed, but the new image is not shown... Do I have to do anything with the OutFile path? Maybe add some slashes...

EDIT2: Missed Marty's post, just had to add to slashes before the path, it works great now! Thanks guys :D!
RE: Loading a external image by Matti on 03-02-2007 at 07:23 PM

quote:
Originally posted by CookieRevised
Short answer: declare WndProfileInformation as a global variable.
And this should be done when you create the window, like in:
code:
WndProfileInformation = MsgPlus.CreateWnd("thing.xml", "WndProfileInformation");
The difference here is the missing "var" prefix, without it it'll get declared as a global variable.

Note: when the window is destroyed, you should delete the variable too!
RE: Loading a external image by Yorick on 03-02-2007 at 07:32 PM

I don't know if I need to open a new topic about this, please say if I need to!

I bumped into another problem. I want to show some information, but I don't always have all the information....

Like this:
Profile:
Name
Country (optional)
Age (Optional)

But sometimes I don't have information to fill the country, and I do have information to fill the age. If I do it with static controls, you'll get a gap, because I can't fill country.. anyone a brilliant idea how to do this?


RE: RE: Loading a external image by CookieRevised on 03-02-2007 at 09:13 PM

quote:
Originally posted by Mattike
quote:
Originally posted by CookieRevised
Short answer: declare WndProfileInformation as a global variable.
And this should be done when you create the window, like in:
code:
WndProfileInformation = MsgPlus.CreateWnd("thing.xml", "WndProfileInformation");
The difference here is the missing "var" prefix, without it it'll get declared as a global variable.

Note: when the window is destroyed, you should delete the variable too!

Personally I would not recommend declaring variables like that. It is bad practice and prone to errors/bugs if you're not carefull.

Always use var and always declare your global variables outside functions first.


quote:
Originally posted by Yorick
I want to show some information, but I don't always have all the information....

Like this:
Profile:
Name
Country (optional)
Age (Optional)

But sometimes I don't have information to fill the country, and I do have information to fill the age. If I do it with static controls, you'll get a gap, because I can't fill country.. anyone a brilliant idea how to do this?
we need far more information to answer this question properly as there are billions of things which you can mean or want to do.


With the information given all I can say is if you don't have the info then don't display it and use a description prefix.
eg:
Profile
    Name: John
    Country:
    Age: 25



EDIT: after seeing your other thread, I understand what you mean. hint: always provide enough details from the start ;)

PS: a control is in that context always static... no control moves around on their own. Static means 'user can not interact with it' (eg: a text label), opposed to dynamic which is changeable by the user (eg: a combobox). Thus it doesn't have anything todo with moving.


Anyways,

Or you could simply move controls, but this will require the use of Windows APIs. This is possible, but certainly not elegant for this purpose.

Or you could instead of making 3 static labels, just make 1 static label and fill it with a string which is a concatenation from the individual variables seperated with a newline character (\n).

eg:
code:
var Name = "John";
var Country = "";
var Age = "25";
var ShoeSize = "5";
var Fingers = "10"
var State = "Married";

var Profile  = ""; // String to display in first and only label control

If (Name !== "") Profile += "\n" + Name;
If (Country !== "") Profile += "\n" + Country;
if (Age !== "") Profile += "\n" + Age + (Age == 1 ? " year" : " years");
if (ShoeSize !== "") Profile += "\n" + ShoeSize;
if (Fingers !== "") Profile += "\n" + Fingers;
if (Sate !== "") Profile += "\n" + State;

// Remove first NewLine character
Profile = Profile.substr(1);

// Set control text
wndProfileWindow.SetControlText("lblProfile", Profile);
PS: Also notice what I've done with the age. That line adds either "years" or "year" according to what the age is (if age is 1 it will add "year"; thus without the s).

(Age == 1 ? " year" : " years") is called a ternary operation. It is in fact an IF THEN ELSE but written as a single statement on one line. The shown ternary operation is the same as if you would write:
code:
if (Age == 1) {
    return " year"
}
else {
    return " years"
}

RE: RE: RE: Loading a external image by Eljay on 03-02-2007 at 09:23 PM

quote:
Originally posted by CookieRevised
quote:
Originally posted by Mattike
quote:
Originally posted by CookieRevised
Short answer: declare WndProfileInformation as a global variable.
And this should be done when you create the window, like in:
code:
WndProfileInformation = MsgPlus.CreateWnd("thing.xml", "WndProfileInformation");
The difference here is the missing "var" prefix, without it it'll get declared as a global variable.

Note: when the window is destroyed, you should delete the variable too!

Personally I would not recommend declaring variables like that. It is bad practice and prone to errors/bugs if you're not carefull.

Always use var and always declare your global variables outside functions first.


I think he was referring to removing the var from the statement inside the function so instead of creating a local variable, it would set the already existing global variable.