As Mnjul said, you made 2 mistakes:
- OnEvent_ChatWndReceiveMessage is also called for messages you sent and are "received" in the chat window. Therefore, you should check the Origin: only if the Origin is not your own name, you should send the message "Test".
- The Close() function is a child of the PlusWnd object. PlusWnds have absolutely nothing to do with ChatWnds. Therefore, the Close() method won't work for a ChatWnd object. The easiest way to close the window then is to send "/close", after checking if you can actually send something by checking if ChatWnd.EditChangeAllowed is true, but in fact you should do that before you send your "Test" message.
Hopefully these hints allow you to fix your problem.