Shoutbox

General Help with Interfaces - 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: General Help with Interfaces (/showthread.php?tid=79490)

General Help with Interfaces by Crazed on 11-30-2007 at 06:27 AM

Hey all,

I'm relatively new to Plus scripting and totally new to the Win32 API (but not JavaScript or programming in general) and I was wondering if anyone could offer me a little direction.

I'm not asking for a complete solution, but I'm having a few problems conceptualizing and designing a window (and more specifically, what goes into it). I've read the documentation for creating scripts, but I find its information on the interface files to be, while informative, not very friendly.

The situation is a script that needs to dynamically create N number of rows (set by another XML file, but that's irrelevant to this topic) of three columns, each containing a label and two text boxes, in the window. So, what I need is some type of control(s) that can be added on the fly.

I've tried using a ListView for this, but I find I can make only the first column editable, and even being able to edit that column is not consistent. So, my first question is "Can I use a ListView, and if so, what am I doing wrong?"

If a ListView is not what I need for this situation, then my second question is "what are the right controls for this situation?"

In any case, is there any more information on some of the controls found in the interface schema that is easy to digest for someone who hasn't worked with the API before? Because honestly, I've just been piecing things together on my own, which is totally fine for something which I understand (scripting for example), but is quite a bit harder for a technology to which I am a relative novice.

Please let me know if you can help me with this, or if I'm not making any sense. Thanks. :)

(Just to let you know in case you're interested, the script started as a simple dice roller and is turning into a complete DnD supplemental tool to help while playing sessions in MSN. It's turning out quite well, and this window is for generating characters)


RE: General Help with Interfaces by Toneo on 11-30-2007 at 07:30 PM

Hmm.

First, to create your window:
var Wnd = MsgPlus.CreateWnd('XMLFile.xml','WindowIdentifier');
This creates your window, and it can be accessed through Wnd, as declared.

I also recommend you have your window initialization code in a seperate function for flexibility.

And to add items to a ListView, use this.

Wnd.LstView_AddItem("ListView","MainText",Data[Number],Position[Number]);
Note: Parameters Data and Position are optional!

Okay, so say you wanted to add three items, you could do this in two ways.

Way one:

var Wnd = MsgPlus.CreateWnd('XMLFile.xml','WindowIdentifier'); //Initialize Window!
Wnd.LstView_AddItem("ListView","Item 1",0); //Add Item 1
Wnd.LstView_AddItem("ListView","Item 2",1); //Add Item 2
Wnd.LstView_AddItem("ListView","Item 3",2); //Add Item 3

// And repeat for each item. 0, 1, 2 .etc are the data for each element

Way two:

var Wnd = MsgPlus.CreateWnd('XMLFile.xml','WindowIdentifier'); //Initialize Window!
var items = new Array('ItemOne','ItemTwo','ItemThree','ItemFour','ItemFive');

for (i=0; i<=items.length; i++)
{
Wnd.LstView_AddItem("ListView",items[i],2); //Add Item based on array
}

Hopefully that helped! If you have any other problems ask me.
Although I don't think I answered your question correctly, did I?


RE: General Help with Interfaces by Crazed on 11-30-2007 at 07:50 PM

Thanks for the quick reply! Believe it or not, that's precisely what I'm doing right now to test this method. This is the code I'm using:

code:
function OpenNewProfileWindow() {
    var Wnd = MsgPlus.CreateWnd("InterfaceTest.xml", "ProfileChooser");
    Wnd.Combo_SetCurSel("ChooseProfile", Wnd.Combo_AddItem("ChooseProfile", "Dungeons and Dragons 3.5"));
    var item =Wnd.LstView_AddItem("ListViewer", "Test");
    Wnd.LstView_SetItemText("ListViewer", item, 0, "Test 1");
    Wnd.LstView_SetItemText("ListViewer", item, 1, "Test 2");
    Wnd.LstView_SetItemText("ListViewer", item, 2, "Test 3");
}

That quick and dirty code isn't made for release, but I'm just doing it to see how the controls work. That does work as intended, except for one thing: I can't get the fields to be editable. I've attached the interface I've made.

Here's a picture for reference of what it looks like right now.
[Image: plus-dialog1.jpg]

I can't edit or select any of the columns except for the first one, and even that doesn't always work. The user needs to be able to edit the last two columns.


If you could tell me how to do that, I would be very grateful. At least I'm thinking in the right direction so far, I think. :)
RE: General Help with Interfaces by Toneo on 11-30-2007 at 07:54 PM

Well, what you're making looks pretty cool.
Ah. And editing different columns is where i'm stuck too. I'm trying to find out how to edit a column other than the first, but so far i've had no luck. :( But i'm still trying to figure it out.

Oh, and if you need help saving these "Profiles" onto the computer, I can help you if you'd like. :)

Also: I think there's another way, using multiple listboxes that change together, but I would suggest leaving that until we're sure that columns other than the first can be accessed.


RE: General Help with Interfaces by Crazed on 11-30-2007 at 08:23 PM

Thanks, I hope it'll turn out alright when it's done - after I get this part down and do a few more things, it should be ready for a public release. Originally I made it for a few friends and I, but it should be a good general release.

Let me know if you find out anything new about the text. :) I had some problems with ListBoxes. I couldn't get one to display properly. What are they compared to ListViews?

As for saving the profiles, I *should* be alright. I'm pretty good with the DOM and hopefully creating an XML file from scratch should be no problem in JScript. Information like that I can piece together. I'll let you know if I have any problems, though, when we get to that point.


RE: General Help with Interfaces by Toneo on 11-30-2007 at 08:41 PM

Okay. Note, it's not JavaScript, it's JScript 5.6 (or something like 5.6).

If you want to edit the FileSystem you'll need to use ActiveXObject();.

ListBoxes, compared to ListViews, are just single boxes that can list stuff just rows rather than boxes that have rows and columns.

I was going to attach a ListBox version but the script suddenly decided to play up and throw up the evil "null is null or not an object" error... which I get A LOT. :@


RE: General Help with Interfaces by Crazed on 12-01-2007 at 01:58 AM

Have you had any luck? I did some searching, and it appears from other sites (ones about VB, mostly) that only the first column is editable. If I do do different boxes for them instead of a ListView, how will I dynamically create as many as I need?

Thanks. :)


RE: General Help with Interfaces by Toneo on 12-01-2007 at 07:46 AM

I've also searched, and no, I don't think you can edit any but the first column. What a silly thing to do. I hope they add a feature to change any column.

ListBoxes do seem like a good idea, unfortunately you can't dynamically change the amount of listboxes unless you find a way to edit the XML file dynamically and then redraw the window.

Actually, I think that's possible. Here's a [Link] to the FileSystem tutorial i've made. Even if you think you know how you should use it to refresh your memory. =)

As for redrawing the window (to show the new ListBoxes) I think that if you search you'll find that Interop.Call() can help you. But I can't remember the complete command from the top of my head.

I hope what you're making goes well, though! :D


RE: General Help with Interfaces by Matti on 12-01-2007 at 09:09 AM

I'm afraid there really is no way to get multiple editable columns in one row in a ListViewControl.

I also tried to move the editable field to another column, and I somewhat succeeded in that. :P I was using the Win32 API to re-order the columns after creation using LVM_SETCOLUMNORDERARRAY. The only problem was that it also moved any checkboxes or images placed in front of a row to another column, which I didn't like. Therefore, I dropped that. However, if you don't need anything in front of your rows, this may just work for you. :) PM me if you need help with this.

However, I really think Patchou should look into this. It'd be much easier if we could use editable ListViews, and it would also make our windows much nicer. :P


RE: General Help with Interfaces by Toneo on 12-01-2007 at 09:40 AM

Yeah. It's kinda annoying. Oh well, I suppose Patchou'll add editable ListViews to the next update of Plus.


RE: General Help with Interfaces by CookieRevised on 12-01-2007 at 02:11 PM

In normal programs this isn't directly possible either; the listview control (in report mode) simply doesn't directly support this.

However, it is always done by displaying an editbox control (or combobox control or whatever else is needed as 'input' control) over the field you want to edit and filling this editbox with the value of the field. After you've done editing the editbox control is removed (hidden).

But as you can guess this requires some calls to the listview to get the exact column and row position (to be able to know where to display the editbox), and some callbacks.

The stuff you need for this isn't completely supported by Plus!, unfortunatly. There are some workarounds, but they are dodgy and have other disadvantages/shortcommings.

It would be very cool if Patchou could make it directly supported in Plus! of course. Even just adding the ability to use proper callbacks would solve it from what I remember from my trials with this (but then you still need to do the job yourself of course; but it would make it possible).

;)

PS: in the mean time you can always use the listview to display your stuff, and for editing it make a (fixed) row of several editboxes below the listview. Each time the user clicks on a field in the listview, the row of editboxes is filled with the values of that listview row. And the user can then edit the values it in that way.

-----------------------

EDIT: Vikke's suggestion is exactly the same as mine. The only difference is that his suggestion involves an extra window, whereas I said you can add it below your listview in the very same window (=more user friendly IMHO):

+-------+-------+-------+-------+-------+
| title1| title2| title3| title4| title5| <== listview control
+-------+-------+-------+-------+-------+
|       |       |       |       |       |
|       |       |       |       |       |
|       |       |       |       |       |
|       |       |       |       |       |
|       |       |       |       |       |
|       |       |       |       |       |
+-------+-------+-------+-------+-------+
.+-----+ +-----+ +-----+ +-----+ +-----+.
.|     | |     | |     | |     | |     |.  <== editboxes, one per column
.+-----+ +-----+ +-----+ +-----+ +-----+.


When the user highlights a line in the listview, the cells are filled in in the editbox. When the user clicks in an editbox the row in the listview stays highlighted (this is a property of the listview which you can set) and he can edit the value. As soon as the focus is lost from a specific editbox, that value is copied back to the proper cell in the listview. In this way: no need for an extra window with the same labels, more buttons, etc. It enables quicker editing (if that is what you want of course).

It is just a matter of design, of where to place the editboxes. The method is exactly the same: using a row of editboxes. In both cases you don't need any scrollbars though. PS: you can move controls on windows on the fly. This means that you can even make your editboxes grow or shrink according to the column widths of the listview in case you have dynamic column widths.

;)


RE: General Help with Interfaces by vikke on 12-01-2007 at 02:38 PM

ListViews in Windows aren't made to be editable. I bet that's why Patchou hasn't included it in the MP!L scripting, it's simply too much work with dirty workarounds. You can always create a separate window where you store each value in a editbox, so the user can edit it from there. I would have done that if I needed the items to be edited.

As said, it's not supported by the Win32, and I personally think it's not going to be added into MP!L. However what I would like to see is callback functions (so we can do stuff like this with subclassing). That would be even better! :)


RE: General Help with Interfaces by Crazed on 12-01-2007 at 06:11 PM

Thanks for all the help and interesting opinions, guys. :) I admit I had thought about dynamically editing the XML page onthe fly, but that seems drastic to me. I would try to cheat out the API a bit, but as this is my first time truly working with it, I think I'll take it easy.

For now, I think I'll try to go with Vikke's suggestion and create a small window with a few edit boxes for each statistic. That will also solve the problem of needing a scrollbar or something for a whole thing of ListViews.

Thanks so much for all your help! Hopefully I'll be posting soon, releasing this tool. :) Please let me know if there's any other help you can offer.


RE: General Help with Interfaces by Toneo on 12-03-2007 at 04:17 PM

Cool. I'll look forward to when you release it!
If you want any more help, just ask.