Control MSN Messenger Sample
File: ...\Samples\Solution\Toledo\Messenger.scx
This sample demonstrates how to perform operations with MSN Messenger using the Messenger API and Windows Scripting Host. You can use these methods to automate sending messages, e-mail, and files to any MSN user from automated processes. Additionally, if users have mobile messaging, alerts can be sent to their pagers.
This sample is not meant as an alternate user interface to MSN Messenger. For information on the MSN Messenger APIs, see MSDN online at https://msdn.microsoft.com.
MSN Messenger API
This sample demonstrates the Messenger APIs that you can access through the Component Object Model (COM). In this sample, the Messenger object is instantiated in the Init event:
ThisForm.oMessenger = CREATEOBJECT("Messenger.UIAutomation.1")
The Init event also declares some Windows APIs used to bring Messenger windows to the foreground so that you can automate composing e-mail messages and sending files.
DECLARE LONG SetForegroundWindow IN WIN32API LONG
DECLARE INTEGER FindWindow IN WIN32API STRING @ cClass, STRING @ cTitle
DECLARE LONG CloseWindow IN WIN32API LONG
DECLARE Sleep IN WIN32API long
After creating an instance of a Messenger object, you can call methods such as AutoSignin, InstantMessage, OpenInbox, SendFile, SendMail, and SignOut. The SendFile and SendEmail methods also use the Windows APIs to bring Messenger windows to the foreground so that the Windows Scripting Host Shell object can be used to send keystrokes to those windows.
Windows Scripting Host
This sample illustrates how to use Windows Scripting Host to send keystrokes to the activated windows. You can then fill out forms automatically for sending e-mail and files. Windows Scripting Host is required because the MSN Messenger API does not have this functionality. The Windows Scripting Host Shell object is instantiated in the Init event of the sample form:
ThisForm.oWsh = CREATEOBJECT("wscript.Shell")
To send keystrokes to the active window, the SendKeys method of the sample form calls the SendKeys( ) function of the Windows Scripting Host Shell object and automates the composition of e-mail and sending of files.
ThisForm.oWsh.SendKeys(tcKeys)