Subclassing is quite a useful way of monitoring the messages sent to the
keyboard (such as key presses),
mouse (such as right mouse clicks) and
windows (such as minimizing).
Plus! can already do some subclassing; take for example matty's
hotkey code and SpunkyLoveMuff's
StatusKey script. These both involve an invisible Plus! window which monitors the keyboard for a specific hotkey.
However, sometimes Plus! windows are not enough. For example, (as far as I know) it is impossible to detect the changing of tabbed chats using only the Plus! scripting engine and the Win32 API. It is even more impossible to detect messages sent to external applications (like Winamp for example).
This is where the ActiveXObjects come in. By using these, we are able to do all these things, right in Plus! itself!
After doing some browsing, I came across two free subclassing ActiveX files.
1. ARSubclass
Link
Download
ARSubclass is a very lightweight ActiveX library. It allows you to monitor the messages sent to a specific window (given its handle). Firstly, the DLL is required to be registered when the script is imported, so this line must be added to ScriptInfo.xml:
code:
<OleFiles>
<FileName>ARSubclass.dll</FileName>
</OleFiles>
Here is an example code of how to use it:
code:
var ARSubclass = new ActiveXObject("ARSubclassLib.ARSubclass");
function OnEvent_Initialize(MessengerStart) {
ARSubclass.hWnd = Messenger.ContactListWndHandle;
ARSubclass.Message(/* WM_ACTIVATE */ 6) = true;
}
function OnEvent_ContactListWndCreated() { OnEvent_Initialize(); }
var Event = function() {
function ARSubclass::WindowProc(hWnd, iMessage, wParam, lParam, Res) {
if(wParam === /* WA_INACTIVE */ 0) Debug.Trace("WA_INACTIVE");
if(wParam === /* WA_ACTIVE */ 1) Debug.Trace("WA_ACTIVE");
if(wParam === /* WA_CLICKACTIVE */ 2) Debug.Trace("WA_CLICKACTIVE");
}
}
Event();
This will trace when the WM_ACTIVATE message is sent to the contact list and show whether it is activated, activated by click or deactivated. (Here, "activated" simply means that the window gets "focus".) When the contact list is created, the ActiveXObject takes its handle and is set to receive all WM_ACTIVATE messages. When it receives one of these messages, it is processed by the WindowProc function with wParam and lParam. (Cheers to
Pai for the ActiveX event trick).
More information can be found on the website.
2. SubClassX5 and
SubClassX6
Link
Download
SubClassX5 and SubClassX6 work identically except they are compiled with different versions of VisualBasic. They work very similar to ARSubclass, except they can deal with more than one window. This makes them especially useful for our tabbed chats scenario as previously mentioned. Unfortunately, the size is quite a bit larger than ARSubclass, but still useable nonetheless! Again, we must register the DLL with ScriptInfo.xml:
code:
<OleFiles>
<FileName>SubClassX6.dll</FileName>
</OleFiles>
Here is an example code of how to use it:
code:
var SubClassX6 = new ActiveXObject("SubClassX6.Window");
function OnEvent_ChatWndCreated(ChatWnd) {
SubClassX6.SubClass_Start(ChatWnd.Handle);
}
function OnEvent_ChatWndDestroyed(ChatWnd) {
SubClassX6.SubClass_Stop(ChatWnd.Handle);
}
var Event = function() {
function SubClassX6::Message(hWnd, Msg, wParam, lParam, Return_Value, Return_SetValue) {
if(Msg == /* WM_ACTIVATE */ 6 && wParam != /* WA_INACTIVE */ 0) Debug.Trace(hWnd);
}
}
Event();
This will trace the handle of a chat window when it is activated (set in focus). Notice that we are able to subclass more than one window simultaneously from the one ActiveXObject. Here, the callback function is Message.
A full documentation of all the functions and properties comes with the DLL.
Finally, I have an example of how this may be useful to scripters. I have attached a script which uses subclassing that will change the window icon (yes, in the toolbar too!) of tabbed chats to reflect the current contact's status. This
should work with tabbed chats disabled too. (You may need to restart WLM first.) Credits to Veggie for his original
StatusIcon script.
Hopefully this has been useful to some of you. All mistakes are entirely deliferate.
TabbedStatusIconV3 - Download
EDIT: Updated version of TabbedStatusIcon has been attached. This fixes some minor bugs.
EDIT: Updated again because I stuffed up the contact status change. It should all be fixed now!