Add items to chatwindow - 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: Add items to chatwindow (/showthread.php?tid=70681)
Add items to chatwindow by PaulE on 01-14-2007 at 05:25 PM
Hey,
Can you add buttons to a chatwindow, and make them clickable?
I have made a system, but now my commands are /o_add [email] and /o_del [email], and i want to made buttons to add/delete. Like this:
I hope this can be done in Messenger Plus! Live.
PaulE
RE: Add items to chatwindow by Ezra on 01-14-2007 at 05:46 PM
It is possible to do, but it can be tricky, the best way is to make a Plus! window and make it a child of the chatwindow. Place the window on the place where you want the buttons to be and the window should look like it's a part of the chatwindow, while it's not
Take a look at the script TimeZone, he did it, only without the buttons.
RE: Add items to chatwindow by PaulE on 01-14-2007 at 06:04 PM
I have looked into the source, but i dont understand what i do need to make the buttons. There is a lot of source you know..
EDIT:
// Zo te zien ben je nederlands?
RE: Add items to chatwindow by Matti on 01-14-2007 at 07:02 PM
Well,...
- First of all you need to make a window with a WindowTmpl (ChildTmpl don't work and DialogTmpl looks ugly) which has your two buttons. Then, you can eventually remove the borders. (look in the documentation)
- Now, you need to create your window but don't show it yet.
code: var PlusWnd = MsgPlus.CreateWnd("Windows.xml", "MyWnd", 2); //The 2 prevents it from being visible when it's created
- Here's the big trick: you have to set the chat window as the parent of the window:
code: var Result = Interop.Call("User32.dll", "SetParent", PlusWnd.Handle, ChatWnd.Handle); //Make sure ChatWnd is valid. Result can be used to check if the function succeeded.
- Set the width and height of the window
code: var Result = Interop.Call("User32.dll", "SetWindowPos", PlusWnd.Handle, 0, 0, 0, 100, 50, 18); //100 is the width, 50 is the height
- Position your window in the chat window. We'll place it 250 pixels from the bottom and 120 pixels from the right. Therefore, we first need the size of the chat window.
code: var RECT = Interop.Allocate(16);
var Result = Interop.Call("User32", "GetWindowRect", ChatWnd.Handle * 1, RECT);
var CurWidth = RECT.ReadDWORD(8) - RECT.ReadDWORD(0);
var CurHeight = RECT.ReadDWORD(12) - RECT.ReadDWORD(4);
var x = CurWidth - 120;
var y = CurHeight - 250;
var Result = Interop.Call("User32.dll", "SetWindowPos", PlusWnd.Handle, 0, x, y, 0, 0, 17);
- Now, make it visible!
code: PlusWnd.Visible = true
The problem is that when you resize the window, our window will disappear. Therefore, you need to add a timer which repositions the timer every x seconds, somewhere between 100 to 500 milliseconds should do. In other words: add a timer event which repeats step 5 every 100 milliseconds.
All credits go to Timezone by Shondoit!
[OFFTOPIC]Ik ben ook Nederlandstalig (Vlaams) hoor! [/OFFTOPIC]
RE: Add items to chatwindow by PaulE on 01-14-2007 at 07:06 PM
quote: Originally posted by Mattike
...
Haha, bedankt, dit ziet er een stuk simpeler uit dan dat van TimeZone . Ik werk zelf niet veel hiermee, dus dan wordt ik graag een handje geholpen Ik zal is kijken hoever ik hiermee kom! Bedankt!
(Moet ik stap 2 uitvoeren als iemand zich aanmeld ofzo? )
RE: Add items to chatwindow by Ezra on 01-14-2007 at 07:25 PM
Step 2 should be done when a ChatWindow is created. You can find the details of these Events in the Scripting Documentation
quote: Originally posted by Dutch Translation
Je moet stap 2 doen als er een ChatWindow gemaakt word. In de Script Documentatie kan je alles vinden over deze Events.
RE: RE: Add items to chatwindow by PaulE on 01-14-2007 at 07:27 PM
quote: Originally posted by Ezra
Step 2 should be done when a ChatWindow is created. You can find the details of these Events in the Scripting Documentation
quote: Originally posted by Dutch Translation
Je moet stap 2 doen als er een ChatWindow gemaakt word. In de Script Documentatie kan je alles vinden over deze Events.
Hehe, that english i do understand
RE: Add items to chatwindow by Matti on 01-14-2007 at 07:28 PM
quote: Originally posted by PaulE
quote: Originally posted by Mattike
...
Haha, bedankt, dit ziet er een stuk simpeler uit dan dat van TimeZone . Ik werk zelf niet veel hiermee, dus dan wordt ik graag een handje geholpen Ik zal is kijken hoever ik hiermee kom! Bedankt!
(Moet ik stap 2 uitvoeren als iemand zich aanmeld ofzo? )
First of all, if you want to talk Dutch, leave an English version too.
quote: Originally posted by PaulE
quote: Originally posted by Mattike
...
Heh, thanks, this looks a lot more simple than the one from TimeZone . I don't work a lot with this myself, so I like to get some help I'll see how far I get with this! Thanks!
(Do I have to execute step 2 when someone signs in or what? )
In fact, you should store all your PlusWnds and ChatWnds in an array. So, on top of your script you place:
code: var ChatWnds = new Array();
var PlusWnds = new Array();
And in your step 2, you should add:
code: ChatWnds[ChatWnd.Handle] = ChatWnd;
PlusWnds[ChatWnd.Handle] = PlusWnd;
When you don't do that, you can't make a timer!
The whole code block should be executed when a chat window is created, so in the OnEvent_ChatWndCreated. There, you also have ChatWnd as parameter!
code: function OnEvent_ChatWndCreated(ChatWnd) {
//Here the code
}
You should also check if the script is started while the user is already signed in and has some conversations opened. Therefore, you need an OnEvent_Initialize and check if the user is signed in. If so, you should loop through all opened conversations and execute the code for every window.
code: function OnEvent_Initialize(MessengerStart) {
if(Messenger.MyStatus > 0) { //Checks if the user is signed in
for(var e = new Enumerator(Messenger.CurrentChats); !e.atEnd(); e.moveNext()) {
var ChatWnd = e.item();
//Here the code
}
}
}
And when a chat window is destroyed, you should remove the ChatWnd and PlusWnd from the arrays.
code: function OnEvent_ChatWndDestroyed(ChatWnd) {
var PlusWnd = PlusWnds[ChatWnd.Handle];
if(PlusWnd != undefined) {
PlusWnd.Close(0);
}
delete ChatWnds[ChatWnd.Handle];
delete PlusWnds[ChatWnd.Handle];
}
NOTE: I hope you're aware of the problems you can get when you place your buttons there? You can hide the display pictures, you can have a dynamic picture,... and those things aren't easy to work around!
RE: Add items to chatwindow by PaulE on 01-14-2007 at 07:53 PM
Hehe i will see where i will place them. Normally my chatwindow is always the same size, and DsiplayPicture is always visible Thnx
EDIT
I have made some code of what you guys said, but i get an error:
quote: > Script is gestopt.
> Script wordt gestart.
> Script is succesvol gestart.
> Functieaanroep: "OnEvent_Initialize"
> Functieaanroep: "OnEvent_ChatWndDestroyed"
> Functieaanroep: "OnEvent_ChatWndCreated"
> Fout gedetecteerd in lijn 29: Deze eigenschap of methode wordt niet ondersteund door dit object.
(Code: -2146827850)
> Fout gedetecteerd in "OnEvent_ChatWndCreated".
(Code: -2147352567)
> Functieaanroep: "OnEvent_ChatWndSendMessage"
So, the script starts, buy when i create a ChatWnd i get an error on line 29:
code: Result = Interop.Call("User32", "GetWindowRect", ChatWnds[ChatWnd.Handle] * 1, RECT);
This is my code:
code: var ChatWnds = new Array();
var PlusWnds = new Array();
function OnEvent_Initialize(MessengerStart) {
if(Messenger.MyStatus > 0) {
for(var e = new Enumerator(Messenger.CurrentChats); !e.atEnd(); e.moveNext()) {
var ChatWnd = e.item();
ChatWnds[ChatWnd.Handle] = ChatWnd;
PlusWnds[ChatWnd.Handle] = MsgPlus.CreateWnd("Buttons.xml", "Buttons", 2);
}
}
}
function Onevent_ChatWndCreated(ChatWnd) {
ChatWnds[ChatWnd.Handle] = ChatWnd;
PlusWnds[ChatWnd.Handle] = MsgPlus.CreateWnd("Buttons.xml", "Buttons", 2);
var Result = Interop.Call("User32.dll", "SetParent", PlusWnds[ChatWnd.Handle], ChatWnds[ChatWnd.Handle]);
Result = Interop.Call("User32.dll", "SetWindowPos", PlusWnds[ChatWnd.Handle], 0, 0, 0, 100, 50, 18);
var RECT = Interop.Allocate(16);
Result = Interop.Call("User32", "GetWindowRect", ChatWnds[ChatWnd.Handle] * 1, RECT);
var CurWidth = RECT.ReadDWORD - RECT.ReadDWORD(0);
var CurHeight = RECT.ReadDWORD(12) - RECT.ReadDWORD(4);
var x = CurWidth - 120;
var y = CurHeight - 250;
Result = Interop.Call("User32.dll", "SetWindowPos", PlusWnds[ChatWnd.Handle], 0, x, y, 0, 0, 17);
PlusWnds[ChatWnd.Handle].Visible = true;
}
function OnEvent_ChatWndDestroyed(ChatWnd) {
var PlusWnd = PlusWnds[ChatWnd.Handle];
if(PlusWnd != undefined) {
PlusWnd.Close(0);
}
delete ChatWnds[ChatWnd.Handle];
delete PlusWnds[ChatWnd.Handle];
}
What is the problem?
Edit
I added the source as attachment, because this code tags dont works good
RE: RE: Add items to chatwindow by deAd on 01-14-2007 at 08:17 PM
quote: Originally posted by PaulESo, the script starts, buy when i create a ChatWnd i get an error on line 29:
code: Result = Interop.Call("User32", "GetWindowRect", ChatWnds[ChatWnd.Handle] * 1, RECT);
I didn't read the whole code, but you'll want to just pass ChatWnd.Handle to the GetWindowRect function.
RE: Add items to chatwindow by PaulE on 01-14-2007 at 08:21 PM
quote: Originally posted by deAd
I didn't read the whole code, but you'll want to just pass ChatWnd.Handle to the GetWindowRect function.
I have changed it to ChatWnd.Handle, and now it works.
But i got an other error:
quote: > Functieaanroep: "OnEvent_ChatWndCreated"
> Fout gedetecteerd in lijn 37: 'PlusWnds[...]' is leeg of geen object.
(Code: -2146823281)
> Fout gedetecteerd in "OnEvent_ChatWndCreated".
(Code: -2147352567)
That means that PlusWnds is empty or not a object. But i did:
PlusWnds[ChatWnd.Handle] = MsgPlus.CreateWnd("Buttons.xml", "Buttons", 2);
EDIT
Changed line 37 to: PlusWnds.Visible = true;
But i dont even see any kind of the timer From TimeZone script
RE: Add items to chatwindow by matty on 01-14-2007 at 08:24 PM
quote: Originally posted by PaulE
PlusWnds[ChatWnd.Handle] =
code: var PlusWnds[ChatWnd.Handle] = MsgPlus.CreateWnd("Buttons.xml", "Buttons", 2);
I think this works not at home so.
RE: Add items to chatwindow by PaulE on 01-14-2007 at 08:55 PM
I got this:
code: <Interfaces xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<Window Id="Buttons" Version="1">
<Attributes>
<NoActivate>true</NoActivate>
<LockOnClick>false</LockOnClick>
<ShowInTaskbar>false</ShowInTaskbar>
</Attributes>
<TitleBar>
<AllowMinimize>false</AllowMinimize>
<AllowClose>false</AllowClose>
</TitleBar>
<Position Width="180" Height="75"/>
<Controls>
// Add here
</Controls>
</Window>
</Interfaces>
I dont want that border and BG Color.
And how can i add a image in it, that is clickable?
PaulE
RE: Add items to chatwindow by Mike on 01-14-2007 at 09:14 PM
quote: Originally posted by Ezra
he best way is to make a Plus! window and make it a child of the chatwindow. Place the window on the place where you want the buttons to be and the window should look like it's a part of the chatwindow, while it's not (Smilie)
Actually, that's not the best way, but the easiest way
The best way to do it would be to subclass the window, and on repaint messages add your own data to be drawn, so that WLM will treat what you added as it's own control (like MsgPlus! does it: Do a small test and make the window small. You will see that the MsgPlus! icons will hide into the arrow, because it thinks that the controls is its controls. If SetParent was used, then the icons would be there just floating (unless you used some more advanced methods))
RE: RE: Add items to chatwindow by PaulE on 01-14-2007 at 09:22 PM
quote: Originally posted by Mike
quote: Originally posted by Ezra
he best way is to make a Plus! window and make it a child of the chatwindow. Place the window on the place where you want the buttons to be and the window should look like it's a part of the chatwindow, while it's not (Smilie)
Actually, that's not the best way, but the easiest way
The best way to do it would be to subclass the window, and on repaint messages add your own data to be drawn, so that WLM will treat what you added as it's own control (like MsgPlus! does it: Do a small test and make the window small. You will see that the MsgPlus! icons will hide into the arrow, because it thinks that the controls is its controls. If SetParent was used, then the icons would be there just floating (unless you used some more advanced methods))
I'm not a whizz kid about WLM.. So i dont know how to do. The easit way is what i'm doing now
So how can i delete that border + bgcolor, and how to add an image?
|