Shoutbox

Prevent closing chats? - 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: Prevent closing chats? (/showthread.php?tid=65011)

Prevent closing chats? by Jesus on 08-16-2006 at 12:55 PM

Hi all,

I wrote a small script which should prevent me from closing a chat just after receiving a message (like in aMSN), but so far I've only managed to show a toast with the contact's name and message when I close the chat too fast.

My question is: Is there a way to stop a chat window from closing?

Another option is to reopen the chat immediately, but I don't know if it's possible to show the conversation after the window has been closed.


RE: Prevent closing chats? by RaceProUK on 08-16-2006 at 02:09 PM

I know how to do this, but it requires a DLL and a keyboard hook.


RE: Prevent closing chats? by Jesus on 08-16-2006 at 04:17 PM

hmm I've never done that... is it hard to do?


RE: Prevent closing chats? by RaceProUK on 08-17-2006 at 08:31 AM

Not massively really. If you like, I can post some code later today for you to look at.


RE: Prevent closing chats? by CookieRevised on 08-17-2006 at 08:34 AM

quote:
Originally posted by RaceProUK
I know how to do this, but it requires a DLL and a keyboard hook.
to intercept ALT-F4... But what about all the other ways you can close a chat? Isn't it better to hook the window and intercept the close window message?
RE: RE: Prevent closing chats? by Jesus on 08-17-2006 at 08:39 AM

quote:
Originally posted by RaceProUK
Not massively really. If you like, I can post some code later today for you to look at.

that would be great :)
RE: Prevent closing chats? by RaceProUK on 08-17-2006 at 08:46 AM

quote:
Originally posted by CookieRevised
quote:
Originally posted by RaceProUK
I know how to do this, but it requires a DLL and a keyboard hook.
to intercept ALT-F4... But what about all the other ways you can close a chat? Isn't it better to hook the window and intercept the close window message?
I actually intercept Escape. As for the message, the window still wants to be able to be closed, so some sort of special logic will be needed to handle it.
RE: Prevent closing chats? by Delphi Thunderbolt on 08-17-2006 at 01:45 PM

A better way would be to intercept the actual windows API message that closes the window (WM_CLOSE, or something like that; Use a program like MessageSpy++ to find out).

Edit:
Coding in Windows API is not that hard to do, and if you're fluent in another natively compilable language (Like Delphi or C++), you could probably create a DLL that wraps all the API code you need, and simplify your script's code and operation by getting the DLL to handle all the messy stuff.

I have effectively used WM_NCACTIVATE to detect a flash event to any window, all you need to figure out is how to detect and cancel out that API message and you've practically covered all your bases in terms of closing conversation windows.

You'll need to get your hands dirty in Windows API to be able to use this effectively, but well worth it and rewarding.

Hope that helps.


RE: Prevent closing chats? by Jesus on 08-17-2006 at 02:55 PM

Well I'm not afraid to (try to) learn something, so I'll take a look at it.


RE: Prevent closing chats? by Delphi Thunderbolt on 08-18-2006 at 05:10 AM

quote:
Originally posted by Jesus
Well I'm not afraid to (try to) learn something, so I'll take a look at it.

Heh, it only took me (*counts on fingers, mumbles and adds numbers*) 12 months to learn it and code (or look for code) it :P
RE: Prevent closing chats? by Jesus on 08-26-2006 at 12:46 PM

Am I right that dscwpmsg.dll from this thread can do what I want?
I've tried some stuff with it, but I can't figure out what does and does not work :(


RE: Prevent closing chats? by Jesus on 09-09-2006 at 03:22 PM

*bump*

anyone?


RE: Prevent closing chats? by Delphi Thunderbolt on 09-10-2006 at 01:41 AM

It would be better if you looked for the API message that closes the window (Most likely WM_NCCLOSE) and cancel it out.

That would be your best bet, as nothing would be able to close the window while your script intercepts and terminates this message.

I grabbed this from a Delphi forum, which you could probably use in a DLL and call the function from your script. Take note of the bolded pieces of code.

code:
procedure TForm1.FormCloseQuery(Sender: TObject; var CanClose: Boolean);
var
answer : string;
begin
answer := InputBox('Admin password?','password', '');
if answer='yourpassword' then canclose:=true
else
canclose:=false;
end;


Like I said before, it's not going to be easy initially, but it's quite easy to understand and it's well worth the effort.

RE: Prevent closing chats? by Jesus on 09-10-2006 at 11:01 AM

Well the message to be cancelled is WM_DESTROY, which I found using Winspector Spy. So I went looking for a way to hook the chat window. I found the mentioned thread and started looking into it.
In the included textfile I found a function to discard specific messages, which I believe is what I'm looking for (please tell me if I'm wrong).

problem is, when I try to hook the message window using

code:
    Interop.Call(MsgPlus.ScriptFilesPath + "\\dscwpmsg.dll", "SetCWPMSGHook", ChatWnd.Handle, 1, 1)

it returns 0...
quote:
dscwpmsg.txt
Return Value:

2, if both of the Hooks were installed rsp. released successfully,
1, if one of the Hooks was installed rsp. released successfully,
0 (Zero) otherwise.

RE: Prevent closing chats? by Plik on 09-10-2006 at 11:26 AM

quote:
Originally posted by Jesus
Well the message to be cancelled is WM_DESTROY
You probably want to cancel WM_CLOSE and not WM_DESTROY ;)
Because WM_CLOSE is the message that is sent to a window to tell it to start closeing, and this lets the window clean up and do anything it needs todo when its closed (for example in a group conversation it shows the prompt dialog when you send WM_CLOSE).
However WM_DESTROY is what is sent when the window actually needs to be destroyed, usually after WM_CLOSE has been sent, and the window has had time to clean up.

So if you only canceled WM_DESTROY then the window would still do all the closeing it needs todo (like ending sessions) but the window would just never get destroyed. So you need to possible cancel both.
Hope this makes some sense :)
RE: Prevent closing chats? by Jesus on 09-10-2006 at 11:59 AM

that makes sense indeed, the only problem is that I don't see any WM_CLOSE messages in the window's message list (screenshot)


RE: Prevent closing chats? by xxhannahxx on 09-10-2006 at 12:30 PM

i know someone that could make this for you probally


RE: Prevent closing chats? by CookieRevised on 09-10-2006 at 03:00 PM

jesus, there are many different kind of hooks and methods. And for each specific thing you want to do you need different kinds and different approaches. You can't base your code on some listing which does something completely different (refering to the thread you listed).


What you in the first place need to prevent closing of a window is subclassing. You need to trap WM_CLOSE in the window's windows messages stream.

This means that you will need to redirect the windows messages stream (often called the 'WindowProc') to a function in your program (note: this can not be done in JScript) with a callback function.

In that callback function you simply pass thru all the messages the window will recieve (which are a massive load) to the default WindowProc. Only when WM_CLOSE is detected your callback function must not do anything and thus will effectivly cancel this windows message out.

To subclass a window all you need to do is to change its main window proc address to the address of your callback function so that is called instead. (and in your callback procedure calls the original windowproc procedure of the Window).

An easy (VB6) example explaning all this: http://www.osix.net/modules/article/?id=653



However, you probably also need a system wide or application wide hook to know when a window is opened, so you can get its handle and subclass it. (you could also use a timed loop for this to poll for any newly opened windows, so you don't need a hook at all, but that is rather a more crappy way of doing it imho).

Or if you're writing a DLL to be loaded in a Plus! script, you can of course simply use the Plus! scripting event ChatWndCreated to pass the handle of the chat window to your DLL which on its turn subclass that chat window.

quote:
Originally posted by Delphi Thunderbolt
I grabbed this from a Delphi forum, which you could probably use in a DLL and call the function from your script. Take note of the bolded pieces of code.
That code actually doesn't help at all or has not much todo with this. The code is a build-in event in Delphi and many more languages to trap the closing of a window which was created by that same code. No hooking involved at all. you can't use it, nor any parts of this.
RE: Prevent closing chats? by Delphi Thunderbolt on 09-11-2006 at 10:38 AM

Yeah, sorry there. Just realised it after re-reading the code.

It may be useful to someone, somewhere so Ill leave it.


RE: Prevent closing chats? by Jesus on 09-11-2006 at 05:33 PM

thanks for the replies, I know a bit of VB programming so I'll try it with the help of the links and info you all provided me.