讨论交流:http://x8.maicoo.com/team/8659.html
前端时间做了Messenger助手,后来发现只支持Windows Messenger,不支持Windows Live Messenger,最近改了一下,用到了Active Accessibility编程,代码如下:
using System;
using Accessibility;
namespace MessengerHelper
{
/**//// <summary>
/// 对Messenger窗口进行操作
/// </summary>
public class MessengerWindowHelper
{
IntPtr _messengerWindowHandle ;
IntPtr _inputBoxHandle ;
IntPtr _submitButtonHandle ;
IAccessible _inputBox ;
IAccessible _submitButton ;
private MessengerWindowHelper(){}
public MessengerWindowHelper(IntPtr windowHandle)
{
_messengerWindowHandle = windowHandle ;
_inputBoxHandle = GetInputBoxHandle() ;
_submitButtonHandle = GetSubmitButton() ;
if (_inputBoxHandle == IntPtr.Zero && _submitButtonHandle == IntPtr.Zero)
{
GetAccessibleObjects(_messengerWindowHandle, out _inputBox, out _submitButton);
}
}
/**//// <summary>
/// 输入消息
/// </summary>
/// <param name="message"></param>
public void InputMessage(string message)
{
if (_inputBox == null)
{
Win32.SendMessageString(_inputBoxHandle, Win32.WM_SETTEXT, IntPtr.Zero, message);
}
else
{
_inputBox.set_accValue(Win32.CHILDID_SELF, message) ;
}
}
/**//// <summary>
/// 发送消息
/// </summary>
public void SendMessage()
{
if (_submitButton == null)
{
Win32.SendMessageInt(_submitButtonHandle, Win32.WM_CLICK, IntPtr.Zero, 0);
&
【责任编辑: lanier】