Shoutbox

Progresbar - 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: Progresbar (/showthread.php?tid=77510)

Progresbar by Drakal on 09-15-2007 at 05:10 PM

How do i do a progress bar? i have added a download feature on my skript but i cant see how much that is downloaded or how long time it is to its finished.


RE: Progresbar by Matti on 09-15-2007 at 05:41 PM

Here are some progress bar functions:

code:
function Progress_GetPos(PlusWnd, CtrlId) {
    return PlusWnd.SendControlMessage(CtrlId, /*PBM_GETPOS*/ 0x408, 0, 0);
}

function Progress_SetPos(PlusWnd, CtrlId, nNewPos) {
    return PlusWnd.SendControlMessage(CtrlId, /*PBM_SETPOS*/ 0x402, nNewPos, 0);
}

function Progress_SetStep(PlusWnd, CtrlId, nStepInc) {
    return PlusWnd.SendControlMessage(CtrlId, /*PBM_SETSTEP*/ 0x404, nStepInc, 0);
}

function Progress_StepIt(PlusWnd, CtrlId) {
    return PlusWnd.SendControlMessage(CtrlId, /*PBM_STEPIT*/ 0x405, 0, 0);
}

//Usage example
var nPos = Progress_GetPos(oPlusWnd, "PrgDownload");
Progress_SetPos(oPlusWnd, "PrgDownload", nPos+10);

However, the actual position is hard to find. In fact, you should use a timer which gets the current file size of the downloaded file, divides that by the total file size to be downloaded and multiplies that by 100 to get the percentage. The catch is that you can't easily get the total file size, you'd need a text file on the server containing the file size to actually know how big the file to be downloaded is.

Actually, I don't really know if this is true, so if anyone can proof me wrong and provide me a way to get the file size of the server file, please tell me! :)
RE: Progresbar by Drakal on 09-15-2007 at 06:00 PM

didnt undersand anyting of the first :P do i need a xml file or anything?


RE: Progresbar by Flash on 09-15-2007 at 11:28 PM

Interface Windows Schema Documentation

complexType ProgressControl diagram 


RE: Progresbar by Matti on 09-16-2007 at 06:37 AM

Sorry, I understood your question as how to interact with an existing ProgressControl.

You'll first need to add this in your window:

code:
<Control xsi:type="ProgressControl" Id="PrgDownload">
   <Postion Left="10" Top="10" Width="150" Height="25"/>
</Control>
Then, whenever you need to get or change the position, use Progress_GetPos or Progress_SetPos. Alternatively, you could first set the step increment with Progress_SetStep and then use Progress_StepIt to step further.
RE: Progresbar by Drakal on 09-16-2007 at 08:39 AM

Thank you Mattike but your control didnt work(fixed it on my self) and i got it to move from 0 to 100% when i download a file but without a timer(used my crazy other ways:P)... but to fix i timer... :P the timer i already has dont work any more so can you give me a basic lesson in timers?(feel like a nood :( )


RE: Progresbar by Matti on 09-16-2007 at 10:01 AM

Well, first you need to create one with

code:
MsgPlus.AddTimer("MyTimer", 500);
This will create a timer called MyTimer with an interval of 500 milliseconds.

Then, you need an event:
code:
function OnEvent_Timer(sTimerId) {
if(sTimerId == "MyTimer") {
   //Do progress bar stuff here
   MsgPlus.AddTimer("MyTimer", 500); //Repeat
}
}
This will create a "timed loop", and when you're done with it, you need to stop the timer with MsgPlus.CancelTimer("MyTimer") and make sure that MsgPlus.AddTimer doesn't get called again. :)
RE: Progresbar by Drakal on 09-16-2007 at 12:02 PM

thx.. now i se that my old timer didnt loop :P but what should "oPlusWnd" be? window worked befor and window was  msgplus.createwnd(....) but now in timer it just opens alot of windows until it reaches 100%


RE: Progresbar by Matti on 09-16-2007 at 05:25 PM

quote:
Originally posted by Drakal
thx.. now i se that my old timer didnt loop :P but what should "oPlusWnd" be? window worked befor and window was  msgplus.createwnd(....) but now in timer it just opens alot of windows until it reaches 100%
You'll need to create a global variable and set that to the created window, and when it's destroyed you clear the variable again. When you declare it as global, you can use it wherever you like. I think you'll understand it better with the following style example:
code:
var MainWnd = false;

function OpenThingy() {
   MainWnd = MsgPlus.CreateWnd("XML", "WINDOWID");
   //Other stuff, like the timer
   Progress_SetStep(MainWnd.Handle, "PROGRESS", 10);
   MsgPlus.AddTimer("MyTimer", 500);
}

function OnEvent_Timer(sTimerId) {
   if(sTimerId == "MyTimer" && MainWnd != false) {
      //Do timer stuff
      Progress_StepIt(MainWnd.Handle, "PROGRESS");
      //Re-create timer
      MsgPlus.AddTimer("MyTimer", 500);
   }
}

function OnWINDOWIDEvent_Destroyed(PlusWnd) {
   MsgPlus.CancelTimer("MyTimer"); //Cancel timer
   MainWnd = false; //Clear global variable
}

RE: Progresbar by Drakal on 09-17-2007 at 01:43 PM

code:
function Progress_SetStep(PlusWnd, CtrlId, nStepInc) {
return PlusWnd.SendControlMessage(CtrlId, /*PBM_SETSTEP*/ 0x404, nStepInc, 0);
}
it is some thing wrong in this code. debug says something about objects on the line "return PlusWnd.SendCont...." :S
RE: Progresbar by Matti on 09-17-2007 at 05:05 PM

Woops, my mistake. Leave out the ".Handle" after each "MainWnd" occurence. :)


RE: Progresbar by Drakal on 09-17-2007 at 08:31 PM

it dont works :( but you can do a script that have a progress bar. the progress bar widow opens at start-up and moves 10% every timer loop... so i see whats wrong :P it will be easier and faster than if  u explain every little thing for me xD


RE: Progresbar by Matti on 09-18-2007 at 04:54 PM

Alright then, here you go! :)
Tested, working and with explaining comments. ;)


RE: Progresbar by Drakal on 09-18-2007 at 07:28 PM

thx alot Mattike :D i will add you in my about window in the thx to list with two other :P