The reason it isn't making sense is because you are not globally defining the Chat Window object. You could do this by putting var objChatWnd; at the top of your script then in your OnEvent_MenuClicked you would assign objChatWnd = pChatWnd. The problem then becomes how do you support multiple windows. Well you would do that with the following code. Let me know if this doesn't make sense.
js code:
// Object container
var oChatWnds = {};
// We clicked a menu item, let us make sure it is from the chat window
function OnEvent_MenuClicked(sMenuItemId, nLocation, pChatWnd) {
if (nLocation === MENULOC_CHATWND) {
// Create the window
var tmpWindow = MsgPlus.CreateWnd('TestXmlFile.xml', 'TestWindow');
// Store the Chat Window object in a container
oChatWnds[tmpWindow.Handle] = pChatWnd;
}
}
// We pushed a button
function OnTestWindowEvent_CtrlClicked(pPlusWnd, sControlId) {
// Make sure we are allowed to send a message
// and that the contact isn't offline or blocked
if (oChatWnds[pPlusWnd.Handle].EditChangeAllowed === true)
// Send the message
oChatWnds[pPlusWnd.Handle].SendMessage('This message was sent from clicking a control in a window.');
}
// Our window is closed we need to remove
// the association in the object container
function OnTestWindowEvent_Destroyed(pPlusWnd) {
delete oChatWnds[pPlusWnd.Handle];
}
function OnEvent_ChatWndDestroyed(pChatWnd) {
for (var i in oChatWnds) {
if (oChatWnds[i].Handle === pChatWnd.Handle) {
// Close the original window
Interop.Call('user32', 'SendMessageW', i, 0x10, 0, 0);
// Delete the object from the container
delete oChatWnds[i];
}
}
}